anniec
anniec

Reputation: 3

How to set up a webhook in servicem8?

I am not sure where/how to set up a webhook in servicem8. I want to trigger an update when a Job status changes from Quote to Work Order. I have read the documentation, but am not clear on the process.

Upvotes: 0

Views: 740

Answers (1)

Brinkin
Brinkin

Reputation: 168

Webhooks in ServiceM8 are only supported when using OAuth authentication using an access token, so you will need to register for a free developer account to get your OAuth Client Id and Secret. If you have not yet done so, follow the steps listed here: http://developer.servicem8.com/docs/the-basics/public-applications/

Once you have OAuth authentication working, Subscribe to the 'Job' webhook to receive notifications when job data has changed. Do this by POSTing to https://api.servicem8.com/webhook_subscriptions

As mentioned on http://developer.servicem8.com/docs/platform-services/webhooks/ , the subscribe request should include:

  • object='job'
  • fields='status'
  • callback_url - Set this to the URL you wish to receive notifications

Once you subscribe to the webhook, you will immediately receive a request at your callback url to challenge you own this url. The request will contain URL parameters mode=subscribe, and a challenge value. To successfully confirm the challenge request you need to return a 200 result, with the body of the response set to the challenge code.

If you successfully confirm the challenge code request, you will start receiving notifications at your callback_url for any changes to job data within your ServiceM8 account. The notification you receive will contain JSON data similar to

{
"object": "job",
"entry": {
    "changed_fields": ["status"],
    "time": "2015-01-01 00:00:00",
    "uuid": "de305d54-75b4-431b-adb2-eb6b9e546013"
},
"resource_url": "https://api.servicem8.com/api_1.0/job/de305d54-75b4-431b-adb2-eb6b9e546013.json"
}`

Upvotes: 2

Related Questions