user4651092
user4651092

Reputation:

How to use a curl GET call code inside php

I have this code give from a platform called wrike. Code:

curl -g -X GET -H 'Authorization: bearer <token_here>' 
     'https://www.wrike.com/api/v3/tasks?&fields=["metadata","attachmentCount",
           "parentIds","sharedIds","superParentIds","description",
           "briefDescription","hasAttachments","responsibleIds","recurrent",
           "superTaskIds","subTaskIds","customFields","authorIds","dependencyIds"]' 

My question is, how to turn this code into php? When executed the response from strike is in json. I don't need to know how to fetch the response. (already have created the code for it.) I just want to know how to use this code inside a php file. Thanks

Upvotes: 0

Views: 187

Answers (1)

adampweb
adampweb

Reputation: 1469

try this: (// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/)

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.wrike.com/api/v3/tasks?&fields=[\"metadata\",\"attachmentCount\",\"parentIds\",\"sharedIds\",\"superParentIds\",\"description\",\"briefDescription\",\"hasAttachments\",\"responsibleIds\",\"recurrent\",\"superTaskIds\",\"subTaskIds\",\"customFields\",\"authorIds\",\"dependencyIds\"]");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");


$headers = array();
$headers[] = "Authorization: bearer <token_here>";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

Upvotes: 1

Related Questions