Create a Webhook Subscriber
Creates a Webhook Subscriber
POST
/
api
/
v2
/
platform
/
webhooks
/
subscribers
Create a Webhook Subscriber
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
subscriber: {
url: 'https://www.url.com/',
active: true,
subscriptions: ['order.created', 'order.completed', 'product.updated']
}
})
};
fetch('http://{defaultHost}/api/v2/platform/webhooks/subscribers', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url http://{defaultHost}/api/v2/platform/webhooks/subscribers \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"subscriber": {
"url": "https://www.url.com/",
"active": true,
"subscriptions": [
"order.created",
"order.completed",
"product.updated"
]
}
}
'{
"data": {
"id": "9",
"type": "subscriber",
"attributes": {
"url": "https://www.url9.com/",
"active": true,
"subscriptions": [
"*"
],
"created_at": "2022-11-08T19:35:59.334Z",
"updated_at": "2022-11-08T19:35:59.334Z"
}
}
}{
"error": "Url must be a valid URL, Url can't be blank, and Url the URL must have a path",
"errors": {
"url": [
"must be a valid URL",
"can't be blank",
"the URL must have a path"
]
}
}Was this page helpful?
⌘I
Create a Webhook Subscriber
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
subscriber: {
url: 'https://www.url.com/',
active: true,
subscriptions: ['order.created', 'order.completed', 'product.updated']
}
})
};
fetch('http://{defaultHost}/api/v2/platform/webhooks/subscribers', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url http://{defaultHost}/api/v2/platform/webhooks/subscribers \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"subscriber": {
"url": "https://www.url.com/",
"active": true,
"subscriptions": [
"order.created",
"order.completed",
"product.updated"
]
}
}
'{
"data": {
"id": "9",
"type": "subscriber",
"attributes": {
"url": "https://www.url9.com/",
"active": true,
"subscriptions": [
"*"
],
"created_at": "2022-11-08T19:35:59.334Z",
"updated_at": "2022-11-08T19:35:59.334Z"
}
}
}{
"error": "Url must be a valid URL, Url can't be blank, and Url the URL must have a path",
"errors": {
"url": [
"must be a valid URL",
"can't be blank",
"the URL must have a path"
]
}
}
