Scopes
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 queryqueryquery() => Promise<ScopesDetail>() => Promise<ScopesDetail>requiredrequired
Queries Shopify to see what scopes have been granted
- Anchor to requestrequestrequest(scopes: string[]) => Promise<void>(scopes: string[]) => Promise<void>requiredrequired
Requests the merchant grant the provided scopes
This method performs a redirect to the grant screen.
- Anchor to revokerevokerevoke(scopes: string[]) => Promise<ScopesRevokeResponse>(scopes: string[]) => Promise<ScopesRevokeResponse>requiredrequired
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[]
ScopesRevokeResponse
- revoked
The scopes that have been revoked on the shop for this app
string[]
/app._index.tsx
Examples
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 };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 };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 };