GraphQL Request and Response Structure

GraphQL API is an alternative to a traditional REST API, but operates similarly. To execute a query, make a POST request to the GraphQL endpoint, available at https://{MyDomainName}.my.salesforce.com/services/data/v{version}/graphql.

Replace these values:

  • MyDomainName: A custom subdomain specific to a Salesforce org. For example, companyname creates the URL https://companyname.my.salesforce.com.
  • version: A Salesforce API version in the format XX.X. For example, 57.0.

For a collection of sample queries, connect to the Salesforce Developer Postman Collection.

For a deep dive into the types involved in the request and response, see the API Reference.

The GraphQL request body has four parts. The query field contains the GraphQL query as a string. Optionally, use the operationName field to indicate which query to execute. Provide the operationName field if the query has multiple queries or mutations, to specify which query or mutation to execute. If the query defines any variables, include them as a map under the variables field. Finally, if the query uses extensions, include them as a map under the extensions field.

Here's a simple request to execute a query.

This request specifies that the contacts query is the one query executed of the two defined in the document.

This request includes argument values for variables defined in the query.

If you're sending a request via curl or HTTP, send the query with your API access token in a JSON string.

You can also use a JSON tool like JQ to help transform or format your output.

To send a request via a client like Altair or Postman, pass in the query directly.

The response has a data section, an errors section, and an extensions section. The data section contains the response to the request query. The errors section includes errors that occur during the execution of the request. The extensions section includes extensions returned by the request.

If the request is successful, you receive a JSON blob like this.

If the request fails, you receive a JSON blob like this.

Status Codes and Error Responses