Table of Contents |
---|
Webhooks can be configured on the organization and event level.
Depending on whether one wants to use the default payload or a GraphQL-constructed payload for webhooks, there might be two different types of views for the structure. For constructing the webhook payload, please use values defined in https://gql.doo.net. For details on how to do that, use the steps defined in Constructing GraphQL body.
Webhook Configuration for Default Payload
JSON
Table of Contents |
---|
Object
Code Block | ||
---|---|---|
| ||
{ "name": "<name>", "description": "<description>", "hooks": [ { "type": "event_created", "method": "POST", "endpoint": "<hook_endpoint>" }, { "type": "event_removed", "method": "POST", "endpoint": "<hook_endpoint>" }, { "type": "event_updated", "method": "POST", "endpoint": "<hook_endpoint>" }, { "type": "order_created", "method": "POST", "endpoint": "<hook_endpoint>" }, { "type": "order_removed", "method": "POST", "endpoint": "<hook_endpoint>" }, { "type": "order_updated", "method": "POST", "endpoint": "<hook_endpoint>" }, { "type": "order_cancelled", "method": "POST", "endpoint": "<hook_endpoint>" } ], "authentication": { "grant_type": "client_credentials", "endpoint": "<oauth_endpoint>", "credentials": { "client_id": "<client_id>", "client_secret": "<client_secret>" }, "header_format": "Authorization", "header_value_format": "Bearer %ACCESS_TOKEN%" } } |
Webhook Configuration for GraphQL-based Payload
Example how to provide GraphQL setting. In API request, body must be escaped
Code Block | ||
---|---|---|
| ||
{ "name": "<name>", "description": "<description>", "hooks": [ { "type": "event_created", "method": "POST", "origin":{ "method":"POST", "endpoint":"https://<some url>", "body":"{<this is body as enclosed JSON string>}" }, "endpoint": "<hook_endpoint>" } ], "authentication": { "grant_type": "client_credentials", "endpoint": "<oauth_endpoint>", "credentials": { "client_id": "<client_id>", "client_secret": "<client_secret>" }, "header_format": "Authorization", "header_value_format": "Bearer %ACCESS_TOKEN%" } } | ||
Info | ||
NOTE: In case you don't have OAuth endpoint and want to omit the authorization step with your server - don't include authentication property into the AddWebhook object |
Parameters
Parameter | Required | Description |
---|---|---|
<name> | Yes | Webhook configuration name |
<description> | No | Webhook configuration detailed description |
<hook_endpoint> | Yes | Your server URL where you want to receive the webhook Can be separate for each hook type |
<oauth_endpoint> | Yes | Your server OAuth endpoint URL |
<client_id> | No | Client Id for your OAuth endpoint |
<client_secret> | No | Client Secret for your OAuth endpoint |
Examples
Default case:
JSON Default case
Example
Code Block | ||
---|---|---|
| ||
{ "name": "My Test Webhookwebhook", "description": "Webhook for testing all the hook types", "hooks": [ { "type"description": "event_created",Event creation and updates "method": "POSTwebhook subscription", "endpointhooks": "https://requestb.in/123"[ }, { "type": "event_removed", "method": "POST", "endpoint": "https://requestb.in/123" }, { "type": "event_updated", "method": "POST", "endpoint": "https://requestb.in/123" }, { "type": "order_created", "method": "POST", "endpoint": "https://requestb.in/123" }, { "type": "order_removed", "method": "POST", "endpoint": "https://requestb.in/123" }, { "type": "order_updated", "method": "POST", "endpoint": "https://requestbcompany.in/123" }, { "type": "order_cancelled", "method": "POST", "endpoint": "https://requestb.in/123" } ], "authentication": { "grant_type": "client_credentials", "endpoint": "https://requestb.in/123", "credentials": { "client_id":"doo", "client_secret":"super-strong-secret" }com/receive-doo-webhooks", "header_format": "Authorization", "header_value_format": "Bearer %ACCESS_TOKEN%" } } |
GraphQL case:
JSON GraphQL example with concrete values
Code Block | ||
---|---|---|
| ||
{ "name":"Sample-Org", "description":"Sample-Description", "hooks":[ "origin": { "type":"event_created", "method":"POST", "origin":{ "method":"POST", "endpoint": "https://gql.doo.net", "body": "{\"operationName\":\"EventShort\"null,\"variables\":{\"ideventId\":\"%EVENT_ID%\"},\"query\":\"query EventShort($id$eventId: ID!) {\\n event(id: $id) {\\n title\\n }\\n}\\n\"}" }, "endpoint":"http://requestbin.net/r/123" }, { "type":"event_removed", "method":"POST", "origin":{ "method":"POST", "endpoint":"https://gql.doo.net", "body":"{\"operationName\":\"EventShort\",\"variables\":{\"id\":\"%EVENT_ID%\"},\"query\":\"query EventShort($id: ID!) {\\n event(id: $id) {\\n title\\n }\\n}\\n$eventId) { id title }}\"}" }, "endpoint":"http://requestbin.net/r/123" }, { "type": "event_updated", "method":"POST", "origin":{ "method":"POST", "endpoint": "https://gqlcompany.doo.netcom/receive-doo-webhooks", "body":"{\"operationName\":\"EventShort\",\"variables\":{\"id\":\"%EVENT_ID%\"},\"query\":\"query EventShort($id: ID!) {\\n event(id: $id) {\\n title\\n }\\n}\\n\"}" }, "endpoint":"http://requestbin.net/r/123" }, "origin": { "type":"order_cancelled", "method":"POST", "origin":{ "method":"POST", "endpoint":"https://gql.doo.net", "body":"{\"operationName\":\"OrderShort\",\"variables\":{\"id\":\"%ORDER_ID%\"},\"query\":\"query OrderShort($id: ID!) {\\n order(id: $id) {\\n hash\\n }\\n}\\n\"}" }, "endpoint":"http://requestbin.net/r/123" }, { "type":"order_created", "method":"POST", "origin":{ "method":"POST", "endpoint":"https://gql.doo.net", "body":"{\"operationName\":\"OrderShort\",\"variables\":{\"id\":\"%ORDER_ID%\"},\"query\":\"query OrderShort($id: ID!) {\\n order(id: $id) {\\n hash\\n }\\n}\\n\"}" }, "endpoint":"http://requestbin.net/r/123" }, { "type":"order_removed", "method":"POST", "origin":{ "method":"POST", "endpoint":"https://gql.doo.net", "body":"{\"operationName\":\"OrderShort\"null,\"variables\":{\"ideventId\":\"%ORDER%EVENT_ID%\"},\"query\":\"query OrderShort($id$eventId: ID!) {\\n orderevent(id: $id) {\\n hash\\n }\\n}\\n\"}" }, "endpoint":"http://requestbin.net/r/123" }, { "type":"order_updated", "method":"POST", "origin":{ "method":"POST", "endpoint":"https://gql.doo.net", "body":"{\"operationName\":\"OrderShort\",\"variables\":{\"id\":\"%ORDER_ID%\"},\"query\":\"query OrderShort($id: ID!) {\\n order(id: $id) {\\n hash\\n }\\n}\\n\$eventId) { id title }}\"}" }, "endpoint":"http://requestbin.net/r/123" } ], "authentication": { "grant_type": "client_credentials", "endpoint": "httphttps://requestbincompany.net/r/456com/authorize-doo-webhooks", "credentials": { "client_id": "doo", "client_secret": "super-strong-secret" }, "header_format": "Authorization", "header_value_format": "Bearer %ACCESS_TOKEN%" } } |
Constructing GraphQL body
Below, we will demonstrate a simple case of constructing the trigger payload using GraphQL:
...
Go to https://gql.doo.net
Under the section HTTP Headers, put the Api_Key and Access Token in this format:
Code Block |
---|
{
"x-api-key":"<api_key>",
"Authorization":"Bearer <access_token>"
} |
Provide Query Variables. Example:
Code Block |
---|
{"id": <event_id>} |
...
Provide the body. Example:
Code Block |
---|
query EventShort($id: ID!){
event(id: $id) {
title,
startDate,
endDate
}
} |
to construct a body, one can use the Schema (green button on the right). There you pick the desired entities and then use the detailed variables to construct the payload.
...
Verify the payload. To do that, simply click on the Play button and you will get a complete payload in json and potentially discover mistakes in your body query.
...