Unauthenticated storefrontobject
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.
Creates an unauthenticated Storefront context.
Anchor to shop
shop
string
required
Promise<>
Was this section helpful?
Anchor to examplesExamples
Anchor to example-sessionsession
Anchor to example-using-the-offline-sessionUsing the offline session
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));
};
Anchor to example-storefrontstorefront
Anchor to example-querying-the-graphql-apiQuerying the GraphQL API
Use storefront.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
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());
}