Simple GET request in PHP

54 views
Skip to first unread message

pa...@paulgobble.com

unread,
Oct 4, 2018, 11:42:16 AM10/4/18
to Capsule API
I’m having trouble with a very simple GET request to the Capsule API. I’m asking for the list of open Tasks with their associated Cases. This went easy enough prototyping the GET request with the CURL terminal application.

curl -H "Authorization: Bearer{token}“ https://api.capsulecrm.com/api/v2/tasks?embed={“kase”}?status={“open”}

This did just want I wanted. But moving over to PHP hasn’t worked as well.

// Get cURL resource
$curl = curl_init();

// Prepping the Capsule CRM URL
$capsuleBaseUrl = 'https://api.capsulecrm.com/api/v2/';
$capsuleDetails = 'tasks?embed={“kase”}?status={“open”}';

// Set a single option, the URL
curl_setopt($curl, CURLOPT_URL, $capsuleBaseUrl . $capsuleDetails);
// Set a single option, Return results as string
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

// Prepping the Capsule CRM custom request headers
$request_headers = array();
$request_headers[] = 'Authorization: Bearer{token}’;
$request_headers[] = 'Accept: application/json';

// Setting the Capsule CRM custom request headers
curl_setopt($curl, CURLOPT_HTTPHEADER, $request_headers);

// Send the request & save response to $resp
$resp = curl_exec($curl);

// Close request to clear up some resources
curl_close($curl);

// Barf test results
echo("<h3>Barfing test results</br></h3>");
echo($resp);

This code results in
400 Bad request
Your browser sent an invalid request.

When I simplify the $capsuleDetails to just ‘tasks’ it functions, but I don’t get the associated Case data like I was able to using the CURL command line app. Can you help me get the PHP request straightened out?

Thanks,
Paul

Ross Grayton

unread,
Oct 4, 2018, 11:55:22 AM10/4/18
to Capsule API
Hi Paul,

Changing $capsuleDetails to 'tasks?embed=kase&status=open' fixes it for me - does that work for you?

Thanks,
Ross

pa...@paulgobble.com

unread,
Oct 4, 2018, 12:12:04 PM10/4/18
to Capsule API
Ross,

Yes it did!  I tried escaping the quotes, but it didn't occur to me to simply leave the out.

Thanks!
Reply all
Reply to author
Forward
0 new messages