Skip to content

stockReferenceAdjustInventoryLevel

Required scope: edit_stock_references

Sets absolute inventory levels for a stock reference. All provided quantity fields are applied as exact values, replacing the current counters. Fields not provided in the input are left unchanged.

Use this mutation for inventory reconciliation — when a physical stock count reveals a discrepancy between the system quantities and the actual warehouse state. For incremental movements (e.g., receiving a new shipment), prefer stockReferenceUpdatePhysicalStock instead.


Mutation

graphql
mutation StockReferenceAdjustInventoryLevel($input: StockReferenceAdjustInventoryLevelInput!) {
  stockReferenceAdjustInventoryLevel(input: $input) {
    id
    physicalQuantity
    usableQuantity
    reservedQuantity
  }
}

Input

StockReferenceAdjustInventoryLevelInput

FieldTypeRequiredDescription
idStringYesStock reference UUID
physicalQuantityIntNoNew absolute physical quantity
usableQuantityIntNoNew absolute usable quantity
reservedQuantityIntNoNew absolute reserved quantity

At least one quantity field must be provided. Quantities cannot be negative.


Variables

json
{
  "input": {
    "id": "sr_abc123",
    "physicalQuantity": 150,
    "reservedQuantity": 10,
    "usableQuantity": 140
  }
}

Response

json
{
  "data": {
    "stockReferenceAdjustInventoryLevel": {
      "id": "sr_abc123",
      "physicalQuantity": 150,
      "usableQuantity": 140,
      "reservedQuantity": 10
    }
  }
}

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 StockReferenceAdjustInventoryLevel($input: StockReferenceAdjustInventoryLevelInput!) { stockReferenceAdjustInventoryLevel(input: $input) { id physicalQuantity usableQuantity reservedQuantity } }",
    "variables": {
      "input": {
        "id": "sr_abc123",
        "physicalQuantity": 150,
        "reservedQuantity": 10,
        "usableQuantity": 140
      }
    }
  }'
js
async function adjustInventoryLevel(accessToken, input) {
  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 StockReferenceAdjustInventoryLevel($input: StockReferenceAdjustInventoryLevelInput!) {
          stockReferenceAdjustInventoryLevel(input: $input) {
            id
            physicalQuantity
            usableQuantity
            reservedQuantity
          }
        }
      `,
      variables: { input },
    }),
  });

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

const updated = await adjustInventoryLevel(accessToken, {
  id: 'sr_abc123',
  physicalQuantity: 150,
  reservedQuantity: 10,
  usableQuantity: 140,
});
python
import requests

def adjust_inventory_level(access_token, input_data):
    response = requests.post(
        'https://api-v3.happycolis.com/graphql',
        headers={
            'Authorization': f'Bearer {access_token}',
            'Content-Type': 'application/json',
        },
        json={
            'query': '''
                mutation StockReferenceAdjustInventoryLevel(
                    $input: StockReferenceAdjustInventoryLevelInput!
                ) {
                    stockReferenceAdjustInventoryLevel(input: $input) {
                        id
                        physicalQuantity
                        usableQuantity
                        reservedQuantity
                    }
                }
            ''',
            'variables': {'input': input_data},
        },
    )
    result = response.json()
    if 'errors' in result:
        raise Exception(result['errors'][0]['message'])
    return result['data']['stockReferenceAdjustInventoryLevel']

updated = adjust_inventory_level(access_token, {
    'id': 'sr_abc123',
    'physicalQuantity': 150,
    'reservedQuantity': 10,
    'usableQuantity': 140,
})
php
function adjustInventoryLevel(string $accessToken, array $input): 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 StockReferenceAdjustInventoryLevel(
                    $input: StockReferenceAdjustInventoryLevelInput!
                ) {
                    stockReferenceAdjustInventoryLevel(input: $input) {
                        id
                        physicalQuantity
                        usableQuantity
                        reservedQuantity
                    }
                }
            ',
            'variables' => ['input' => $input],
        ],
    ]);

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

$updated = adjustInventoryLevel($accessToken, [
    'id'               => 'sr_abc123',
    'physicalQuantity' => 150,
    'reservedQuantity' => 10,
    'usableQuantity'   => 140,
]);
go
package main

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

type AdjustInventoryLevelInput struct {
    ID               string `json:"id"`
    PhysicalQuantity *int   `json:"physicalQuantity,omitempty"`
    UsableQuantity   *int   `json:"usableQuantity,omitempty"`
    ReservedQuantity *int   `json:"reservedQuantity,omitempty"`
}

func adjustInventoryLevel(accessToken string, input AdjustInventoryLevelInput) (map[string]interface{}, error) {
    query := `
        mutation StockReferenceAdjustInventoryLevel(
            $input: StockReferenceAdjustInventoryLevelInput!
        ) {
            stockReferenceAdjustInventoryLevel(input: $input) {
                id
                physicalQuantity
                usableQuantity
                reservedQuantity
            }
        }
    `

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

HappyColis API Documentation