Skip to content

productCreate

Required scope: create_products

Create a new product. Products start in DRAFT status by default and must be activated before they can be used in orders.


Mutation

graphql
mutation ProductCreate($input: ProductInput!) {
  productCreate(input: $input) {
    id
    title
    status
    model
  }
}

Input — ProductInput

FieldTypeRequiredDescription
organizationIdStringOrganization UUID
titleStringProduct title
descriptionStringProduct description
statusProductStatusEnumInitial status — defaults to DRAFT
modelProductModelEnumProduct model — defaults to PRODUCT

Example

Variables

json
{
  "input": {
    "organizationId": "org_123",
    "title": "Classic T-Shirt",
    "description": "A comfortable cotton t-shirt",
    "status": "DRAFT",
    "model": "PRODUCT"
  }
}

Response

json
{
  "data": {
    "productCreate": {
      "id": "prod_456",
      "title": "Classic T-Shirt",
      "status": "DRAFT",
      "model": "PRODUCT"
    }
  }
}

Code Examples

bash
curl -X POST https://api-v3.happycolis.com/graphql \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "mutation ProductCreate($input: ProductInput!) { productCreate(input: $input) { id title status model } }",
    "variables": {
      "input": {
        "organizationId": "org_123",
        "title": "Classic T-Shirt",
        "description": "A comfortable cotton t-shirt",
        "status": "DRAFT",
        "model": "PRODUCT"
      }
    }
  }'
js
async function createProduct(accessToken, productData) {
  const response = await fetch('https://api-v3.happycolis.com/graphql', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${accessToken}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      query: `
        mutation ProductCreate($input: ProductInput!) {
          productCreate(input: $input) {
            id
            title
            status
            model
          }
        }
      `,
      variables: { input: productData },
    }),
  });

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

// Usage
const product = await createProduct(accessToken, {
  organizationId: 'org_123',
  title: 'Classic T-Shirt',
  description: 'A comfortable cotton t-shirt',
  status: 'DRAFT',
  model: 'PRODUCT',
});
python
import requests

def create_product(access_token, product_data):
    response = requests.post(
        'https://api-v3.happycolis.com/graphql',
        headers={
            'Authorization': f'Bearer {access_token}',
            'Content-Type': 'application/json',
        },
        json={
            'query': '''
                mutation ProductCreate($input: ProductInput!) {
                    productCreate(input: $input) {
                        id
                        title
                        status
                        model
                    }
                }
            ''',
            'variables': {'input': product_data},
        },
    )
    result = response.json()
    if 'errors' in result:
        raise Exception(result['errors'][0]['message'])
    return result['data']['productCreate']

# Usage
product = create_product(access_token, {
    'organizationId': 'org_123',
    'title': 'Classic T-Shirt',
    'description': 'A comfortable cotton t-shirt',
    'status': 'DRAFT',
    'model': 'PRODUCT',
})
php
function createProduct(string $accessToken, array $productData): array
{
    $client = new \GuzzleHttp\Client();

    $response = $client->post('https://api-v3.happycolis.com/graphql', [
        'headers' => [
            'Authorization' => 'Bearer ' . $accessToken,
            'Content-Type'  => 'application/json',
        ],
        'json' => [
            'query' => '
                mutation ProductCreate($input: ProductInput!) {
                    productCreate(input: $input) {
                        id
                        title
                        status
                        model
                    }
                }
            ',
            'variables' => ['input' => $productData],
        ],
    ]);

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

// Usage
$product = createProduct($accessToken, [
    'organizationId' => 'org_123',
    'title'          => 'Classic T-Shirt',
    'description'    => 'A comfortable cotton t-shirt',
    'status'         => 'DRAFT',
    'model'          => 'PRODUCT',
]);
go
package main

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

type ProductInput struct {
    OrganizationID string `json:"organizationId"`
    Title          string `json:"title"`
    Description    string `json:"description,omitempty"`
    Status         string `json:"status,omitempty"`
    Model          string `json:"model,omitempty"`
}

func createProduct(accessToken string, input ProductInput) (map[string]interface{}, error) {
    query := `
        mutation ProductCreate($input: ProductInput!) {
            productCreate(input: $input) {
                id
                title
                status
                model
            }
        }
    `

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

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

HappyColis API Documentation