Skip to main content

Session API

The Session API provides access to current POS session information and secure authentication tokens, allowing you to retrieve shop details, user information, location data, and generate tokens for secure backend communication. The API includes both static session data and dynamic token generation for authenticated API calls.

Use cases

  • Authentication: Authenticate API calls to your app's backend using secure session tokens.
  • Shop context: Customize extension behavior based on shop domain or location settings.
  • Location features: Implement location-specific features like tax calculations or inventory checks.
  • User tracking: Track user activity and staff member interactions for analytics.

The SessionApi object provides access to current session information and authentication methods. Access these properties and methods through api.session to retrieve shop data and generate secure tokens. These methods enable secure API calls while maintaining user privacy and app permissions.

required

Provides comprehensive information about the current POS session including shop details, user authentication, location data, staff member information, currency settings, and POS version. This data is static for the duration of the session and updates when users switch locations or staff members change.

() => Promise<string>
required

Generates a fresh session token for secure communication with your app's backend service. Returns undefined when the authenticated user lacks proper app permissions. The token is a Shopify OpenID Connect ID Token that should be used in Authorization headers for backend API calls. This is based on the authenticated user, not the pinned staff member.

Examples
import React, {useState} from 'react';
import {
reactExtension,
useApi,
Screen,
Text,
} from '@shopify/ui-extensions-react/point-of-sale';

const SmartGridModal = () => {
const {currentSession, getSessionToken} =
useApi<'pos.home.modal.render'>().session;

const {shopId, userId, locationId, staffMemberId} = currentSession;
const [sessionToken, setSessionToken] = useState<string>();

getSessionToken().then((newToken) => {
setSessionToken(newToken);
});

return (
<Screen name="ScreenOne" title="Screen One Title">
<Text>
shopId: {shopId}, userId: {userId}, locationId: {locationId}, staffId:
{staffMemberId}
</Text>
<Text>sessionToken: {sessionToken}</Text>
</Screen>
);
};

export default reactExtension('pos.home.modal.render', () => (
<SmartGridModal />
));

  • Use appropriate identifiers: Distinguish between userId (authenticated account) and staffMemberId (pinned staff member) to implement correct permissions and personalization logic.
  • Implement location-aware features: Use locationId and currency information.
  • Secure backend communication: Use session tokens exclusively for backend API calls and never expose them in client-side logs or storage. validate tokens on your backend before processing requests.

  • Session tokens are only available when the authenticated user has proper app permissions enabled. Staff members who are pinned in but not authenticated can't generate tokens.
  • Session data is read-only and can't be modified through the API. Changes to shop settings, locations, or staff assignments require POS application updates.
  • Session tokens should only be used for communication with your app's configured backend service and can't be used for direct Shopify API calls from the client side.
Was this page helpful?