Accessing the GraphQL Programmatically

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 “Authorization” 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.

To get or refresh a bearer token, see Getting a Bearer Token.

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. See Using Variables in GraphQL for information about passing variables into a Query.

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:

  1. The query string is all on one line - JSON does not permit the "query" string to contain embedded line breaks.
  2. The quotes around the company number have been escaped. To avoid the need for escaping, you can pass strings as variables. See Using Variables in GraphQL for more information

 

If you have any further questions, please reach out to our Support Team via Contact Us.