CWS External Sync API Pro/Documentation/Code Examples

Code Examples

Implementation samples in 5 programming languages

cURL

cURL

curl -X POST https://SHOP_URL/api/external-sync/stock/upsert \
  -H "Authorization: Bearer API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"items":[{"identifier":{"type":"productNumber","value":"SW10001"},"stock":{"quantity":150}}]}'

PHP

PHP (Guzzle)

$client = new GuzzleHttp\Client();
$response = $client->post('https://SHOP_URL/api/external-sync/stock/upsert', [
    'headers' => [
        'Authorization' => 'Bearer API_TOKEN',
        'Content-Type'  => 'application/json',
    ],
    'json' => [
        'items' => [[
            'identifier' => ['type' => 'productNumber', 'value' => 'SW10001'],
            'stock'      => ['quantity' => 150],
        ]],
    ],
]);

Node.js

Node.js (Fetch)

const response = await fetch('https://SHOP_URL/api/external-sync/stock/upsert', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer API_TOKEN',
    'Content-Type':  'application/json',
  },
  body: JSON.stringify({
    items: [{
      identifier: { type: 'productNumber', value: 'SW10001' },
      stock: { quantity: 150 },
    }],
  }),
});

Python

Python (requests)

import requests

response = requests.post(
    'https://SHOP_URL/api/external-sync/stock/upsert',
    headers={
        'Authorization': 'Bearer API_TOKEN',
        'Content-Type':  'application/json',
    },
    json={
        'items': [{
            'identifier': {'type': 'productNumber', 'value': 'SW10001'},
            'stock': {'quantity': 150},
        }],
    },
)

.NET

.NET (HttpClient)

using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue("Bearer", "API_TOKEN");

var payload = new {
    items = new[] { new {
        identifier = new { type = "productNumber", value = "SW10001" },
        stock = new { quantity = 150 },
    }},
};

var response = await client.PostAsJsonAsync(
    "https://SHOP_URL/api/external-sync/stock/upsert", payload);
← Back to Documentation
Shopware Extension Partner