Access CommerceClarity APIs via Bearer Token
CommerceClarity APIs use Bearer Token authentication to protect endpoints and ensure that only authorized clients can access the data. Each API request must include a valid access token in the HTTP header.
Currently, API tokens are provided directly by the CommerceClarity support team. To request an access token, fill out the support form available at this link providing your organization name and the API token request in the description.
To authenticate your API requests, include the token in the Authorization
header of each HTTP request using the format Bearer <token>
.
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
curl -X GET "https://api.commerceclarity.io/products/list" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Accept: application/json"
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
$client = new Client([
'base_uri' => 'https://api.commerceclarity.io',
'timeout' => 10.0,
'headers' => [
'Authorization' => 'Bearer YOUR_API_TOKEN',
'Accept' => 'application/json',
]
]);
try {
$response = $client->get('/products/list');
$data = json_decode($response->getBody()->getContents(), true);
// Process the data
} catch (RequestException $e) {
if ($e->hasResponse()) {
$errorResponse = json_decode($e->getResponse()->getBody()->getContents(), true);
// Handle the error...
}
}
const apiUrl = 'https://api.commerceclarity.io/products/list';
const token = 'YOUR_API_TOKEN';
fetch(apiUrl, {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`,
'Accept': 'application/json'
}
})
.then(response => {
if (!response.ok) {
throw new Error(`Status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log('Received data:', data);
// Process the data
})
.catch(error => {
console.error('Error during the API request:', error);
});
import requests
api_url = 'https://api.commerceclarity.io/products/list'
token = 'YOUR_API_TOKEN'
headers = {
'Authorization': f'Bearer {token}',
'Accept': 'application/json'
}
try:
response = requests.get(api_url, headers=headers)
response.raise_for_status() # Raise an exception for HTTP 4XX/5XX responses
data = response.json()
# Process the data
except requests.exceptions.HTTPError as err:
print(f'HTTP Error: {err}')
if response.text:
error_data = response.json()
print(f'Error message: {error_data.get("message", "No message")}')
except requests.exceptions.RequestException as err:
print(f'Request error: {err}')
If the token is missing or invalid, the API request will receive a 401 Unauthorized
error response.
{
"status": "error",
"message": "Unauthenticated."
}
Your API token provides full access to your CommerceClarity account. To protect your data:
Always use HTTPS for API requests to ensure that the token and all transmitted data are encrypted during transit.
Avoid including API tokens in publicly accessible JavaScript frontend applications. Instead, use a backend server to make API requests.
Problem | Possible Cause | Solution |
---|---|---|
"Unauthenticated" or 401 error | Missing or invalid token | Verify that the token is correctly formatted and included in the <code>Authorization</code> header |
Token works for some endpoints but not others | The token may have limited or specific permissions | Check the documentation for specific authentication requirements for the endpoints in question |
Add new products to your inventory to be able to retrieve their details.
Go to Product AnalysisCheck the current status of a specific product in your inventory.
Go to Product DetailsIf you have questions or encounter issues with the APIs, our support team is available to help. Fill out the support form available at this link including details about your request and any error messages received.