Ottieni l'albero delle categorie personalizzate

Recupera l'intero albero delle categorie personalizzate per l'utente autenticato.

GET

Questo endpoint ti permette di recuperare una mappa delle tue categorie personalizzate. La risposta sarĂ  un oggetto in cui le chiavi sono gli ID delle categorie e i valori sono i percorsi completi delle categorie.

Endpoint URL
GET https://api.commerceclarity.io/api/v1/custom-category

Autenticazione

Le API di CommerceClarity utilizzano l'autenticazione Bearer Token per proteggere gli endpoint e garantire che solo i client autorizzati possano accedere ai dati. Ogni richiesta API deve includere un token di accesso valido nell'header HTTP.

Esempi di Risposta

Risposta di Successo
{
    "tree": {
        "1": "Category 1",
        "1.1": "Category 1 > Subcategory 1.1",
        "2": "Category 2"
    }
}
Esempio di Risposta per Errore di Autenticazione
{
    "error": "User not authenticated."
}

Esempi di Codice

curl -X GET "https://api.commerceclarity.io/api/v1/custom-category" \
-H "Authorization: Bearer IL_TUO_TOKEN_API" \
-H "Content-Type: application/json"

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;

$client = new Client();
$token = 'IL_TUO_TOKEN_API';
$url = 'https://api.commerceclarity.io/api/v1/custom-category';

try {
    $response = $client->get($url, [
        'headers' => [
            'Authorization' => 'Bearer ' . $token,
            'Accept' => 'application/json',
        ],
    ]);

    $body = $response->getBody();
    $data = json_decode($body, true);
    // Elabora i dati
} catch (RequestException $e) {
    // Gestisci l'errore...
}
                            

import requests

token = 'IL_TUO_TOKEN_API'
url = 'https://api.commerceclarity.io/api/v1/custom-category'
headers = {
    'Authorization': f'Bearer {token}',
    'Accept': 'application/json'
}

try:
    response = requests.get(url, headers=headers)
    response.raise_for_status()  # Raise HTTPError for bad responses (4xx or 5xx)
    data = response.json()
    # Elabora i dati
except requests.exceptions.HTTPError as errh:
    print(f"Http Error: {errh}")
except requests.exceptions.ConnectionError as errc:
    print(f"Error Connecting: {errc}")
except requests.exceptions.Timeout as errt:
    print(f"Timeout Error: {errt}")
except requests.exceptions.RequestException as err:
    print(f"Something Else: {err}")

                            

const token = 'IL_TUO_TOKEN_API';
const url = 'https://api.commerceclarity.io/api/v1/custom-category';

fetch(url, {
    method: 'GET',
    headers: {
        'Authorization': `Bearer ${token}`,
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    }
})
.then(response => {
    if (!response.ok) {
        throw new Error('Network response was not ok');
    }
    return response.json();
})
.then(data => {
    console.log(data);
    // Elabora i dati
})
.catch(error => {
    console.error('There has been a problem with your fetch operation:', error);
    // Gestisci l'errore...
});