1

For few days I am trying to use the ClickUp API. The goal is: We have a form, and when the form is submitted, it creates a task on a space on ClickUp.

It is a PHP form, and even with the API Doc here, I am not able to understand how it is working. I found this: https://jsapi.apiary.io/apis/clickup20/reference/0/tasks/create-task.html

But it requires some access token, from the user, but normally, It's not supposed to work like that.

Here the script that I have taken from the doc:

    <?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.clickup.com/api/v2/list/17229593/task");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_POSTFIELDS, "{
  \"name\": \"New Task Name\",
  \"content\": \"New Task Content\",
  \"assignees\": [
    183
  ],
  \"tags\": [
    \"tag name 1\"
  ],
  \"status\": \"Open\",
  \"priority\": 3,
  \"due_date\": 1508369194377,
  \"due_date_time\": false,
  \"time_estimate\": 8640000,
  \"start_date\": 1567780450202,
  \"start_date_time\": false,
  \"notify_all\": true,
  \"parent\": null,
  \"custom_fields\": [
    {
      \"id\": \"0a52c486-5f05-403b-b4fd-c512ff05131c\",
      \"value\": 23
    },
    {
      \"id\": \"03efda77-c7a0-42d3-8afd-fd546353c2f5\",
      \"value\": \"Text field input\"
    }
  ]
}");

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  "Authorization: "access_token"",
  "Content-Type: application/json"
));

$response = curl_exec($ch);
curl_close($ch);

var_dump($response);

When I try that, I get the error 500, and when I go to the API's link, I get an Auth problem.

Is someone know something about this API?

Tim Post
  • 33,371
  • 15
  • 110
  • 174
Yanis Abt
  • 11
  • 3
  • 3
    Please never, ever, ever manually construct json strings ... ever. Form your array, then `json_encode()` it. This is **OAuth2**. You are going to need to follow the directions in their documentation. – mickmackusa Mar 25 '20 at 13:03
  • You need to use a "refresh token" to get an "access token". The access token can be used many times to make API endpoint calls, but will have small lifespan. I just happen to be doing this kind of work (for that last few weeks). – mickmackusa Mar 25 '20 at 13:09
  • Hey @mickmackusa, we don't want member who submitted the form to be logged in. We want that automatically. Form sent = Task created on ClickUp – Yanis Abt Mar 25 '20 at 13:10
  • How is this problem related to "forms", "json" or "cURL"? If you receive an error 500 from an API provider, the request is malformed and triggers a server error – Nico Haase Mar 25 '20 at 13:21
  • 1
    There needs to be some flow in your system whereby a specific user "grants your application authorization" to access _their_ data (within the specified "scope(s)" that were agreed to when access was granted). Upon receiving their permission, you will need to database the generated "refresh token". Then, every time that you want to do something with that user's data, you will need to get a fresh access token using their refresh token, before you make the API endpoint calls -- the endpoint calls are generalized, so the only way to know that you are accessing their data is to use their token. – mickmackusa Mar 25 '20 at 13:24
  • 1
    I should correct what I said... in this case, don't `json_encode()` the POST payload, use `http_build_query($array)`. – mickmackusa Mar 25 '20 at 13:26
  • The json comes from the documentation, for the moment, it is just to test. About tag, "forms" because it is linked to a form, "json" because it is json, "cURL", because it is the way to get this – Yanis Abt Mar 25 '20 at 14:15

0 Answers0