PHP | How to create an API watcher

Publié sur un an il y a par  Julien Pauthier

Publier un sujet
Julien Pauthier
Julien Pauthier Administrateur

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:

0 Votes

0 Commentaires

Connexion ou S'inscrire pour poster un commentaire