Commencer un nouveau sujet

PHP | How to create an API watcher and define its schema to meet your requirements

You can use this snippet to create a new watcher (or webhook) using the Watcher API. Once the watcher is created, Agendize platform will notify the subscribed URL (your third-party system: CRM, ERP...) and send the JSON structure each time a specific event is triggered.


Here is an example to create an Appointment watcher (for each appointment booked): 


<?php 
$apiKey = "";
$token = "";
$companyId = "";

//create a new cURL resource
$ch = curl_init("https://app.agendize.com/api/2.1/scheduling/companies/$companyId/appointments/watch?apiKey=$apiKey&token=$token");

//setup request to send json via POST
$data = array(
    'address' => "https://webhook.site/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
    // or: 'address' => "https://hooks.zapier.com/hooks/catch/yyyyyyy/xxxxxx/"
);
$payload = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

//set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

//execute the POST request
$result = curl_exec($ch);

//close cURL resource
curl_close($ch);
?>


You can also apply templating to the JSON format to map the data to your own JSON properties. Here is an example of a template applied to an appointment event watcher: 


{
  "address": "https://webhook.site/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
  "schema": {
    "id": "{id}",
    "staff": "{staff.firstName} {staff.lastName}",
    "firstName": "{client.firstName}",
    "lastName": "{client.lastName}",
    "email": "{client.email}",
    "phone": "{client.phone}",
    "datetime": {
      "start": "{start.dateTime}",
      "end": "{end.dateTime}"
    },
    "appointment": "{service.name}"
  },
  "addPreviousData": "false"
}



Connexion ou Inscription pour poster un commentaire