Webhooks

Receive events from Coredination in near-realtime.

What are Webhooks?

Webhooks are a way for you to receive events from Coredination in near-realtime. They are simply HTTP callbacks. You can subscribe to events of interest and we'll POST data to the URL you specify when those events occur.

Webhooks are available for a bunch of different types of events. They are organized into channels and event types. Channels are roughly equivalent to the resources (aka entities) in the API. Event types are also visible throughout other parts of the API and applications.

To add a subscription you need to specify:

  • A valid URL that will receive our POST requests with a response status in the 200s.
  • What channels you want to subscribe to.
  • A regular expression event type filter (if any).
You also need an API key. If you know you're only going to handle a few events, we encourage the use of event type filters so that we don't send you events that you're not going to care about.

Subscribing to Webhooks

Webhook subscriptions are managed via the API. The curl examples below can of course be modified to use whatever language or mechanism you're using to talk to the API.

1. Create an API key

If you don't have an API key yet, head over to the API settings page and create one. All you need to fill out is an application name, the rest will be pre-filled. You can just call it My Webhook API Test or something like that for now.

2. Setup an endpoint to receive the webhook events

In order to receive the webhook events, you need to provide a publicly accessible endpoint that accepts JSON data.

You don't need to start by implementing your receiving endpoint and deploying on a server right away. We recommend you start using requestb.in. It allows you to inspect what the webhooks look like quickly in your browser. Once you start developing stuff on your local machine you can also use UltraHook to make it available on the interwebs.

3. Create a webhook subscription

At this point you need to decide what channel(s) to subscribe to. If you don't know or care at this point, try the job channel.

curl -i 'https://app.coredination.net/api/1/webhook' \
	-H 'API-Key: {my-api-key}' \
	-H 'Content-Type: application/json' \
	-X POST \
	-d '{ "url": "http://requestb.in/13jr22w1", "channels": [ "job" ] }'

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
{
    "uuid": "a540e834-5c54-4b07-b471-e3c1cb027af9",
    "active": true,
    "channels": [ "job" ],
    "eventTypeFilter": null,
    "url": "http://requestb.in/13jr22w1"
}

4. Trigger an event

Log in to the web application and create a job (or do anything else that generates a job event).

If you don't want to make any changes to your data but still want to test your webhook, you can issue an empty POST request to https://app.coredination.net/api/1/webhook/:subscriptionUuid/test and you'll receive a special webhook event with eventType="TEST".

5. Verify that the event was received

You should receive your event a few seconds after it was triggered. If you're using requestb.in just point your browser at your bin with ?inspect added to it, like http://requestb.in/13jr22w1?inspect.

Contents

Once you have a subscription going, your server will be bombarded with requests looking something like:

POST https://my.url.com/coredination/webhook
Content-type: application/json; charset=UTF-8
X-Webhook-Signature: 0cG7he1ZCphRTd7GYYW1CPPIWhk=
{
	"channel": "job",
	"eventType": "CREATE",
	"eventTimeStamp": 1377550047244,
	"entityClass": "Job",
	"entityUuid": "a6ba7c52-4da6-4cc3-bf52-db3e6684e0ab",
}
The example shows the event you'll receive when a new job has been created. The JSON content is pretty printed here for clarity, the real ones you'll receive will not be.

Security

The webhook request includes the X-Webhook-Signature header which contains an HMAC-SHA1 signature of the body of the request, signed with your API secret.

Verifying the signature is optional so you can get started without caring about that. Keep in mind though that without any kind of verification anyone could start sending requests to your endpoint as long as they know the URL.

You can use the following code example to generate the signature and compare with the one received in the header:

Timing and Reliability

Webhook requests will be fired off pretty much in real-time when an event has occurred. Requests are processed in a worker-queue scheme on our end, so they might be slightly delayed if our server load is high.

In case of network timeout, or if the endpoint responds with status code 404, 408, 409, 500, 502, 503 or 504, the request will be retried 5 times with 1 minute interval.

Channels and Events

The following table lists available channels and events.

ChannelEvent typeDescription
jobCREATE, UPDATE, DELETEA job has been created, updated or deleted.
jobAll job eventsPlease see the list of job event types on the job resource page.
workreportCREATE, UPDATE, DELETEA work report has been created, updated or deleted.
invoiceCREATE, UPDATE, DELETEAn invoice has been created, updated or deleted.
customerCREATE, UPDATE, DELETEA customer has been created, updated or deleted.
articleCREATE, UPDATE, DELETEAn article has been created, updated or deleted.
assetCREATE, UPDATE, DELETEAn asset has been created, updated or deleted.

Webhook resource reference

List subscriptions

List webhook subscriptions that belong to your API key.

Example

GET /webhook
Response

A list of webhook subscriptions.

[
	{
	    "uuid": "a540e834-5c54-4b07-b471-e3c1cb027af9",
	    "active": true,
	    "channels": [ "job" ],
	    "eventTypeFilter": null,
	    "url": "http://requestb.in/13jr22w1"
	},
	{
	    "uuid": "33e8a280-fa71-4d28-9e2e-11a62beb485a",
	    "active": false,
	    "channels": [ "customer", "article" ],
	    "eventTypeFilter": "(CREATE|DELETE)",
	    "url": "http://my.fantastic.application.com/webhook/fantasy"
	},
]
Method
GET
URL
/webhook
Authentication
Key
Response
List of WebhookSubscription

Get a subscription

Get a specific subscription by its UUID.

Example

GET /webhook/a540e834-5c54-4b07-b471-e3c1cb027af9
Response

A webhook subscriptions.

{
    "uuid": "a540e834-5c54-4b07-b471-e3c1cb027af9",
    "active": true,
    "channels": [ "job" ],
    "eventTypeFilter": null,
    "url": "http://requestb.in/13jr22w1"
}
Method
GET
URL
/webhook/:uuid
Authentication
Key
Response
WebhookSubscription

Create a subscription

Create a new subscription.

Example

POST /webhook
Content-type: application/json

{
    "active": true,
    "channels": [ "customer" ],
    "eventTypeFilter": "CREATE.*",
    "url": "http://requestb.in/13jr22w1"
}

Response

The created webhook subscriptions.

Method
POST
URL
/webhook
Authentication
Key
Response
WebhookSubscription

Update/create a subscription

Update a subscription, or create a new one if the UUID doesn't exist.

Example

PUT /webhook/a540e834-5c54-4b07-b471-e3c1cb027af9
Content-type: application/json

{
    "active": false,
}

Response

The updated/created webhook subscriptions.

Method
PUT
URL
/webhook/:uuid
Authentication
Key
Response
WebhookSubscription

Delete a subscription

Delete a subscription by its UUID.

Example

DELETE /webhook/a540e834-5c54-4b07-b471-e3c1cb027af9
Method
DELETE
URL
/webhook/:uuid
Authentication
Key
Response
Status code only

Queue a test event

Queue a test event. This will cause the webhook to be called within a few seconds.

Example

POST /webhook/a540e834-5c54-4b07-b471-e3c1cb027af9/test
Method
POST
URL
/webhook/:uuid/test
Authentication
Key
Response
Status code only

Get event log

Get the last events called by this webhook, sorted by descending timestamp (newest first). At the time of writing, the last 100 events are stored, although this might change at any point. So please use this only for testing and verification and don't rely on it.

Query Parameters

limit Maximum number of events to get Integer 1

Example

GET /webhook/a540e834-5c54-4b07-b471-e3c1cb027af9/log?limit=1

This would get the last event.

Response

A list of webhook events.

[
  {
    "url": "http://requestb.in/13jr22w1",
    "tryCount": 0,
    "responseTimeStamp": 1442952578310,
    "responseTime": 198,
    "responseStatus": 200,
    "requestTimeStamp": 1442952578112,
    "event": {
      "eventType": "UPDATE",
      "eventTimeStamp": 1442952578092,
      "entityUuid": "107d6dcb-6de8-4d2e-8a8a-2927c9799a16",
      "entityClass": "Job",
      "channel": "job"
    },
    "errorMessage": null
  }
]
Method
GET
URL
/webhook/:uuid/log
Authentication
Key
Response
List of webhook events