4

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?

7
  • curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); Commented Jun 27, 2017 at 2:18
  • @ivor this API is on post or get method? I think it is post, right? Commented Jun 27, 2017 at 2:26
  • hmm.. i need to get the json of this link... Commented Jun 27, 2017 at 2:27
  • @ivor but which kind of method this API is using? post or get bro! Commented Jun 27, 2017 at 2:29
  • @duongkhang Get method bro... Commented Jun 27, 2017 at 2:45

1 Answer 1

4

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'}; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.