Advertisement
livechatinc

Webhook - example

Dec 16th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2.  
  3. $apiURL = "https://api.livechatinc.com";
  4.  
  5. $data = file_get_contents('php://input');
  6. $data = json_decode($data);
  7.  
  8. $license_id = $data->license_id;
  9. $token = $data->token;
  10. $visitor_id = $data->visitor->id;
  11.  
  12. global $response;
  13. $data = array(
  14.     'name' => 'time - test',
  15.     'value' => time(),
  16. );
  17.  
  18. $response[] = (object)$data;
  19.  
  20. $postfields = http_build_query(array(
  21.     'license_id' => $license_id,
  22.     'token' => $token,
  23.     'icon' => 'cdn.livechatinc.com/website/media/img/resources/logos/livechat_64x64.png',
  24.     'id' => 'my-integration',
  25.     'fields' => $response
  26. ));
  27.  
  28. $ch = curl_init();
  29. curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-API-Version: 2'));                
  30. curl_setopt($ch, CURLOPT_URL, $apiURL.'/visitors/'.$visitor_id.'/details');
  31. curl_setopt($ch, CURLOPT_POST, 1);
  32. curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  33. $result = curl_exec($ch);
  34. curl_close($ch);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement