Scopesobject
Contains functions used to manage scopes for your app.
This object is returned on authenticated Admin requests.
Anchor to scopesscopes
Provides utilities that apps can use to manage scopes for the app using the Admin API.
- Anchor to queryquery() => Promise<ScopesDetail>required
Queries Shopify to see what scopes have been granted
- Anchor to requestrequest(scopes: string[]) => Promise<void>required
Requests the merchant grant the provided scopes
This method performs a redirect to the grant screen.
- Anchor to revokerevoke(scopes: string[]) => Promise<ScopesRevokeResponse>required
Revokes the provided scopes
Warning: This method throws an error if the provided optional scopes contains a required scope.
ScopesDetail
- granted
The scopes that have been granted on the shop for this app
string[]
- optional
The optional scopes that the app has declared in its configuration
string[]
- required
The required scopes that the app has declared in its configuration
string[]
export interface ScopesDetail {
/**
* The scopes that have been granted on the shop for this app
*/
granted: Scope[];
/**
* The required scopes that the app has declared in its configuration
*/
required: Scope[];
/**
* The optional scopes that the app has declared in its configuration
*/
optional: Scope[];
}
ScopesRevokeResponse
- revoked
The scopes that have been revoked on the shop for this app
string[]
export interface ScopesRevokeResponse {
/**
* The scopes that have been revoked on the shop for this app
*/
revoked: Scope[];
}
Anchor to examplesExamples
Anchor to example-query-for-granted-scopesQuery for granted scopes
Call scopes.query
to get scope details.
Query for granted scopes
/app._index.tsx
Examples
Query for granted scopes
Description
Call `scopes.query` to get scope details.
/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-requestrequest
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.
Ask the merchant to grant the provided scopes
/app/routes/app.request.tsx
Examples
Ask the merchant to grant the provided scopes
Description
Call `scopes.request` to request optional 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 };
Anchor to example-revokerevoke
Anchor to example-revoke-optional-scopesRevoke optional scopes
Call scopes.revoke
to revoke optional scopes.
Revoke optional scopes
/app._index.tsx
Examples
Revoke optional scopes
Description
Call `scopes.revoke` to 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 };