![]() ![]() This is what GraphQL does to generate the schema for its clients.If you are developing a set of APIs, chances are you already know Postman - an API Client for API development. You can also query GraphQL for the schema itself. If there are errors, a message and details of the error are shown: When checking responses, you should always check to see if the JSON response has any errors. The above example uses "id=5" for the query parameter which filters out ID values to less than 5. This can also be dropped straight into our REST APIs in the form of /api/invoices?id=5. The format for the query option is in the form of a query string parameter that’s also used to filter out values in our REST APIs. Advanced filtering and querying optionsĬollection queries have the additional option parameter called query that further filters out responses. If it can be converted to that given type, then the fields requested will be returned. The fragments tell Coupa to attempt to convert the custom fields to the specified types (if applicable). In the above example, we specify two fragments: … on User. For customFields, you can specify fragments at the type level: ![]() Fragmentsįragments let you construct sets of fields, and then include them in queries. The customFields field can reveal what the type is for that specific custom field, which will allow you to query for those types specifically using fragments. Objects may have custom fields that can be queried by the field name customFields:Ĭustom fields can be any of a number of types (eg: text, datetime, user, etc…). Notice that even within expense lines we are querying for nested data. In the expense report, we are querying for who created it and additional information on the report’s expense lines. The image above shows a query for a single expense report (this also works for a collection of objects). GraphQL allows you to query for nested data: To query for a collection of objects, use the plural form of the object name in lower camel case. For example, users, expenseReports. For example, user(id: 1), expenseReport(id: 1).ĭata is returned in JSON format with the data for the fields queried. ![]() To query for a single object, use the singular form of the object name in lower camel case and specify the object ID. You can query for data for a single object, or a collection of objects. With GraphQL, you can query specifically for the data you need. Mutations are not supported and should not be used. With the schema, you can find out what is queryable and the return types for the queries. Make sure to prefix the Header value with bearer or you won't be able to authorize.Įxpanding the Docs in GraphiQL will allow you to explore the schema. When editing the header, add an authorization header by clicking the Add Header button and the following information: ![]() Click on Docs to expand to show the schema.Edit the HTTP headers to add your access token to the Authorization header (See image below).Provide your instance URL and append it with /api/graphql in the GraphQL Endpoint address bar.In the following examples, we will be using GraphQL. One of the main advantages to using GraphQL is that it fetches the schema and allows you to explore the schema in a user friendly way.ĭownload GraphiQL from or, if you're a Mac user with Homebrew installed, use the following command: brew install -cask graphiqlĪfter installing GraphiQL, launch it and you’ll see something similar to the image below: These tools include curl, Postman, and GraphiQL. GraphQL clientsĪfter you have an access token, there are many tools available that can be used to make GraphQL requests to Coupa. Contact your Coupa Administrator or Coupa Support for steps on how to retrieve an access token with your OIDC client information. We won’t go into discussing how to obtain an access token. We currently only support client credentials grant types.Īfter creating an OIDC client, use the OIDC client information to retrieve an access token. Go to Setup > Integrations > Oauth2/OpenID Connect Clients and click the Create button (or go to /oauth2/clients/new) to create an OIDC client with the appropriate OAuth2 read scopes for your queries (writing is not yet supported). OIDC/OAuth2Ĭoupa’s GraphQL query endpoint is authenticated using OIDC and authorization is handled using OAuth2 scopes. API filters continue to be a key feature that should still be used to reduce resource usage when making REST API GET calls. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |