Skip to main content

Scopes
object

Contains functions used to manage scopes for your app.

This object is returned on authenticated Admin requests.

Provides utilities that apps can use to manage scopes for the app using the Admin API.

() => Promise<>
required

Queries Shopify to see what scopes have been granted

(scopes: string[]) => Promise<void>
required

Requests the merchant grant the provided scopes

This method performs a redirect to the grant screen.

(scopes: string[]) => Promise<>
required

Revokes the provided scopes

Warning: This method throws an error if the provided optional scopes contains a required scope.

Was this section helpful?

Call scopes.query to get scope details.

Was this section helpful?

Query for granted scopes

/app._index.tsx

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

export const loader = async ({ request }) => {
const { scopes } = await authenticate.admin(request);
const { required, optional, granted } = await scopes.query();

if (granted.includes("write_products")) {
// do something
}

return null
};

Anchor to example-ask-the-merchant-to-grant-the-provided-scopesAsk the merchant to grant the provided scopes

Call scopes.request to request optional scopes.

Was this section helpful?

Ask the merchant to grant the provided scopes

/app/routes/app.request.tsx

import { authenticate } from "../shopify.server";

// Example of an action to request optional scopes
export const action = async ({ request }) => {
const { scopes } = await authenticate.admin(request);
const { granted } = await scopes.query();

if (!granted.includes("write_products")) {
await scopes.request(["write_products"]);
}

return null
};

Call scopes.revoke to revoke optional scopes.

Was this section helpful?

Revoke optional scopes

/app._index.tsx

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

// Example of an action to POST optional scopes to revoke
export const action = async ({ request }) => {
const { scopes } = await authenticate.admin(request);
const { granted } = await scopes.query();

if (granted.includes("write_products")) {
const revokedResponse = await scopes.revoke(["write_products"]);
return json(revokedResponse);
}

return null
};