Skip to main content
Migrate to Polaris

Version 2025-07 is the last API version to support React-based UI components. Later versions use web components, native UI elements with built-in accessibility, better performance, and consistent styling with Shopify's design system. Check out the migration guide to upgrade your extension.

Session Token API

The API for interacting with session tokens.

The base API object provided to purchase extension targets.

Anchor to sessionToken
sessionToken
required

The session token providing a set of claims as a signed JSON Web Token (JWT).

The token has a TTL of 5 minutes.

If the previous token expires, this value will reflect a new session token with a new signature and expiry.

Refer to session token examples for more information.

Anchor to useSessionToken
useSessionToken()

Returns a the session token API object.

SessionToken

get
() => Promise<string>

Requests a session token that hasn't expired. You should call this method every time you need to make a request to your backend in order to get a valid token. This method will return cached tokens when possible, so you don’t need to worry about storing these tokens yourself.

Examples
import {useEffect} from 'react';
import {
reactExtension,
Banner,
useApi,
} from '@shopify/ui-extensions-react/checkout';

export default reactExtension(
'purchase.checkout.block.render',
() => <Extension />,
);

function Extension() {
const {sessionToken} = useApi();

useEffect(() => {
async function queryApi() {
// Request a new (or cached) session token from Shopify
const token = await sessionToken.get();
console.log('sessionToken.get()', token);

const apiResponse =
await fetchWithToken(token);
// Use your response
console.log('API response', apiResponse);
}

function fetchWithToken(token) {
const result = fetch(
'https://myapp.com/api/session-token',
{
headers: {
Authorization: `Bearer ${token}`,
},
},
);
return result;
}

queryApi();
}, [sessionToken]);

return (
<Banner>See console for API response</Banner>
);
}
Was this page helpful?