API reference
Create a webhook
How to create a webhook via API
To create a new webhook, send a POST request to the /api/webhooks endpoint, passing the resource arguments in the request body.

Request

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

Arguments

Body Parameter
Type
Required
type
string
Required
attributes.name
string
Optional, default to "webhook
attributes.topic
string
Required
attributes.callback_url
string
Required
attributes.include_resources
array
Optional
attributes.reference
string
Optional
attributes.reference_origin
string
Optional
attributes.metadata
object
Optional

Example

Request
Response
The following request creates a new webhook:
1
curl -g -X POST \
2
'https://yourdomain.commercelayer.io/api/webhooks' \
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": "webhooks",
9
"attributes": {
10
"topic": "orders.place",
11
"callback_url": "https://yourapp.com/webhooks"
12
}
13
}
14
}'
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": "webhooks",
5
"links": {
6
"self": "https://yourdomain.commercelayer.io/api/webhooks/xYZkjABcde"
7
},
8
"attributes": {
9
"name": "myorg-orders.place",
10
"topic": "orders.place",
11
"callback_url": "https://yourapp.com/webhooks",
12
"include_resources": [
13
"customer",
14
"shipping_address",
15
"billing_address"
16
],
17
"circuit_state": "closed",
18
"circuit_failure_count": 5,
19
"created_at": "2018-01-01T12:00:00.000Z",
20
"updated_at": "2018-01-01T12:00:00.000Z",
21
"reference": "ANY-EXTERNAL-REFEFERNCE",
22
"reference_origin": "ANY-EXTERNAL-REFEFERNCE-ORIGIN",
23
"metadata": {
24
"foo": "bar"
25
}
26
},
27
"relationships": {
28
"last_event_callbacks": {
29
"links": {
30
"self": "https://yourdomain.commercelayer.io/api/webhooks/xYZkjABcde/relationships/last_event_callbacks",
31
"related": "https://yourdomain.commercelayer.io/api/webhooks/xYZkjABcde/last_event_callbacks"
32
}
33
}
34
},
35
"meta": {
36
"mode": "test"
37
}
38
}
39
}
Copied!
Copy link