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.
shop: string
export type GetUnauthenticatedAdminContext<
Resources extends ShopifyRestResources,
> = (shop: string) => Promise
Methods for interacting with the GraphQL / REST Admin APIs for the given store.
The session for the given shop. This comes from the session storage which `shopifyApp` uses to store sessions in your database of choice. This will always be an offline session. You can use to get shop-specific data.
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.
import { LoaderFunctionArgs, json } from "@remix-run/node";
import { unauthenticated } from "../shopify.server";
export const loader = async ({ request }: LoaderFunctionArgs) => {
const { admin, session } = await unauthenticated.admin(request);
const response = await admin.rest.get(
{
path: "/customers/count.json"
}
);
const customers = await response.json();
return json({ customers });
};
import { shopifyApp } from "@shopify/shopify-app-remix/server";
import { restResources } from "@shopify/shopify-api/rest/admin/2023-04";
const shopify = shopifyApp({
restResources,
// ...etc
});
export default shopify;
export const unauthenticated = shopify.unauthenticated;
import { ActionFunctionArgs } from "@remix-run/node";
import { unauthenticated } from "../shopify.server";
export async function action({ request }: ActionFunctionArgs) {
const { admin } = await unauthenticated.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 json({ data: productData.data });
}
import { shopifyApp } from "@shopify/shopify-app-remix/server";
const shopify = shopifyApp({
restResources,
// ...etc
});
export default shopify;
export const unauthenticated = shopify.unauthenticated;
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.admin(shop);
return json(await getMyAppData({shop: session.shop));
};