Table of Contents |
---|
...
Table of Contents |
---|
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
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
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 request 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:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{ "name": "My Test Webhook", "description": "Webhook for testing all the hook types", "hooks": [ { "type": "event_created", "method": "POST", "endpoint": "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://requestb.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" }, "header_format": "Authorization", "header_value_format": "Bearer %ACCESS_TOKEN%" } } |
GraphQL case:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{
"name":"Sample-Org",
"description":"Sample-Description",
"hooks":[
{
"type":"event_created",
"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\"}"
},
"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\"}"
},
"endpoint":"http://requestbin.net/r/123"
},
{
"type":"event_updated",
"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\"}"
},
"endpoint":"http://requestbin.net/r/123"
},
{
"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\",\"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_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\"}"
},
"endpoint":"http://requestbin.net/r/123"
}
],
"authentication":{
"grant_type":"client_credentials",
"endpoint":"http://requestbin.net/r/456",
"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:
Paste code macro language json {"x-api-key":"<api_key>", "Authorization":"Bearer <access_token>" }
Provide Query Variables. Example:
Paste code macro language json {"id": <event_id>}
Provide the body. Example:
Paste code macro language json 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.
- Once you are satisfied and want to create a webhook configuration with your GraphQL query, don't forget to escape the query before pasting it to the AddWebhook object.