Skip to content

Instantly share code, notes, and snippets.

@bmcbride
Created February 12, 2014 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmcbride/8959544 to your computer and use it in GitHub Desktop.
Save bmcbride/8959544 to your computer and use it in GitHub Desktop.
Fulcrum webhook endpoint used for deleting a record from the device when the Status field is changed. In this case the Status field data name was left at the default 'status' (line 15). I set the default status to 'Active' (green) and added an additional status of 'Deleted' (red). When a user changes the status to 'Deleted' and syncs their devic…
<?php
# Fulcrum Info
$form_id = 'my_form_id'; // Get from App URL: https://web.fulcrumapp.com/data/{my_form_id}#
$fulcrum_api_key = 'my_fulcrum_api_key'; // Get from Fulcrum settings page
//$input = file_get_contents('payload.json'); # local file for testing
$input = file_get_contents('php://input'); # POST data from webhook
$data = json_decode($input, TRUE);
# Make sure it's the form we want
if ($data['data']['form_id'] == $form_id) {
# Grab record id and status values
$fulcrum_id = $data['data']['id'];
$status = $data['data']['status'];
# Listen for record update webhook event
if ($data['type'] == 'record.update') {
# If status is Deleted, delete the record via the API
if ($status == 'Deleted') {
$ch = curl_init('http://api.fulcrumapp.com/api/v2/records/'.$fulcrum_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'X-ApiToken: '.$fulcrum_api_key)
);
$result = curl_exec($ch);
curl_close($ch);
# Write payload out to file for inspection
/*$json = json_encode($input);
$data = json_decode($json, true);
$payload = fopen('payload.json', 'w+');
fwrite($payload, $data);
fclose($payload);*/
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment