Skip to main content

Admin API
object

Contains objects used to interact with the Admin API.

This object is returned as part of different contexts, such as admin, unauthenticated.admin, and webhook.

Provides utilities that apps can use to make requests to the Admin API.

<AdminOperations>
required

Methods for interacting with the Shopify Admin GraphQL API

Was this section helpful?

Use admin.graphql to make query / mutation requests.

Catch GraphqlQueryError errors to see error messages from the API.

Was this section helpful?

Querying the GraphQL API

import { ActionFunctionArgs } from "react-router";
import { authenticate } from "../shopify.server";

export const action = async ({ request }: ActionFunctionArgs) => {
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
`#graphql
mutation populateProduct($input: ProductInput!) {
productCreate(input: $input) {
product {
id
}
}
}`,
{
variables: {
input: { title: "Product Name" },
},
},
);

const productData = await response.json();
return ({
productId: productData.data?.productCreate?.product?.id,
});
}