Skip to main content

Admin

Contains methods for authenticating and interacting with the Admin API.

This function can handle requests for apps embedded in the Admin, Admin extensions, or non-embedded apps.

Authenticates requests coming from the Shopify admin.

Note

The shape of the returned object changes depending on the distribution config. Merchant custom apps (AppDistribution.ShopifyAdmin) are not embedded so do not return session tokens or redirect functionality. All other distributions are embedded and so they return a context with session tokens and redirect functionality.

Anchor to request
request
Request
required

Promise<<Config>>
Examples

/app/routes/**.ts

import {type ActionFunctionArgs, data} from 'react-router';
import {GraphqlQueryError} from '@shopify/shopify-api';

import {authenticate} from '../shopify.server';

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

try {
await admin.graphql(
`#graphql
mutation updateProductTitle($input: ProductInput!) {
productUpdate(input: $input) {
product {
id
}
}
}`,
{
variables: {
input: {id: '123', title: 'New title'},
},
},
);

return redirect('/app/product-updated');
} catch (error) {
if (error instanceof GraphqlQueryError) {
return data({errors: error.body?.errors}, {status: 500});
}

return new Response('Failed to update product title', {status: 500});
}
};
Was this page helpful?