Skip to content

product

Required scope: view_products

Retrieve a single product by its ID, including all of its variants.


Query

graphql
query GetProduct($id: String!) {
  product(id: $id) {
    id
    title
    description
    status
    model
    variants {
      id
      sku
      title
      status
      weight
      weightUnit
    }
    organization {
      id
    }
  }
}

Arguments

ArgumentTypeDescription
idString!The product UUID

Example

Variables

json
{
  "id": "prod_123"
}

Response

json
{
  "data": {
    "product": {
      "id": "prod_123",
      "title": "Classic T-Shirt",
      "description": "A comfortable cotton t-shirt",
      "status": "ACTIVE",
      "model": "PRODUCT",
      "variants": [
        {
          "id": "var_001",
          "sku": "TSHIRT-S-BLUE",
          "title": "Small / Blue",
          "status": "ACTIVE",
          "weight": 200,
          "weightUnit": "G"
        },
        {
          "id": "var_002",
          "sku": "TSHIRT-M-BLUE",
          "title": "Medium / Blue",
          "status": "ACTIVE",
          "weight": 220,
          "weightUnit": "G"
        }
      ],
      "organization": {
        "id": "org_123"
      }
    }
  }
}

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 GetProduct($id: String!) { product(id: $id) { id title description status model variants { id sku title status weight weightUnit } organization { id } } }",
    "variables": {
      "id": "prod_123"
    }
  }'
js
async function getProduct(accessToken, productId) {
  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 GetProduct($id: String!) {
          product(id: $id) {
            id
            title
            description
            status
            model
            variants {
              id
              sku
              title
              status
              weight
              weightUnit
            }
            organization {
              id
            }
          }
        }
      `,
      variables: { id: productId },
    }),
  });

  const { data, errors } = await response.json();
  if (errors) throw new Error(errors[0].message);
  return data.product;
}

// Usage
const product = await getProduct(accessToken, 'prod_123');
python
import requests

def get_product(access_token, product_id):
    response = requests.post(
        'https://api-v3.happycolis.com/graphql',
        headers={
            'Authorization': f'Bearer {access_token}',
            'Content-Type': 'application/json',
        },
        json={
            'query': '''
                query GetProduct($id: String!) {
                    product(id: $id) {
                        id
                        title
                        description
                        status
                        model
                        variants {
                            id
                            sku
                            title
                            status
                            weight
                            weightUnit
                        }
                        organization {
                            id
                        }
                    }
                }
            ''',
            'variables': {'id': product_id},
        },
    )
    result = response.json()
    if 'errors' in result:
        raise Exception(result['errors'][0]['message'])
    return result['data']['product']

# Usage
product = get_product(access_token, 'prod_123')
php
function getProduct(string $accessToken, string $productId): 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 GetProduct($id: String!) {
                    product(id: $id) {
                        id
                        title
                        description
                        status
                        model
                        variants {
                            id
                            sku
                            title
                            status
                            weight
                            weightUnit
                        }
                        organization {
                            id
                        }
                    }
                }
            ',
            'variables' => ['id' => $productId],
        ],
    ]);

    $result = json_decode($response->getBody()->getContents(), true);
    if (isset($result['errors'])) {
        throw new \Exception($result['errors'][0]['message']);
    }
    return $result['data']['product'];
}

// Usage
$product = getProduct($accessToken, 'prod_123');
go
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

func getProduct(accessToken, productID string) (map[string]interface{}, error) {
    query := `
        query GetProduct($id: String!) {
            product(id: $id) {
                id
                title
                description
                status
                model
                variants {
                    id
                    sku
                    title
                    status
                    weight
                    weightUnit
                }
                organization {
                    id
                }
            }
        }
    `

    body, _ := json.Marshal(map[string]interface{}{
        "query":     query,
        "variables": map[string]interface{}{"id": productID},
    })

    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["product"].(map[string]interface{}), nil
}

HappyColis API Documentation