2

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"}]}

5
  • curl --help to get info about params. Commented May 9, 2014 at 11:39
  • Thanks @RahilWazir but my code is not working and i don't want to run it though command prompt. Commented May 9, 2014 at 11:40
  • What do you get back in the response? Commented May 9, 2014 at 11:41
  • Whats not working? Could you explain what response you are getting. Commented May 9, 2014 at 11:41
  • Can you provide API documentation? Does curl example in your post work? Commented May 19, 2014 at 21:19

2 Answers 2

2

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'));
Sign up to request clarification or add additional context in comments.

Comments

0

Looks like you forgot to json encode your data

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

2 Comments

@manwal Still you say. Thats tricky. At least we can deduct the body for now. Can you try to get another error by screwing up your auth, maybe to try to rule out that. Since I see you left that out from your curl
My other requests are working @Cleric but only this one is not working. I haven't found any code example in Doc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.