LiquidPlanner Classic Forum

Ask a Question
Back to All

Adding Document to Task

(edited)

Posted on behalf of a customer. Original posting date 2013-12-27

Hi There,

I have a form creating a task then adding a note and a comment to it after creation and it is working perfectly. I am using php and also trying to upload a file after the task is created and can't seem to get it to work. The error in the response I am getting is "You must POST a document[attached_file] part when creating a document." which seems like it means it isen't getting the file but if I echo the value I am putting in there it seems to work. Below is my code, what am I doing wrong?

//Document Creation 
//Fields to fill in the document json format 
$doc = array( 
"document" => array( 
"file_name" => $_FILES['file']['name'], 
"attached_file" => file_get_contents("files/".$_FILES['file']['name']) 
) 
);

curl_setopt($conn, CURLOPT_URL, $url."/tasks/".$responseOne->id."/documents" ); 
curl_setopt($conn, CURLOPT_POST, true); 
curl_setopt($conn, CURLOPT_POSTFIELDS, json_encode( $doc ) );

$responseFour = json_decode(curl_exec($conn)); //Get the data returned by LP and reformat from JSON

Thanks for the help!