Advertisement
livechatinc

Webhook - example

Nov 3rd, 2015
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 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.  
  9. $license_id = $data->license_id;
  10. $token = $data->token;
  11. $visitor_id = $data->visitor->id;
  12.  
  13. $response = array();
  14. $data = array(
  15.     'name' => 'time',
  16.     'value' => time(),
  17. );
  18.  
  19. $response[] = (object)$data;
  20.  
  21. $postfields = http_build_query(array(
  22.     'license_id' => $license_id,
  23.     'token' => $token,
  24.     'id' => 'my-integration',
  25.     'fields' => $response
  26. ));
  27.  
  28. // send request back to LiveChat API
  29.  
  30. $ch = curl_init();
  31. curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-API-Version: 2'));                
  32. curl_setopt($ch, CURLOPT_URL, $apiURL.'/visitors/'.$visitor_id.'/details');
  33. curl_setopt($ch, CURLOPT_POST, 1);
  34. curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  35. $result = curl_exec($ch);
  36. curl_close($ch);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement