Skip to main content

Unauthenticated admin
object

Allows interacting with the Admin API when working outside of Shopify requests. This enables apps to integrate with 3rd party services and perform background tasks.

Caution

This function doesn't perform any validation and shouldn't rely on raw user input.

When using this function, consider the following:

Background tasks

Apps should ensure that the shop domain is authenticated when enqueueing jobs.

3rd party service requests

Apps must obtain the shop domain from the 3rd party service in a secure way.

Creates an unauthenticated Admin context.

string
required

Promise<>
Was this section helpful?

Use admin.graphql to make query / mutation requests.

Was this section helpful?

Querying the GraphQL API

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

export async function action({ request }: ActionFunctionArgs) {
const shop = getShopFromExternalRequest(request);
const { admin } = await unauthenticated.admin(shop);

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 ({ data: productData.data });
}

Get your app's shop-specific data using the returned offline session object.

Was this section helpful?

Using the offline session

/app/routes/**\/*.ts

import { LoaderFunctionArgs, json } from "react-router";
import { unauthenticated } from "../shopify.server";
import { getMyAppData } from "~/db/model.server";

export const loader = async ({ request }: LoaderFunctionArgs) => {
const shop = getShopFromExternalRequest(request);
const { session } = await unauthenticated.admin(shop);
return (await getMyAppData({shop: session.shop}));
};