API Authentication

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.

Getting an API Token

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.

Using the Token

To authenticate your API requests, include the token in the Authorization header of each HTTP request using the format Bearer <token>.

Header Format
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

API Request Examples

cURL Example
curl -X GET "https://api.commerceclarity.io/products/list" \
     -H "Authorization: Bearer YOUR_API_TOKEN" \
     -H "Accept: application/json"
PHP Example (Guzzle)
<?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...
    }
}
JavaScript Example (Fetch)
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);
});
Python Example (Requests)
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}')

Authentication Errors

If the token is missing or invalid, the API request will receive a 401 Unauthorized error response.

Authentication Error Response Example
{
  "status": "error",
  "message": "Unauthenticated."
}

Token Security

API Token Protection

Your API token provides full access to your CommerceClarity account. To protect your data:

  • Treat the token like a password - do not share it with unauthorized third parties
  • Never include the token directly in public source code or repositories
  • Use environment variables or secret management systems to store the token
  • Immediately revoke any compromised token by contacting support

Best Practices

Communication Security

Always use HTTPS for API requests to ensure that the token and all transmitted data are encrypted during transit.

Tokens in Frontend Clients

Avoid including API tokens in publicly accessible JavaScript frontend applications. Instead, use a backend server to make API requests.

Troubleshooting

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

Next Steps

Product Analysis Endpoint

Add new products to your inventory to be able to retrieve their details.

Go to Product Analysis
Product Details

Check the current status of a specific product in your inventory.

Go to Product Details
Product State

Manage the publication state of your products.

Go to Product State

Assistance

Technical Support

If 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.