Webhooks

Webhooks are URLs that will be called automatically with relevant Parse on Buddy data (in JSON format) as a result of Cloud Code triggers or functions. For more details on Cloud Code triggers and functions see here.

Trigger webhooks

To create a trigger webhook, you must select the Cloud Code trigger that will fire the webhook, and enter the class name. When the trigger fires for the specified class, the webhook will be called with JSON associated with the object. Here is a list of supported Cloud Code triggers:

beforeSave
afterSave
beforeDelete
afterDelete

For example, if you wanted your webhook to be called every time a User is deleted, you would select the ‘afterDelete’ trigger and enter ‘User’ as the class name in the Create a webhook dialog.

The webhook will receive the following example names/values in JSON format:
{
“triggerName”: “beforeSave”, // either beforeSave, afterSave, beforeDelete, or afterDelete
“object”: {
“{object name 1}”: “{object value 1}”,
“{object name 2}”: “{object value 2}”,
etc.
},
“master”: false, // always false, can be ignored
“log”: { “appID”: “{Parse on Buddy app ID}” }, // contains the app ID associated with this trigger in the ‘appID’ property. This will allow the webhook to service multiple apps.
“installationId”: // can be ignored
}

For the beforeSave trigger, your webhook can return JSON that either disallows the save of the object, or changes it. Here is example JSON:

Disallow:
{
“error”: “{your error message}”
}

Change object:
{
“success”: {
“className”: “{class name of object}”,
“{object name 1}”: “{object value 1}”, // you should return all the name/values you received in the webhook, modifying as desired.
“{object name 2}”: “{object value 2}”,
etc.
}
}

For the beforeDelete trigger, your webhook can return JSON that either disallows the delete of the object, or accepts it. Here is example JSON:

Disallow:
{
“error”: “{your error message}”
}

Change object:
{
“success”: “{your success message}”
}

 

Function webhooks

When you create a function webhook, you must enter the name of the Cloud Code function that will fire the webhook. Every time the function is called, either by the REST API or by scheduling it in the Jobs UI, the webhook will fire.

The webhook will receive the following example names/values in JSON format:

{
“params”: {
“{param name 1}”: “{param value 1}”,
“{param name 2}”: “{param value 2}”
}, // JSON sent to the Cloud Code function
“master”: false, // always false, can be ignored
“log”: { “appID”: “{Parse on Buddy app ID}” }, // contains the app ID associated with this trigger in the ‘appID’ property. This will allow the webhook to service multiple apps.
“headers”: {
“{header name 1}”: “{header value 1}”,
“{header name 2}”: “{header value 2}”
}, // contains all the HTTP headers passed up with the Cloud Code function
“functionName”: “{your function name}” // name of the Cloud Code function call that fired the webhook. This will allow the webhook to service multiple functions.
}