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
Section titled “Calling the Shopify Admin API”Calling the Shopify Admin API is straightforward, just use the BrushContext.adminApi object and pass 2 arguments:
- The GraphQL query or mutation
- 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", });};