3

This is the sample code but using Curl on cmd :

curl https://www.zopim.com/api/v2/chats -u {username}:{password}

How do I query it in PHP?

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
ivor
  • 307
  • 1
  • 6
  • 16

1 Answers1

3

maybe answered on How to use basic authorization in PHP curl so try from that:

<?php
$username='username';
$password='pass';
$URL='https://www.zopim.com/api/v2/chats';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result=curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);   //get status code
curl_close ($ch);

to print or show the json use:

$obj = json_decode($result);
print $obj->{'user'}; 
echo $obj->{'message'}; 
Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73