Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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
languagejs
titleJSON
{
  "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
languagejs
titleExample how to provide GraphQL setting. In API request, body must be escaped
{
  "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

ParameterRequiredDescription
<name>YesWebhook configuration name
<description>NoWebhook 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>

NoClient Id for your OAuth endpoint 

<client_secret>

NoClient Secret for your OAuth endpoint 

Examples

...

Default case:

Code Block
languagejs
titleJSON Default case
collapsetrue
{
  "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
languagejs
titleJSON GraphQL example with concrete values
collapsetrue
{
    "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:

  1. Go to https://gql.doo.net
  2. Under the section HTTP Headers, put the Api_Key and Access Token in this format:

    Paste code macro
    languagejson
    {"x-api-key":"<api_key>",
     "Authorization":"Bearer <access_token>"
    }


  3. Provide Query Variables. Example:

    Paste code macro
    languagejson
    {"id": <event_id>}


  4. Provide the body. Example:

    Paste code macro
    languagejson
    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.

  5. 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.
  6. 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.