If you’re familiar with webhooks it shouldn’t take long to integrate webhooks from Costlocker.

  1. Create webhooks
  2. Edit time entries via API or at costlocker.com
  3. Receive webhooks
  4. Delete webhooks

Today we notify you about about created and updated time entries.

0. Configuration

Prepare environment variables so curl example are little more readable.

CL_AUTH="webhooks_test:YOUR_PERSONAL_TOKEN"
CL_API="https://new.costlocker.com/api-public/v2"
CL_WEBHOOK="UUID_OF_EXISTING_WEBHOOK (create variable after first step)"

1. Create webhooks

Let’s prepare webhooks request. I recommend using http://requestb.in/ for testing webhooks before you start writing production integration.

curl -X POST -u $CL_AUTH "$CL_API/webhooks" -d @webhooks-request.json

webhooks-request.json

[
   {
      "url":"http://requestb.in/123v1fw1?all",
      "events":[
         "timeentries.create",
         "timeentries.update"
      ]
   }
]

Costlocker returns uuid of created webhook. Save it in the environment variable CL_WEBHOOK.

{
   "meta":{
      "created":1,
      "updated":0
   },
   "data":[
      {
         "uuid":"2113a6ab-7d6a-42e6-852e-e9e7713df981",
         "links":{
            "webhook":"https://new.costlocker.com/api-public/v2/webhooks/2113a6ab-7d6a-42e6-852e-e9e7713df981"
         }
      }
   ]
}

2. Edit time entries

Trigger some changes in time entries. You could simply add/edit entries at costlocker.com, import time entries from Toggl etc. This article isn’t about creating time entries. So we expect that you somehow edit at least one entry :)

3. Receive webhooks

Immediately after editing entries you should see webhook event in requestb.in:

requestb.in example

Tip: use /webhooks/uuid/test endpoint for getting event structure without triggering any change.

curl -X GET -u $CL_AUTH "$CL_API/webhooks/$CL_WEBHOOK/test"

4. Delete webhooks

If you don’t need webhook anymore you can delete it.

curl -X DELETE -u $CL_AUTH "$CL_API/webhooks/$CL_WEBHOOK"

Slack notifications

Now you can push notifications to Slack. Add Slack webhook to url in 1st step. Check slack documentation if you’ve never worked with Slack webhooks.

Don’t forget to transform Costlocker events to Slack message. You can test it without a running server by copy-pasting payload from http://requestb.in/. Or test your message in Message Builder.

Slack message preview

Did you find a mistake? Is something unclear or isn’t the code working? Help us to improve the article!