Create task in Clickup using Oauth2 API

1.4k Views Asked by At

I am looking to create a task in clickup using the API. I got the refresh token and generated the access token. But when I use this access token to create a task, I am getting error as {"err":"Oauth token not found","ECODE":"OAUTH_019"}

Can you please help. Below is my code for creating a task.

$accessToken = 'Bearer 4939XXXX_XXXXXXXXXXXXXXXXXXX'; 
$data = array(
    "name" => "New Test Task",
    "description" => "New Task Description",
    "assignees" => array(),
    "status" => "Open",
    "start_date" => strtotime(date("Y-m-d")),
);

$post_data = json_encode($data);
$url = "https://api.clickup.com/api/v2/list/163420181/task";

$headers = [];
$headers[] = 'Content-Type:application/json';
$headers[] = 'Authorization:"' . $accessToken . '"';

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
$result = curl_exec($curl);   // to perform the curl session
curl_close($curl);   // to close the curl session
print_r($result);
1

There are 1 best solutions below

0
On

Figured out the fix. Need to remove Bearer text from the access token and Authorization value shouldn't have double quote.

$headers[] = 'Authorization: '. $accessToken