GraphQL headers
Adobe Commerce and Magento Open Source GraphQL supports the HTTP GET and POST methods. You can send a query as a GET or POST request. Mutations must be POST requests. You can optionally send a GET query request in a URL. In these requests, you must specify query as the query string. You might need to encode the query, as shown below:
http://<host>/graphql?query=%7Bproducts(filter%3A%7Bsku%3A%7Beq%3A%2224-WB01%22%7D%7D)%7Bitems%7Bname%20sku%7D%7D%7D
The previous example is equivalent to the following query. You could send the query as either a GET or POST request.
Request:
{
products(
filter: { sku: { eq: "24-WB01" } }
) {
items {
name
sku
}
}
}
Response:
{
"data": {
"products": {
"items": [
{
"name": "Voyage Yoga Bag",
"sku": "24-WB01"
}
]
}
}
}
Some queries sent as a GET request can be cached. See GraphQL caching for more information.
Request headers
The application accepts the following headers in a GraphQL request:
AuthorizationBearer <authorization_token>X-Adobe-Company<company_uid>company_id in the response to retrieve information about the companies assigned to a company user account.Content-CurrencyUSDContent-Typeapplication/jsonPreview-VersionStore<store_view_code>default or the code that is defined when a store view is created.X-CaptchaX-Magento-Cache-IdX-ReCaptchaSpecify request headers in a GraphQL browser
GraphQL browsers, such as GraphiQL, allow you to enter a set of header name/value pairs. The following example shows an example customer authorization token and content type headers.
Specify request headers with the curl command
Use the curl command with a separate -H argument to specify each request header. The following example uses the same request headers as those used in the GraphQL browser.
curl 'http://magento.config/graphql' -H 'Authorization: Bearer hoyz7k697ubv5hcpq92yrtx39i7x10um' -H 'Content-Type: application/json' --data-binary '{"query":"query {\n customer {\n firstname\n lastname\n email\n }\n}"}'