Crest Design
Shopify 8 min read

Shopify expiring offline tokens: building custom apps safely

Shopify expiring offline access tokens are required for new custom apps from December 2026. How refresh works, Node.js code, and fixes for common errors.

Crest Design
Illustration for a guide to Shopify expiring offline access tokens and token refresh in new custom apps.

This post is for store owners and operations leads who are about to hire a developer to build a Shopify custom app: an ERP or warehouse sync, a CRM connection, a reporting job. Since December 1, 2026, every new custom app has to use Shopify expiring offline access tokens for Admin API calls. You'll learn what that means in plain terms, how the token refresh works, what a correct setup looks like in code, and what to ask your agency so the integration doesn't quietly stop an hour after launch.

The problem: the token that used to last forever now expires

For years, a custom app got one offline access token at install and kept using it until someone uninstalled the app. Developers pasted it into an environment variable and forgot about it. That model is gone for new builds.

Shopify's developer changelog set the date: from December 1, 2026, new custom apps, including apps a merchant creates for their own store, must request expiring offline tokens for both the GraphQL and REST Admin APIs. Public apps have been under the same rule since April 2026. Custom apps created before December 1 can keep their existing tokens, so nothing breaks on stores that already run an older integration.

The practical risk is with new projects. A developer who copies an older tutorial will get the first install working, watch a few test calls succeed, and hand over an integration that starts returning authorization errors once the first token runs out. Orders stop syncing, stock levels drift, and nobody notices until a customer does.

How Shopify expiring offline access tokens work

An "offline" token is the kind a server uses when no staff member is logged in: overnight inventory jobs, webhooks that write back to the store, scheduled exports. "Expiring" means the token now has a short life and comes with a second credential that renews it.

  • The access token is what goes in the X-Shopify-Access-Token header. Shopify's docs give it a lifetime of one hour (the expires_in field).
  • The refresh token is never sent with API calls. Your server swaps it for a fresh access token. It has its own expiry, reported in refresh_token_expires_in (90 days when issued, per the docs).
  • Rotation: every refresh returns a new access token and a new refresh token. The old refresh token is spent, so the new pair must be saved before anything else happens.

Why the change? A permanent token that leaks from a log file or an old laptop is useful to an attacker indefinitely. A token that dies within the hour limits that window, and a refresh token is only useful together with the app's client secret, which never leaves the server.

There's a second route worth knowing. Apps created in the Dev Dashboard that belong to the same Shopify organization as the store can use the client credentials grant: the server sends its client ID and secret and gets a token valid for a day, with no refresh token at all. When it ends, the server simply asks again. That suits a brand running its own integration on its own store. It does not work when an agency's organization owns the app and the store belongs to the client; Shopify rejects that with a shop_not_permitted error, and the app needs a normal OAuth install instead.

Decision diagram: same-organization apps can use client credentials; apps installed on a client's store use OAuth with expiring offline and refresh tokens.
Which token route a new custom app takes depends on who owns the app and the store.

How to set up token refresh in a Shopify custom app

For an app installed through OAuth (token exchange or the authorization code grant), the setup has four parts.

  1. 1 Ask for an expiring token at install. Add expiring=1 to the offline token request. Shopify's own app templates and the @shopify/shopify-app-remix and shopify-api libraries handle this when the expiring-token option is turned on, so check the library version before writing anything by hand.
  2. 2 Store four values per shop: the access token, its expiry time, the refresh token and its expiry time. Keep them in a database or secrets store, encrypted at rest, never in a .env file that gets copied between machines.
  3. 3 Refresh before expiry, not after a failure. Check the stored expiry before each call and refresh a few minutes early.
  4. 4 Refresh one at a time per shop. If two background jobs refresh at the same moment, one of them uses a refresh token the other has already spent. Serialize refreshes per shop.
Flow of a Shopify expiring offline access token: install with expiring=1, store the token pair, call the Admin API, refresh one at a time before expiry, then save the new pair.
The token loop a new Shopify custom app has to run on its own.

Here's a minimal Node.js helper (Node.js 22 or later, using the built-in fetch) that does steps three and four. Put it in your app's server code, pass in your own storage object with load and save methods, and read the client ID and secret from your environment. The shop value is the store's example.myshopify.com domain.

// shopify-token.js
const refreshing = new Map(); // one refresh per shop in this process

export async function getAdminToken(shop, store) {
  const t = await store.load(shop); // { accessToken, expiresAt, refreshToken }
  if (Date.now() < t.expiresAt - 5 * 60_000) return t.accessToken;

  if (!refreshing.has(shop)) {
    refreshing.set(shop, refresh(shop, t, store).finally(() => refreshing.delete(shop)));
  }
  return refreshing.get(shop);
}

async function refresh(shop, t, store) {
  const res = await fetch(`https://${shop}/admin/oauth/access_token`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    body: new URLSearchParams({
      client_id: process.env.SHOPIFY_CLIENT_ID,
      client_secret: process.env.SHOPIFY_CLIENT_SECRET,
      grant_type: 'refresh_token',
      refresh_token: t.refreshToken,
    }),
  });
  if (!res.ok) throw new Error(`Token refresh failed for ${shop}: ${res.status}`);

  const data = await res.json();
  const now = Date.now();
  const next = {
    accessToken: data.access_token,
    expiresAt: now + data.expires_in * 1000,
    refreshToken: data.refresh_token,
    refreshExpiresAt: now + data.refresh_token_expires_in * 1000,
  };
  await store.save(shop, next); // save first: the old refresh token is now spent
  return next.accessToken;
}

The Map only stops duplicate refreshes inside one process. If your app runs several workers or serverless functions, use a lock in the database (a row lock or an advisory lock keyed by shop) so only one of them refreshes at a time.

What we've learned building token refresh

Most of the trouble we see isn't the refresh call itself. It's what surrounds it.

  • Treat a failed refresh as an incident. If the refresh token has expired or been spent, the app can't recover by itself; someone has to re-open the app in the admin so it re-authorizes. Send that failure to a person by email or chat, not just to a log.
  • Don't let quiet stores lose their token. A refresh token that's never used eventually expires. For a store where the integration only runs occasionally, a small scheduled job that refreshes regularly keeps the chain alive.
  • Prefer the official libraries. We'd only hand-write the flow, as above, when the app isn't built on Shopify's templates, for example a standalone Node.js sync service.
  • Pick client credentials when ownership allows. If the store's own organization owns the app, the client credentials grant is simpler: no refresh chain to break. The trade-off is that the app's secret must live with the store owner, which is usually what you want anyway.

Troubleshooting

Symptom Likely cause Fix
Calls return 401 about an hour after install The app saved the access token but never refreshes it Store the refresh token and expiry, and refresh before each call as in the code above
Refresh returns an invalid_grant error now and then Two jobs refreshed at once and one used a spent refresh token Serialize refreshes per shop with an in-process or database lock
Refresh fails after a long quiet period The refresh token itself expired Re-authorize the app from the admin, then add a scheduled refresh
Client credentials request returns shop_not_permitted The app and the store belong to different organizations Install through OAuth with expiring tokens, or create the app under the store's organization

Network rules matter too. If the store or app uses an allowlist, check the guidance in our post on the Shopify custom app IP allowlist, and for apps that call outside services, see Shopify network access declarations.

Questions people ask

Do existing Shopify custom apps have to switch?

Not yet. Custom apps created before December 1, 2026 can keep using their current non-expiring offline tokens. It's still sensible to plan a move when the app is next updated, because the expiring model limits the damage if a token leaks.

Why does my Shopify Admin API token keep expiring?

The app was most likely created after the change and received an expiring offline token, but the code doesn't use the refresh token. Add the refresh step and the problem goes away.

Can I still copy a permanent Admin API token for a connector?

New custom apps don't give you a permanent token to paste anywhere. Any connector or third-party tool you plan to use needs to support OAuth or the client credentials grant, so check that before you choose it.

Why it matters when you hire a Shopify developer

An integration that syncs orders, stock or customers is part of how the business runs. If its credentials are handled carelessly, the failure shows up as missing orders or wrong stock, not as an obvious error page. Before you sign off a custom app, ask your developer:

  • Which token route the app uses, and why.
  • Where the tokens and the client secret are stored, and who can read them.
  • Which Shopify organization owns the app, and how ownership moves to you at handover. Our post on the Shopify store activity log covers how to see what apps and collaborators change in your store.
  • What happens, and who is told, if a refresh fails.

Summary: request expiring tokens at install, store the full token pair, refresh early and one at a time, alert a person on failure, and choose client credentials when the app and store share an organization.

If you're planning a new integration, our Shopify development service and Node.js integration work cover this setup, and we're happy to talk it through on our contact page.

(over to you)

Planning a build like this?

Tell us what you're building and we'll come back with ideas and next steps.