Search…
API Reference
Creating resources
How to create a resource via API
You can create a resource by sending a POST request to the resources endpoint, with a JSON payload.
The Content-Type header must be application/vnd.api+json.
You can get the list of arguments, with type and examples from the documentation of each resource.

Example

Request
Response
The following request creates a new SKU:
1
curl -g -X POST \
2
'https://yourdomain.commercelayer.io/api/skus' \
3
-H 'Accept: application/vnd.api+json' \
4
-H 'Authorization: Bearer your-access-token' \
5
-H 'Content-Type: application/vnd.api+json' \
6
-d '{
7
"data": {
8
"type": "skus",
9
"attributes": {
10
"code": "TSHIRTMM000000FFFFFFXLXX",
11
"name": "Black Men T-shirt with White Logo (XL)"
12
},
13
"relationships": {
14
"shipping_category": {
15
"data": {
16
"type": "shipping_categories",
17
"id": "zxcVBnMASd"
18
}
19
}
20
}
21
}
22
}'
Copied!
On success, the API responds with a 201 Created status code, returning the created resource object:
1
{
2
"data": {
3
"id": "xYZkjABcde",
4
"type": "skus",
5
"links": {
6
"self": "https://yourdomain.commercelayer.io/api/skus/xYZkjABcde"
7
},
8
"attributes": {
9
"code": "TSHIRTMM000000FFFFFFXLXX",
10
"name": "Black Men T-shirt with White Logo (XL)",
11
"description": null,
12
"image_url": null,
13
"tag_names": "",
14
"pieces_per_pack": null,
15
"weight": null,
16
"unit_of_weight": null,
17
"hs_tariff_number": null,
18
"do_not_ship": false,
19
"do_not_track": false,
20
"created_at": "2018-01-01T12:00:00.000Z",
21
"updated_at": "2018-01-01T12:00:00.000Z",
22
"reference": null,
23
"metadata": {}
24
},
25
"relationships": {
26
"shipping_category": {
27
"links": {...}
28
},
29
"prices": {
30
"links": {...}
31
},
32
"stock_items": {
33
"links": {...}
34
},
35
"delivery_lead_times": {
36
"links": {...}
37
},
38
"sku_options": {
39
"links": {...}
40
}
41
},
42
"meta": {
43
"mode": "test"
44
}
45
}
46
}
Copied!
Last modified 1mo ago
Copy link
Contents
Example