Interacting with Shopify Admin
Once you set up your backend, you can use the authenticate.admin
function to integrate your app with Shopify Admin.
This function works for both embedded and non-embedded apps, and ensures the app is installed on the current store.
It returns a context with functions to enable loaders and actions to respond to any requests made by or in Shopify Admin.
This page goes over the basics of authenticating those requests, and some of the things you can do with it, like querying the Admin API.
Anchor to authAuthenticating requests
To authenticate admin requests you can call authenticate.admin(request)
in a loader or an action.
If there's a session for this user, then this loader will return null. If there's no session for the user, then the loader will throw the appropriate redirect Response.
If you are authenticating more than one route, then we recommend using Remix layout routes to automatically authenticate them.
Authenticating requests
/app/routes/**/*.tsx
Anchor to headersHeaders
The OAuth process can't happen inside the admin iframe, and this package is capable of detecting that scenario and properly redirecting using the Remix export to set the correct headers for App Bridge.
Use the abstractions provided by this package in your authenticated routes, to automatically set up the error and headers boundaries to redirect outside the iframe when needed.
You can also add this to a Remix layout if you want to authenticate more than one route, but make sure to call the Shopify boundary methods whenever you need to add your own exports.
Configure header boundaries
/app/routes/**/*.tsx
Anchor to cors-authAuthenticating cross-origin admin requests
If your Remix server is authenticating an admin extension, then a request from the extension to Remix will be cross-origin.
Here authenticate.admin
provides a cors
function to add the required cross-origin headers.
Add cross-origin headers
/app/routes/**/*.tsx
Anchor to graphql-apiUsing the GraphQL API
Once a request is authenticated, authenticate.admin
will return an admin
object that contains a GraphQL client that can interact with the GraphQL Admin API.
Make GraphQL requests
/app/routes/**/*.tsx
Anchor to graphql-apiUsing the GraphQL API in background jobs
You may need to interact with the Admin API when working outside of Shopify requests. To do so use the unauthenticated.admin
function.
This enables apps to integrate with 3rd party services and perform background tasks.
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.
Make GraphQL requests in background jobs
/app/jobs/**/*.tsx
Anchor to rest-apiUsing the REST API (Deprecated)
Shopify is all-in on graphql. In the next major release, the REST API will be removed from the package.If the
future flag is true, then the REST API will not be available.
Once a request is authenticated, authenticate.admin
will return an admin
object that contains a REST client that can interact with the REST Admin API.
You can also import a set of resource classes from the package, which is included in
.
These classes map to the individual REST endpoints, and will be returned under admin.rest.resources
.