Question

I am unable to convert this command line curl to php:

Structure

curl -X POST https://kanbanflow.com/api/v1/tasks -H "Content-type: application/json"
-d '{ "<PROPERTY_1>": <PROPERTY_VALUE_1>, "<PROPERTY_2>": <PROPERTY_VALUE_2>, ... "<PROPERTY_N>": <PROPERTY_VALUE_N> }'

Example in api documentation

curl -X POST https://kanbanflow.com/api/v1/tasks -H "Content-type: application/json"
-d '{ "name": "Write report", "columnId": "7ca19de0403f11e282ebef81383f3229", "color": "red" }'

I can't understand what is -d here? and how to pass data in this format.

so far i reach here but its not working.

Updated Code

$data = json_encode(array('name'=>'Testing of api', 'columnId' =>"xxxxxxxxxxxxxxxxxxx",'color'=>"red"));

$token = base64_encode("apiToken:xxxxxxxxxxxxxxxxxxxxxxxxx");

$headers = array(
        "Authorization: Basic " . $token,
        "Content-type: application/json"
);

$url = "https://kanbanflow.com/api/v1/tasks";

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
echo "<pre>";
print_r($response);

Suggest me where i am wrong..

Update

I want to use https://kanbanflow.com api to add task

Response: {"errors":[{"message":"Unexpected error"}]}

Was it helpful?

Solution

I got solution of my problem i was missing swimlaneId attribute. I am posting code here for future reference so it will help others.

Now sending data using object like following

$object = new stdClass();
   $object->name = 'Testing Task';
   $object->columnId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
   $object->swimlaneId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
   $object->color = 'green';

$url = "https://kanbanflow.com/api/v1/tasks";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($object));
$response = curl_exec($curl); 

Array of Json_encode is also working here

$data = json_encode(array('name'=>'Testing of api', 'columnId' =>"f648831061e111e3a41aa3dbd7a40406", 'color'=>'red', 'swimlaneId' => 'd0635fc061e711e3a41aa3dbd7a40406'));

OTHER TIPS

Looks like you forgot to json encode your data

$data = json_encode(array('name'=>'Testing of api', 'columnId' =>"xxxxxxxxxxxxxxxxxxx",'color'=>"red"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top