Testing the Shopify Admin GraphQL API

Shopify's Admin API is GraphQL-first: products, orders, customers and inventory are all one endpoint away. It's a good API to learn in an API client before writing app code, because you can see exactly what a query costs and how errors come back. And Shopify's GraphQL has two error channels that tests need to check.

Step 1: Store and token

Use a development store from your Shopify Partner account, never a live shop. Create an app in the store's admin with the Admin API scopes you need (read_products and write_products for this guide), install it and copy the Admin API access token.

VariableValue
shopyour-dev-store.myshopify.com
apiVersiona current stable version from Shopify's docs, such as 2025-10
shopifyTokenthe access token, marked as secret

Shopify doesn't use Authorization: Bearer. On the collection's Authorization tab, choose API key with the header name X-Shopify-Access-Token and the value {{shopifyToken}}.

Step 2: A GraphQL request

Create a request, switch its type to GraphQL, and set the URL:

Output
https://{{shop}}/admin/api/{{apiVersion}}/graphql.json

In the Query tab:

GraphQL
query Products($first: Int!) {
  products(first: $first) {
    edges {
      node { id title status totalInventory }
    }
    pageInfo { hasNextPage endCursor }
  }
}

And in Variables:

JSON
{"first": 5}
A GraphQL request with a query on the left and a JSON response on the right
A GraphQL request in Requestarium: query, variables and the response side by side

Step 3: Check both kinds of errors

GraphQL answers 200 even for a broken query. Shopify then puts problems in two places:

  • errors at the top level: the query itself is wrong (a typo in a field, a missing scope, throttling).
  • userErrors inside a mutation's result: the query was fine, but Shopify rejected the change (a missing title, an invalid price).
JavaScript
const body = pm.response.json();

pm.test('no GraphQL errors', () => {
  pm.expect(body.errors).to.be.undefined;
});

pm.test('returns products', () => {
  pm.expect(body.data.products.edges).to.be.an('array');
});

Put the errors check in the collection's post-response script, so every request gets it.

Step 4: A mutation and its userErrors

GraphQL
mutation CreateProduct($product: ProductCreateInput!) {
  productCreate(product: $product) {
    product { id title }
    userErrors { field message }
  }
}
JSON
{"product": {"title": "API test product {{$timestamp}}", "status": "DRAFT"}}
JavaScript
const result = pm.response.json().data.productCreate;

pm.test('product created without userErrors', () => {
  pm.expect(result.userErrors).to.be.empty;
  pm.expect(result.product.id).to.match(/^gid:\/\/shopify\/Product\//);
});

pm.environment.set('productId', result.product.id);

Then send the same mutation with an empty title, and check that userErrors names the field. Clean up with productDelete and {"input": {"id": "{{productId}}"}}.

Step 5: Query cost

Shopify rate-limits GraphQL by query cost, not by request count. Each response reports it:

JSON
"extensions": {
  "cost": {
    "requestedQueryCost": 12,
    "actualQueryCost": 7,
    "throttleStatus": {"maximumAvailable": 2000, "currentlyAvailable": 1993, "restoreRate": 100}
  }
}
JavaScript
pm.test('query is reasonably cheap', () => {
  pm.expect(pm.response.json().extensions.cost.requestedQueryCost).to.be.below(100);
});

A query that asks for first: 250 products with nested variants and metafields can cost hundreds of points. Testing the cost catches that before it throttles your app in production.

Step 6: Paginate with cursors

Store endCursor and pass it as after in the next request:

JavaScript
const page = pm.response.json().data.products.pageInfo;
pm.environment.set('after', page.hasNextPage ? page.endCursor : '');

More on pagination in How to test API pagination.