Skip to content

Shopify Admin API

Backend

For the backend, Brush prepares the Admin API for you for the current Shopify shop. This current Shopify shop is:

  • whether the one which made a REST request to your backend (see REST API)
  • or the one you specified when using a Gadget action (see Gadget actions)

Calling the Shopify Admin API is straightforward, just use the BrushContext.adminApi object and pass 2 arguments:

  1. The GraphQL query or mutation
  2. The variables (optionnal)

Example:

const fetchProduct = async (context: BrushContext) => {
const PRODUCT_QUERY =
/* GraphQL */
`
query GetProduct($id: ID!) {
product(id: $id) {
title
}
}
`;
const result = await context.adminApi.graphql(PRODUCT_QUERY, {
id: "gid://shopify/Product/108828309",
});
};