להלן דוגמת קוד PHP לאוטומציה:
<?php
/*
How to use:
1 – add your contact details in an array
$contact = array(
'Email' => YOUR_CONTACT_EMAIL,
'FirstName' => YOUR_CONTACT_FIRSTNAME,
'LastName' => YOUR_CONTACT_LASTNAME,
'PhoneNumber' => YOUR_CONTACT_PHONE,
// any other parameters…
);
2 – call the function
echo send_event(YOUR_USERNAME,YOUR_TOKEN,YOUR_EVENT_NAME,$contact)
*/
// function gets the following input: username, token, event name and an array with the contact
// it formats everything in JSON and posts it to the automation API
function send_event($Username,$Token,$ApiEventName,$contact) {
header('Content-type: application/json');
//API Url
$url = 'https://capi.inforu.co.il/api/Automation/Trigger?json=';
// Comment above line and uncomment line below to
// test your parameters with webhook.site – first get your unique URL for testing
//$url = 'https://webhook.site/…………….';
//create a new cURL resource
$ch = curl_init($url);
//setup request to send json via POST
$user = array(
'Username' => $Username,
'Token' => $Token
);
$data = array(
'ApiEventName' => $ApiEventName,
'Contacts' => array($contact)
);
// use json_encode to format the arrays as JSON
$payload = json_encode(array('User' => $user, 'Data' =>$data));
//attach encoded JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
//set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
//return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute the POST request
$result = curl_exec($ch);
// return the result
return $result;
//close cURL resource
curl_close($ch);
}
?>