--- title: Unauthenticated admin description: |- Allows interacting with the Admin API on requests that didn't come from Shopify. > Caution: This should only be used for Requests that do not originate from Shopify. > You must do your own authentication before using this method. >This function doesn't perform **any** validation and shouldn't rely on unvalidated user input. api_version: v1 api_name: shopify-app-remix source_url: html: https://shopify.dev/docs/api/shopify-app-remix/v1/unauthenticated/unauthenticated-admin md: https://shopify.dev/docs/api/shopify-app-remix/v1/unauthenticated/unauthenticated-admin.md --- # Unauthenticated adminobject Allows interacting with the Admin API on requests that didn't come from Shopify. Caution This should only be used for Requests that do not originate from Shopify. You must do your own authentication before using this method. This function doesn't perform **any** validation and shouldn't rely on unvalidated user input. ## unauthenticated.​admin([shop](#unauthenticatedadmin-propertydetail-shop)​) Creates an unauthenticated Admin context. ### Parameters * shop string required ### Returns * Promise\> ### UnauthenticatedAdminContext * session 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. ```ts Session ``` * admin Methods for interacting with the GraphQL / REST Admin APIs for the given store. ```ts AdminApiContext ``` ````ts export interface UnauthenticatedAdminContext< Resources extends ShopifyRestResources, > { /** * 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. * * @example * Using the offline session. * Get your app's shop-specific data using the returned offline `session` object. * ```ts * // /app/routes/**\/*.ts * import { LoaderArgs, json } from "@remix-run/node"; * import { unauthenticated } from "../shopify.server"; * import { getMyAppData } from "~/db/model.server"; * * export const loader = async ({ request }: LoaderArgs) => { * const shop = getShopFromExternalRequest(request); * const { session } = await unauthenticated.admin(shop); * return json(await getMyAppData({shop: session.shop)); * }; * ``` */ session: Session; /** * Methods for interacting with the GraphQL / REST Admin APIs for the given store. */ admin: AdminApiContext; } ```` ### AdminApiContext * rest Methods for interacting with the Shopify Admin REST API There are methods for interacting with individual REST resources. You can also make \`GET\`, \`POST\`, \`PUT\` and \`DELETE\` requests should the REST resources not meet your needs. ```ts RestClientWithResources ``` * graphql Methods for interacting with the Shopify Admin GraphQL API ```ts GraphQLClient ``` ````ts export interface AdminApiContext< Resources extends ShopifyRestResources = ShopifyRestResources, > { /** * Methods for interacting with the Shopify Admin REST API * * There are methods for interacting with individual REST resources. You can also make `GET`, `POST`, `PUT` and `DELETE` requests should the REST resources not meet your needs. * * {@link https://shopify.dev/docs/api/admin-rest} * * @example * Using REST resources. * Getting the number of orders in a store using REST resources. * * ```ts * // /app/shopify.server.ts * import { shopifyApp } from "@shopify/shopify-app-remix/server"; * import { restResources } from "@shopify/shopify-api/rest/admin/2023-07"; * * const shopify = shopifyApp({ * restResources, * // ...etc * }); * export default shopify; * export const authenticate = shopify.authenticate; * ``` * * ```ts * // /app/routes/**\/*.ts * import { LoaderArgs, json } from "@remix-run/node"; * import { authenticate } from "../shopify.server"; * * export const loader = async ({ request }: LoaderArgs) => { * const { admin, session } = await authenticate.admin(request); * return json(admin.rest.resources.Order.count({ session })); * }; * ``` * * @example * Performing a GET request to the REST API. * Use `admin.rest.` to make custom requests to the API. * * ```ts * // /app/shopify.server.ts * 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 authenticate = shopify.authenticate; * ``` * * ```ts * // /app/routes/**\/*.ts * import { LoaderArgs, json } from "@remix-run/node"; * import { authenticate } from "../shopify.server"; * * export const loader = async ({ request }: LoaderArgs) => { * const { admin, session } = await authenticate.admin(request); * const response = await admin.rest.get({ path: "/customers/count.json" }); * const customers = await response.json(); * return json({ customers }); * }; * ``` */ rest: RestClientWithResources; /** * Methods for interacting with the Shopify Admin GraphQL API * * {@link https://shopify.dev/docs/api/admin-graphql} * {@link https://github.com/Shopify/shopify-api-js/blob/main/docs/reference/clients/Graphql.md} * * @example * Querying the GraphQL API. * Use `admin.graphql` to make query / mutation requests. * ```ts * import { ActionArgs } from "@remix-run/node"; * import { authenticate } from "../shopify.server"; * * export async function action({ request }: ActionArgs) { * const { admin } = await authenticate.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 }); * } * ``` */ graphql: GraphQLClient; } ```` ### RestClientWithResources ```ts RemixRestClient & {resources: Resources} ``` ## Examples ### session Using the offline session Get your app's shop-specific data using the returned offline `session` object. ### Examples * #### Using the offline session ##### Description Get your app's shop-specific data using the returned offline \`session\` object. ##### /app/routes/\*\*\\/\*.ts ```typescript import { LoaderArgs, json } from "@remix-run/node"; import { unauthenticated } from "../shopify.server"; import { getMyAppData } from "~/db/model.server"; export const loader = async ({ request }: LoaderArgs) => { const shop = getShopFromExternalRequest(request); const { session } = await unauthenticated.admin(shop); return json(await getMyAppData({shop: session.shop)); }; ``` ### rest Using REST resources Getting the number of orders in a store using REST resources. Performing a GET request to the REST API Use `admin.rest.` to make custom requests to the API. ### Examples * #### Using REST resources ##### Description Getting the number of orders in a store using REST resources. ##### /app/shopify.server.ts ```typescript import { shopifyApp } from "@shopify/shopify-app-remix/server"; import { restResources } from "@shopify/shopify-api/rest/admin/2023-07"; const shopify = shopifyApp({ restResources, // ...etc }); export default shopify; export const authenticate = shopify.authenticate; ``` ##### /app/routes/\*\*\\/\*.ts ```typescript import { LoaderArgs, json } from "@remix-run/node"; import { authenticate } from "../shopify.server"; export const loader = async ({ request }: LoaderArgs) => { const { admin, session } = await authenticate.admin(request); return json(admin.rest.resources.Order.count({ session })); }; ``` * #### Performing a GET request to the REST API ##### Description Use \`admin.rest.\\` to make custom requests to the API. ##### /app/shopify.server.ts ```typescript 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 authenticate = shopify.authenticate; ``` ##### /app/routes/\*\*\\/\*.ts ```typescript import { LoaderArgs, json } from "@remix-run/node"; import { authenticate } from "../shopify.server"; export const loader = async ({ request }: LoaderArgs) => { const { admin, session } = await authenticate.admin(request); const response = await admin.rest.get({ path: "/customers/count.json" }); const customers = await response.json(); return json({ customers }); }; ``` ### graphql Querying the GraphQL API Use `admin.graphql` to make query / mutation requests. ### Examples * #### Querying the GraphQL API ##### Description Use \`admin.graphql\` to make query / mutation requests. ##### Example ```typescript import { ActionArgs } from "@remix-run/node"; import { authenticate } from "../shopify.server"; export async function action({ request }: ActionArgs) { const { admin } = await authenticate.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 }); } ``` ## Related [![](https://shopify.dev/images/icons/32/pickaxe-1.png)![](https://shopify.dev/images/icons/32/pickaxe-1-dark.png)](https://shopify.dev/docs/api/shopify-app-remix/apis/admin-api) [Interact with the Admin API.API context](https://shopify.dev/docs/api/shopify-app-remix/apis/admin-api)