Search…
API Reference
Resources
Create a shipping zone
How to create a shipping zone via API
To create a new shipping zone, send a POST request to the /api/shipping_zones endpoint, passing the resource arguments in the request body.

Request

POST https://yourdomain.commercelayer.io/api/shipping_zones

Arguments

Body Parameter
Type
Required
type
string
Required
attributes.name
string
Required
attributes.country_code_regex
string
Optional
attributes.not_country_code_regex
string
Optional
attributes.state_code_regex
string
Optional
attributes.not_state_code_regex
string
Optional
attributes.zip_code_regex
string
Optional
attributes.not_zip_code_regex
string
Optional
attributes.reference
string
Optional
attributes.reference_origin
string
Optional
attributes.metadata
object
Optional

Example

Request
Response
The following request creates a new shipping zone:
1
curl -g -X POST \
2
'https://yourdomain.commercelayer.io/api/shipping_zones' \
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": "shipping_zones",
9
"attributes": {
10
"name": "Europe (main countries)"
11
}
12
}
13
}'
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": "shipping_zones",
5
"links": {
6
"self": "https://yourdomain.commercelayer.io/api/shipping_zones/xYZkjABcde"
7
},
8
"attributes": {
9
"name": "Europe (main countries)",
10
"country_code_regex": "AT|BE|BG|CZ|DK|EE|DE|HU|LV|LT",
11
"not_country_code_regex": "AT|BE|BG|CZ|DK|EE|DE",
12
"state_code_regex": "A[KLRZ]|C[AOT]|D[CE]|FL",
13
"not_state_code_regex": "A[KLRZ]|C[AOT]",
14
"zip_code_regex": "(?i)(JE1|JE2|JE3|JE4|JE5)",
15
"not_zip_code_regex": "(?i)(JE1|JE2|JE3)",
16
"created_at": "2018-01-01T12:00:00.000Z",
17
"updated_at": "2018-01-01T12:00:00.000Z",
18
"reference": "ANY-EXTERNAL-REFEFERNCE",
19
"reference_origin": "ANY-EXTERNAL-REFEFERNCE-ORIGIN",
20
"metadata": {
21
"foo": "bar"
22
}
23
},
24
"relationships": {
25
"attachments": {
26
"links": {
27
"self": "https://yourdomain.commercelayer.io/api/shipping_zones/xYZkjABcde/relationships/attachments",
28
"related": "https://yourdomain.commercelayer.io/api/shipping_zones/xYZkjABcde/attachments"
29
}
30
}
31
},
32
"meta": {
33
"mode": "test"
34
}
35
}
36
}
Copied!
Last modified 20d ago
Copy link