Admin APIobject
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
.
Anchor to adminadmin
Provides utilities that apps can use to make requests to the Admin API.
Anchor to graphql
graphql
<AdminOperations>
required
Methods for interacting with the Shopify Admin GraphQL API
Was this section helpful?
Anchor to examplesExamples
Anchor to example-graphqlgraphql
Anchor to example-querying-the-graphql-apiQuerying the GraphQL API
Use admin.graphql
to make query / mutation requests.
Anchor to example-handling-graphql-errorsHandling GraphQL errors
Catch 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,
});
}