get-anonymous-token
Method: POST
Path: /auth/anonymous
Tags: Auth
Summary
Create anonymous session
Description
Creates an anonymous user session with a persistent user_id for analytics and cart tracking. Returns an AnonymousUser object with access_token and refresh_token. Call this before any other authenticated endpoint for guest users.
Storefront SDK Usage
SDK Method: sdk.auth.getAnonymousToken()
Example:
typescript
// Get token for guest browsing
const { data, error } = await sdk.auth.getAnonymousToken();
if (error) {
console.error("Failed to get anonymous token:", error.message);
} else {
console.log("Anonymous token:", data.access_token);
// Store token or proceed with guest operations
}TypeScript Definition
typescript
"get-anonymous-token": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
/** @description A string containing a descriptive message related to the success or failure of the anonymous user creation or authentication. */
message: string;
/** @description A boolean value indicates the success or failure of the anonymous user operation.`true` for success `false` for failure. */
success: boolean;
/** @description An object containing the response content. */
content: {
/** @description Information about the user, including their name, email, profile image, etc. */
user: components["schemas"]["AnonymousUser"];
/** @description It is a string-based token utilized for authentication and authorization. */
access_token: string;
/** @description It is a string-based token designed for refreshing the user's access token. */
refresh_token: string;
};
};
};
};
400: components["responses"]["BadRequest"];
401: components["responses"]["Unauthorized"];
};
};Component References
| Reference | Resolves To |
|---|---|
components["schemas"]["AnonymousUser"] | AnonymousUser |
components["responses"]["BadRequest"] | BadRequest |
components["responses"]["Unauthorized"] | Unauthorized |
Responses
200
OK
400
Bad request
401
Not authorized for given operation on the Resource
OpenAPI Definition
json
{
"tags": [
"Auth"
],
"operationId": "get-anonymous-token",
"summary": "Create anonymous session",
"description": "Creates an anonymous user session with a persistent `user_id` for analytics and cart tracking. Returns an `AnonymousUser` object with `access_token` and `refresh_token`. Call this before any other authenticated endpoint for guest users.",
"externalDocs": {
"url": "https://llm-docs.commercengine.io/storefront/operations/get-anonymous-token",
"description": "API reference for the get-anonymous-token operation"
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"message",
"success",
"content"
],
"properties": {
"message": {
"description": "A string containing a descriptive message related to the success or failure of the anonymous user creation or authentication.",
"type": "string"
},
"success": {
"description": "A boolean value indicates the success or failure of the anonymous user operation.`true` for success `false` for failure.",
"type": "boolean"
},
"content": {
"description": "An object containing the response content.",
"properties": {
"user": {
"description": "Information about the user, including their name, email, profile image, etc.",
"$ref": "#/components/schemas/AnonymousUser"
},
"access_token": {
"description": "It is a string-based token utilized for authentication and authorization.",
"type": "string"
},
"refresh_token": {
"description": "It is a string-based token designed for refreshing the user's access token. ",
"type": "string"
}
},
"required": [
"user",
"access_token",
"refresh_token"
],
"type": "object"
}
}
}
}
},
"links": {
"GetUserCart": {
"operationId": "get-user-cart",
"parameters": {
"user_id": "$response.body#/content/user/user_id"
},
"description": "Retrieve the cart for this anonymous user."
},
"GetUserDetail": {
"operationId": "get-user-detail",
"parameters": {
"id": "$response.body#/content/user/user_id"
},
"description": "Retrieve the detail of this anonymous user."
},
"RefreshAnonymousToken": {
"operationId": "refresh-token",
"requestBody": {
"refresh_token": "$response.body#/content/refresh_token"
},
"description": "Refresh the access token using the refresh token."
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
}
},
"security": [
{
"X-Api-Key": []
}
],
"x-speakeasy-group": "auth",
"x-speakeasy-ignore": false,
"x-speakeasy-name-override": "getAnonymousToken"
}Auto-generated from OpenAPI spec and TypeScript definitions