Supertab.api provides a streamlined interface for making authenticated requests to the Customer API. This client handles the underlying HTTP communication, authentication, and error management, allowing developers to interact directly with Customer API endpoints.

While some endpoints don’t require authentication, users must be authenticated via Supertab.auth first to call endpoints with mandatory authentication. Once authenticated, the API client automatically includes the necessary authorization headers with each request.

This interface is particularly useful for custom integrations that require direct control over API interactions beyond what the pre-built experiences provide.

Methods

Each method returns a promise which resolves with the response from the Customer API endpoint with object keys transformed from snake_case to camelCase.

See Errors for a list of common exceptions.

retrieveCustomer

Retrieves the current customer.

Auth: optional

When called without an existing session, the response will return limits in a currency based on the user’s geographical location. Call this method again after auth to get limits in the user’s tab currency.

You must re-fetch this information after a new auth session is started.

Returns

Customer object. See Retrieve current customer. Supertab.js returns the response object keys in camelCase.

Example

await supertabClient.retrieveCustomer();

retrieveSite

Retrieves the site object associated with the client ID used to initialize Supertab.js.

Auth: optional

If called without auth, the response will return prices in a currency based on the user’s geographical location. Call this method again after auth to get prices in the user’s tab currency.

You must re-fetch this information after a new auth session is started in order to show correct pricing.

Returns

Site object. See Retrieve site. Supertab.js returns the response object keys in camelCase.

Example

await supertabClient.retrieveSite();

checkEntitlement

This method checks the entitlement details for a given content key.

Auth: required

Parameters

contentKey
string
required

The content key of the entitlement to check.

Returns

An object with the entitlement details. See Retrieve entitlement status. Supertab.js returns the response object keys in camelCase.

Examples

Check entitlement for a specific content key
await supertabClient.checkEntitlement({
    contentKey: "content-key"
});
Check entitlement for all site content keys
// Retrieve site to get content keys
const { contentKeys } = await supertabClient.retrieveSite();

// Check entitlement
const entitlement = await Promise.all(
    contentKeys.map(async (contentKey) => {
        return await supertabClient.checkEntitlement(contentKey);
    })
);

purchase

Purchases an offering or a one-time offering.

Auth: required

Parameters

Either offeringId or onetimeOfferingId must be provided.
offeringId
string

The offering ID to purchase.

onetimeOfferingId
string

The onetime offering ID to purchase.

currencyCode
string
required

ISO4217 currency code.

Must match the currency of user’s tab, otherwise the purchase will fail.

metadata
object

Free-form metadata to associate with the purchase.

Returns

Purchase object. See Purchase an offering endpoint in Customer API docs for detailed list of returned properties. Supertab.js returns the response object keys in camelCase.

Example

await supertabClient.purchase({
    offeringId: "offering-id",
    currencyCode: "USD"
});

retrievePurchase

This method retrieves a purchase object for a given purchase ID.

Auth: required

Parameters

purchaseId
string
required

The purchase ID to retrieve.

Returns

Purchase object. See Retrieve a purchase. Supertab.js returns the response object keys in camelCase.

Example

await supertabClient.retrievePurchase({
    purchaseId: "purchase-id"
});