Add-on | AI agents - Advanced |
While REST APIs have long been a standard for enabling integrations, GraphQL is rapidly gaining traction due to its flexibility and efficiency. You can leverage the integration builder's features to integrate with GraphQL APIs. You can take advantage of GraphQL’s key features, such as requesting only the data you need and handling complex queries with ease.
In this article, we’ll walk you through the process of setting up a GraphQL request using the integration builder, from understanding the GraphQL schema to constructing queries and integrating responses into your conversations.
To set up a GraphQL request
- Find the GraphQL endpoint URL, usually provided by the API documentation (for example, https://api.example.com/graphql or for Shopify: https://{{storeName}}.myshopify.com/admin/api/2023-04/graphql.json).
- Add it to the integration builder interface.
- Navigate to Environments and select the POST method type (if you are requesting data).
- Add your GraphQL endpoint into the URL input.
- Select your authentication method (if required).
- If needed, add your credentials to the headers. For example, if it’s a Shopify integration, it will look like this:
- Understand the GraphQL Schema to select the data that you want returned from the server.
- Obtain the schema from the GraphQL server.
It defines the available queries, mutations, and types. Use tools like Postman, GraphiQL or Apollo Explorer to inspect the schema, and to test and refine the query.
We recommend obtaining the query from Postman by navigating to the Code snippet tab and checking for data where you should see an object with the key “query”. Copy the object to use in the next step. - In the Body tab, add the GraphQL query specifying the data you need or the action you want to perform (if making a mutation request to modify data; create, update, delete).
This must be in JSON format.
Example query:
```{"query":"{\n __type(name: \"Order\") {\n name,\n fields {\n name\n type {\n name\n kind\n }\n }\n }\n}","variables":{}}``` - Navigate to the Success scenario to add your session parameters.
- Using JSONata, write your queries to access and transform (if needed) the data in the response. See below for an example:
0 comments