Skip to main content

Unauthenticated storefront
object

Allows interacting with the Storefront 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.

Anchor to unauthenticated.storefront
unauthenticated.storefront()

Creates an unauthenticated Storefront context.

string
required

Promise<>
Was this section helpful?

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 "@remix-run/node";
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.storefront(shop);
return json(await getMyAppData({shop: session.shop));
};

Use storefront.graphql to make query / mutation requests.

Catch GraphqlQueryError errors to see error messages from the API.

Was this section helpful?

Querying the GraphQL API

app/routes/**\/.ts

import { json } from "@remix-run/node";
import { authenticate } from "../shopify.server";

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

const response = await storefront.graphql(`{blogs(first: 10) { edges { node { id } } } }`);

return json(await response.json());
}