Webhooks

Webhooks are "user-defined HTTP callbacks" from a restdb.io database to any other system. It's perfect to use with integration services like Zapier.

restdb.io calls an URL when an event occurs in the database. An event is triggered when you/api:

  • Create a data record
  • Update a data record
  • Delete one or many data records

Example

Lets say that you created a collection with Article data in RestDB and you want to notify some other system when a new Article is created in your database. In order to set up a Webhook you must know or control the URL endpoint you wish to connect to. An URL endpoint looks something like:

https://myservice.org/customerdata

restdb.io will POST an event JSON object from the database to the URL endpoint each time a record event occurs.

Example event JSON object sent to the URL endpoint when a PUT trigger is called:

{
  "0": {
    "_id": "5660473aa389c34a0000035e",
    "title": "Suite 108",
    "_version": 2,
    "_created": "2015-12-03T13:44:26.034Z",
    "_createdby": "jones",
    "body": "Some text ...",
    "_changed": "2015-12-11T09:23:52.695Z",
    "_changedby": "jones@restdb.io"
  },
  "event": {
    "db": "rdb-nocms",
    "collection": "articles",
    "method": "PUT",
    "payload": [
      {
        "_id": "5660473aa389c34a0000035e",
        "title": "Suite 108",
        "_version": 2,
        "_created": "2015-12-03T13:44:26.034Z",
        "_createdby": "jones",
        "body": "Some text ...",
        "_changed": "2015-12-11T09:23:52.695Z",
        "_changedby": "jones@restdb.io"
      }
    ]
  }
}

The following example shows the data payload to the webhook when a DELETE is called for multiple documents.

{
  "0": "5bd9ea5b61126f280001263c",
  "1": "5bd9ea5b61126f280001263e",
  "event": {
    "db": "rdb-nocms",
    "collection": "articles",
    "method": "DELETE",
    "payload": [
      "5bd9ea5b61126f280001263c",
      "5bd9ea5b61126f280001263e"
    ]
  }
}

Creating a Webhook

To create a Webhook, activate Developer mode (top right corner), navigate to a Collection and click on the Webhook tab.

Enter the URL endpoint for the Webhook, check which event you want to trigger and check the Active checkbox. That's all there is to it. restdb.io will now call this URL each time one of the events occurs.

webhook success

Errors

If restdb.io gets an error while calling a Webhook this is logged and displayed. Subsequent errors will disable the Webhook, i.e. the Active checkbox is turned off. When you locate the error, activate the Webhook again.

webhook error

Tip

Create an URL endpoint for testing your Webhooks: https://httpbin.org or https://webhook.site/. This shows you all the data that are posted from restdb.io to that URL endpoint.

Read more about Webhooks at Wikipedia.