Authentication
Create anonymous session
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.
POST
/
auth
/
anonymous
Create anonymous session
curl --request POST \
--url https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous \
--header 'X-Api-Key: <api-key>'import requests
url = "https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous"
headers = {"X-Api-Key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'X-Api-Key': '<api-key>'}};
fetch('https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"X-Api-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("X-Api-Key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous")
.header("X-Api-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Api-Key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"message": "<string>",
"success": true,
"content": {
"user": {
"id": "<string>",
"is_anonymous": true,
"is_logged_in": true,
"first_name": "<string>",
"last_name": "<string>",
"phone": "<string>",
"email": "<string>",
"is_email_verified": false,
"is_phone_verified": false,
"profile_image_url": "<string>",
"country_code": "<string>",
"customer_id": "<string>",
"customer_group_id": "<string>",
"channel": {
"id": "<string>",
"name": "<string>",
"type": "<string>"
},
"tenant_id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"modified_at": "2023-11-07T05:31:56Z"
},
"access_token": "<string>",
"refresh_token": "<string>"
}
}{
"message": "<string>",
"success": true,
"code": "<string>",
"errors": {},
"details": "<string>"
}{
"message": "Not authorized for given operation on the Resource.",
"success": false,
"code": "unauthorized",
"details": "<string>"
}{
"code": "<string>",
"message": "<string>",
"success": true,
"details": "<string>"
}Response
OK
Was this page helpful?
⌘I
Create anonymous session
curl --request POST \
--url https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous \
--header 'X-Api-Key: <api-key>'import requests
url = "https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous"
headers = {"X-Api-Key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'X-Api-Key': '<api-key>'}};
fetch('https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"X-Api-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("X-Api-Key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous")
.header("X-Api-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://staging.api.commercengine.io/api/v1/{store_id}/storefront/auth/anonymous")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Api-Key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"message": "<string>",
"success": true,
"content": {
"user": {
"id": "<string>",
"is_anonymous": true,
"is_logged_in": true,
"first_name": "<string>",
"last_name": "<string>",
"phone": "<string>",
"email": "<string>",
"is_email_verified": false,
"is_phone_verified": false,
"profile_image_url": "<string>",
"country_code": "<string>",
"customer_id": "<string>",
"customer_group_id": "<string>",
"channel": {
"id": "<string>",
"name": "<string>",
"type": "<string>"
},
"tenant_id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"modified_at": "2023-11-07T05:31:56Z"
},
"access_token": "<string>",
"refresh_token": "<string>"
}
}{
"message": "<string>",
"success": true,
"code": "<string>",
"errors": {},
"details": "<string>"
}{
"message": "Not authorized for given operation on the Resource.",
"success": false,
"code": "unauthorized",
"details": "<string>"
}{
"code": "<string>",
"message": "<string>",
"success": true,
"details": "<string>"
}