You will need to POST the GraphQL request body to the API end point. See API Endpoints for the URLs to use.
In the header you will need to supply 3 headers:
- An 'Accept' header (typically */*)
- A 'Content-Type' header (“application/json”)
- An 'Authorisation' header (“Bearer” followed by a space and then the bearer token). You do not need to supply this header if you’re calling the “signIn” mutation to get a bearer token.
For guidance on getting or refreshing a bearer token, click here.
The post body should be encoded as JSON as shown below:
{
“query”: “…”,
“variables”: { “variable1”: “value1”, …}
}
Note: To be valid JSON, any double-quotes within the query body should be escaped. The 'variables' attribute is optional and is only required if variables have been specified in the query. For information about passing variables into a Query, click here.
Here is an example of a simple GraphQL query to retrieve a company by its number:
query example {
companies(where:{company_number:{eq:"11266456"}}){
items{
company_number
company_name
}
}
}
And here is what would be POSTed to the API Endpoint.
{
"query": "query example {companies (where: {company_number: {eq: \"11266456\"}}) {items {company_number company_name}}}"
}Note:
- The query string is all on one line - JSON does not permit the "query" string to contain embedded line breaks.
- The quotes around the company number have been escaped. To avoid the need for escaping, you can pass strings as variables. For more information on using variables, see here.
If you have any further queries please get in touch with your account manager. If you do not know who your account manager is, please submit a ticket using this link.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article