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): 

$apiKey = "";
$token = "";
$companyId = "";

//create a new cURL resource
$ch = curl_init("$companyId/appointments/watch?apiKey=$apiKey&token=$token");

//setup request to send json via POST
$data = array(
    'address' => ""
    // or: 'address' => ""
$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

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": "",
  "schema": {
    "id": "{id}",
    "staff": "{staff.firstName} {staff.lastName}",
    "firstName": "{client.firstName}",
    "lastName": "{client.lastName}",
    "email": "{}",
    "phone": "{}",
    "datetime": {
      "start": "{start.dateTime}",
      "end": "{end.dateTime}"
    "appointment": "{}"
  "addPreviousData": "false"

Connexion ou Inscription pour poster un commentaire