variant
Required scope: view_products
Retrieve a single variant by its ID or by its SKU. Provide either id or sku — these are mutually exclusive.
Query
graphql
query GetVariant($id: String, $sku: String) {
variant(id: $id, sku: $sku) {
id
sku
title
status
model
weight
weightUnit
height
width
length
distanceUnit
barcode
originCountry
hsCode
product {
id
title
}
}
}Arguments
| Argument | Type | Description |
|---|---|---|
id | String | Variant UUID. Mutually exclusive with sku. |
sku | String | Variant SKU within the organization. Mutually exclusive with id. |
Example — Lookup by ID
Variables
json
{
"id": "var_001"
}Response
json
{
"data": {
"variant": {
"id": "var_001",
"sku": "TSHIRT-S-BLUE",
"title": "Small / Blue",
"status": "ACTIVE",
"model": "PRODUCT",
"weight": 200,
"weightUnit": "G",
"height": 30,
"width": 25,
"length": 5,
"distanceUnit": "CM",
"barcode": "3760123456789",
"originCountry": "FR",
"hsCode": "6109100010",
"product": {
"id": "prod_123",
"title": "Classic T-Shirt"
}
}
}
}Example — Lookup by SKU
Variables
json
{
"sku": "TSHIRT-S-BLUE"
}Code Examples
bash
curl -X POST https://api-v3.happycolis.com/graphql \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"query": "query GetVariant($id: String, $sku: String) { variant(id: $id, sku: $sku) { id sku title status model weight weightUnit height width length distanceUnit barcode originCountry hsCode product { id title } } }",
"variables": {
"id": "var_001"
}
}'js
async function getVariant(accessToken, { id, sku }) {
const response = await fetch('https://api-v3.happycolis.com/graphql', {
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
query GetVariant($id: String, $sku: String) {
variant(id: $id, sku: $sku) {
id
sku
title
status
model
weight
weightUnit
height
width
length
distanceUnit
barcode
originCountry
hsCode
product {
id
title
}
}
}
`,
variables: { id, sku },
}),
});
const { data, errors } = await response.json();
if (errors) throw new Error(errors[0].message);
return data.variant;
}
// Lookup by ID
const variant = await getVariant(accessToken, { id: 'var_001' });
// Lookup by SKU
const variantBySku = await getVariant(accessToken, { sku: 'TSHIRT-S-BLUE' });python
import requests
def get_variant(access_token, id=None, sku=None):
response = requests.post(
'https://api-v3.happycolis.com/graphql',
headers={
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json',
},
json={
'query': '''
query GetVariant($id: String, $sku: String) {
variant(id: $id, sku: $sku) {
id
sku
title
status
model
weight
weightUnit
height
width
length
distanceUnit
barcode
originCountry
hsCode
product {
id
title
}
}
}
''',
'variables': {'id': id, 'sku': sku},
},
)
result = response.json()
if 'errors' in result:
raise Exception(result['errors'][0]['message'])
return result['data']['variant']
# Lookup by ID
variant = get_variant(access_token, id='var_001')
# Lookup by SKU
variant = get_variant(access_token, sku='TSHIRT-S-BLUE')php
function getVariant(string $accessToken, ?string $id = null, ?string $sku = null): array
{
$client = new \GuzzleHttp\Client();
$response = $client->post('https://api-v3.happycolis.com/graphql', [
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
'Content-Type' => 'application/json',
],
'json' => [
'query' => '
query GetVariant($id: String, $sku: String) {
variant(id: $id, sku: $sku) {
id
sku
title
status
model
weight
weightUnit
height
width
length
distanceUnit
barcode
originCountry
hsCode
product {
id
title
}
}
}
',
'variables' => ['id' => $id, 'sku' => $sku],
],
]);
$result = json_decode($response->getBody()->getContents(), true);
if (isset($result['errors'])) {
throw new \Exception($result['errors'][0]['message']);
}
return $result['data']['variant'];
}
// Lookup by ID
$variant = getVariant($accessToken, id: 'var_001');
// Lookup by SKU
$variant = getVariant($accessToken, sku: 'TSHIRT-S-BLUE');go
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type VariantVariables struct {
ID *string `json:"id,omitempty"`
SKU *string `json:"sku,omitempty"`
}
func getVariant(accessToken string, vars VariantVariables) (map[string]interface{}, error) {
query := `
query GetVariant($id: String, $sku: String) {
variant(id: $id, sku: $sku) {
id
sku
title
status
model
weight
weightUnit
height
width
length
distanceUnit
barcode
originCountry
hsCode
product {
id
title
}
}
}
`
body, _ := json.Marshal(map[string]interface{}{
"query": query,
"variables": vars,
})
req, _ := http.NewRequest("POST", "https://api-v3.happycolis.com/graphql", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer "+accessToken)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
if errs, ok := result["errors"]; ok {
return nil, fmt.Errorf("graphql error: %v", errs)
}
data := result["data"].(map[string]interface{})
return data["variant"].(map[string]interface{}), nil
}