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>",
"created_at": "<string>",
"modified_at": "<string>"
},
"access_token": "<string>",
"refresh_token": "<string>"
}
}{
"message": "<string>",
"success": true,
"code": "<string>",
"error": {}
}{
"message": "<string>",
"success": false,
"code": "<string>"
}Auth
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>",
"created_at": "<string>",
"modified_at": "<string>"
},
"access_token": "<string>",
"refresh_token": "<string>"
}
}{
"message": "<string>",
"success": true,
"code": "<string>",
"error": {}
}{
"message": "<string>",
"success": false,
"code": "<string>"
}Authorizations
API key for your store
Response
OK
A string containing a descriptive message related to the success or failure of the anonymous user creation or authentication.
A boolean value indicates the success or failure of the anonymous user operation.true for success false for failure.
An object containing the response content.
Show child attributes
Show child attributes
Was this page helpful?
⌘I