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