LiquidPlanner Classic Forum

Ask a Question
ANSWERED

Upload Documents via API

Hello, I'm having issues uploading files up to Liquid Planner through the use of the API. In an effort to solve this, I even created a simple form that uploads a data file to a temporary file then attempts the upload by calling the API. So far I found a complete example that should work provided in this form but still seem to not be having any luck. https://developer.liquidplanner.com/discuss/5d5c31a3f2fb1d038ed1c396 Code Snip it: //https://developer.liquidplanner.com/discuss/5d5c31a3f2fb1d038ed1c396 $url = "https://app.liquidplanner.com/api/workspaces/" . $workspaceID . "/tasks/" . $taskId . "/documents"; $file = realpath($fileLocation); $data = array( "document[file_name]" => $fileName, "document[description]" => $fileDesc, "document[attached_file]" => "@".$fileLocation, ); var_dump($data); $conn = curl_init(); curl_setopt($conn, CURLOPT_HEADER, 0); curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1); curl_setopt($conn, CURLOPT_ENCODING, ""); curl_setopt($conn, CURLOPT_USERPWD, $email . ":" . $password ); curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($conn, CURLOPT_POST, true); curl_setopt($conn, CURLOPT_URL, $url); curl_setopt($conn, CURLOPT_POSTFIELDS, $data); $response = curl_exec($conn); print_r( $response."\n" ); curl_close($conn); This is what var_dump is reporting: C:\wamp64\www\EIS\LP_Success.php:88: array (size=3) 'document[file_name]' => string 'ckt2.pdf' (length=8) 'document[description]' => string 'application/pdf' (length=15) 'document[attached_file]' => string '@C:\wamp64\www\EIS\uploads\ckt2.pdf' (length=35) {"type":"Error","error":"BadArgument","message":"You must POST a document[attached_file] part when creating a document."} I even went as far as to create a submit form coupled with a process file form to try to get this to work outside of my PHP App. If you would like me to send you the full source which is 2 files I'll be happy to do so. Thanks Miguel Grajeda
ANSWERED

Update Task Description - task_update

*Posted on behalf of a customer. Original posting date 2017-01-12.* What is the correct URL and JSON format? Here is my code, and don't worry about the $super_user_lp, it is working. Only the task_update is not working, and has no response by thisAPI call. ``` $response_update_task_prefix = $super_user_lp->task_update($task_id, $update_data); /* $update_data['name'] = "Prefix"."Original Task Name"; $update_data['description'] = "Prefix"."Original Description"; //By the way, may I update the Note like this:? $update_data['note'] = "New Note"."Original Note"; */ ``` ``` function task_update($taskid, $data){ $encodedTask = json_encode(array('task' => $data)); $url = 'https://app.liquidplanner.com/api/workspaces/{space ID}/tasks/'.$taskid; $response = $this->lp_put($url, $encodedTask); return($response); } ``` ``` function lp_put($endpoint_url, $encodedTask){ $curl = curl_init($endpoint_url); curl_setopt($curl, CURLOPT_HEADER, false); //$conn curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERPWD, trim($this->email).":".trim($this->password)); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); curl_setopt($curl, CURLOPT_ENCODING, "gzip"); ``` ``` // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // curl_setopt($curl, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($curl, CURLOPT_URL, $endpoint_url); // curl_setopt($curl, CURLOPT_POSTFIELDS, $encodedTask); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($encodedTask)); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec( $curl ); $error = curl_error($curl); // curl_close($curl); ``` ``` $results = json_decode($response, true); return $results; } ```
ANSWERED

How to get upload file path? PHP

*Posted on behalf of Feng. Original posting date 2016-12-09.* Here is the code. And the question is how to get the correct $file_path? The file supposed to be located on the local folder. Thanks! ``` $attachment_filename = "test.jpg"; $file_path = "@$attachment_filename"; ``` OR something like this: ``` $attachment_filename= $_FILES['userfile']['name'] ; $tmp_name = $_FILES['userfile']['tmp_name']; $dest_dir = 'upLoad'; $file_path = $dest_dir.'/'.$attachment_filename; ``` ... OR .... your suggestion code ``` //---------------------------------------------- $upload_file_response = $lp->attachDocument($file_path,$attachment_filename, $task_id); ``` ``` function attachDocument($file_path,$filename, $taskid) { ``` ``` $Data = array('document[attached_file]' => $file_path, 'document[file_name]'=> $filename); ``` ``` $url = $this->serviceurl . '/tasks/' . $taskid . '/documents'; $response = $this->lp_attach_file($url, $Data); return($response); } ``` ``` function lp_attach_file($endpoint_url, $Data) { ``` ``` $curl = curl_init($endpoint_url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERPWD, trim($this->email).":".trim($this->password)); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data")); curl_setopt($curl, CURLOPT_ENCODING, ""); // Prevent GZIP compression of response from LP ``` ``` curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_URL, $endpoint_url); curl_setopt($curl, CURLOPT_POSTFIELDS, $Data); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // Accept any SSL certificate $response = curl_exec($curl); $error = curl_error($curl); ``` ``` $results = json_decode($response, true); ``` ``` return $results; } ```
ANSWERED

Creating project | php

*Posted on behalf of Jorn Smits. Original posting date 2014-11-19.* Hi I'm trying to add a project in Liquidplanner with php, but i can't get it to work. I'm always getting the 500 error ( Internal Server Error) I'm using the liquidplanner class from github ``` https://github.com/jonoxer/php-liquidplanner/blob/master/liquidplanner.php ``` Haven't adapted anything, this is the code i'm using ``` <?php require_once('liquidplanner.php'); $name = "Test project"; $parent_id = xxxxxxx; $client_id = xxxxxx; $description = "Test"; /* Create an instance of the Liquid Planner object */ $lp = new LiquidPlanner("xxxxx", "xxxxxxx", "xxxxxxx"); /* Create a new task in Liquid Planner */ $response = $lp->projects_create($name,$client_id,$parent_id,$description); var_dump($response); // echo $response ?> ``` I've replaced all parameters with correct data. Can someone please tell me what I'm doing wrong. **Projects_create function:** ``` public function projects_create($name, $client_id, $parent_id, $description = '', $is_done = false, $done_on = '', $external_reference = '') ``` ``` { $encodedClient = json_encode(array('project' => array( 'name' => $name, 'client_id' => $client_id, 'parent_id' => $parent_id, 'description' => $description, 'is_done' => $is_done, 'done_on' => $done_on, 'external_reference' => $external_reference ))); var_dump($encodedClient); $url = $this->serviceurl.'/projects'; var_dump($url); $response = $this->lp_post($url, $encodedClient); return($response); } ``` **LP_post function:** ``` private function lp_post($url, $encodedTask) ``` ``` { var_dump($encodedTask); var_dump($this->email); var_dump($this->password); /* Set up the CURL object and execute it */ $conn = curl_init(); curl_setopt($conn, CURLOPT_HEADER, false); // Suppress display of the response header curl_setopt($conn, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); // Must submit as JSON curl_setopt($conn, CURLOPT_RETURNTRANSFER, true); // Return result as a string curl_setopt($conn, CURLOPT_POST, true); // Submit data as an HTTP POST curl_setopt($conn, CURLOPT_POSTFIELDS, $encodedTask); // Set the POST field values curl_setopt($conn, CURLOPT_ENCODING, ""); // Prevent GZIP compression of response from LP curl_setopt($conn, CURLOPT_USERPWD, $this->email.":".$this->password); // Authenticate curl_setopt($conn, CURLOPT_URL, $url); // Set the service URL curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, false); // Accept any SSL certificate $response = curl_exec($conn); var_dump($response); curl_close($conn); /* The response is JSON, so decode it and return the result as an array */ $results = json_decode($response, true); var_dump($results); ``` ``` /* Check for Throttling from the API */ if((isset($results['type']) && $results['type'] == "Error") && (isset($results['error']) && $results['error'] == "Throttled")) ``` ``` { //We're being throttled. Wait the right amount of time and call it again. $this->throttle_message($results); sleep($this->get_wait_time($results['message'])); return $this->lp_post($url, $encodedTask); } return $results; } ``` **Contructor:** ``` public function __construct($workspaceID, $email, $password) ``` ``` { $this->email = $email; $this->password = $password; $this->baseurl = "https://app.liquidplanner.com/api"; $this->serviceurl = $this->baseurl . "/workspaces/".$workspaceID; } ```
ANSWERED
ANSWERED
ANSWERED

Getting a 500 error when creating a task with PHP

*Posted on behalf of Mark Langridge. Original post date 2014-06-30* This is pretty much the same problem as the JAVA one posted earlier. However I am using double quotes, and can't see anything else that could be causing this. Target Url https://app.liquidplanner.com/api/workspaces/120300/tasks Posted String `` {"task":{"name":"API Task","parent_id":15821159}} `` The cURL trace is ``` * Adding handle: conn: 0x8eb06b0 * Adding handle: send: 0 * Adding handle: recv: 0 * Curl_addHandleToPipeline: length: 1 * - Conn 0 (0x8eb06b0) send_pipe: 1, recv_pipe: 0 * About to connect() to app.liquidplanner.com port 443 (#0) * Trying 93.184.219.117... * Connected to app.liquidplanner.com (93.184.219.117) port 443 (#0) * SSL connection using ECDHE-RSA-AES128-GCM-SHA256 * Server certificate: * subject: C=US; ST=Washington; L=Seattle; O=LiquidPlanner Inc.; OU=Technology; CN=*.liquidplanner.com * start date: 2014-02-07 00:00:00 GMT * expire date: 2017-02-17 12:00:00 GMT * issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA * SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway. * Server auth using Basic with user '**removed**' > POST /api/workspaces/120300/tasks HTTP/1.1 Authorization: Basic **removed** Host: app.liquidplanner.com Accept: */* Accept-Encoding: gzip User-Agent: KsCogs Curl Handler 1.0 content-type: application/json Content-Length: 120 * upload completely sent off: 120 out of 120 bytes < HTTP/1.1 500 Internal Server Error < Content-Encoding: gzip < Cache-Control: no-cache < Cache-Control: max-age=900 < Content-Type: application/json; charset=utf-8 < Date: Mon, 30 Jun 2014 12:56:20 GMT < Expires: Mon, 30 Jun 2014 13:11:20 GMT * Server Apache is not blacklisted < Server: Apache < Status: 500 Internal Server Error < Strict-Transport-Security: max-age=31536000 < Vary: Accept-Encoding < X-Frame-Options: SAMEORIGIN < X-Rack-Cache: invalidate, pass < X-Request-Id: 3684a601bdbd063a94fed827228082c2 < X-UA-Compatible: IE=Edge,chrome=1 < Content-Length: 118 < * Connection #0 to host app.liquidplanner.com left intact ``` And the response is ``` stdClass Object ( [type] => Error [error] => InternalServerError [message] => Internal error; try again and perhaps it will work (no promises). ) ``` anyone spot anything obvious?
ANSWERED
ANSWERED

Uploading a file to the task. [PHP] [cURL] [REST API]

*Posted on behalf of John Z. Original posting date 2012-11-26.* Hello, I am using the php client that you can get on [github](https://github.com/jonoxer/php-liquidplanner). I am having trouble uploading a file to a task. Well, this file is actually a string, and I want to upload that string as the file to the task. Below are two functions that I am using that I added to the client. ``` $data = the string that I want uploaded as a txt file. $taskid is the correct id for the task. public function attachDocument($data, $taskid) &#123; $encodedData = array('attached_file' => $data, 'file_name'=>'testing.txt'); $url = $this->serviceurl . '/tasks/' . $taskid . '/documents'; $response = $this->lp_attach_file($url, $data); return($response); &#125; private function lp_attach_file($url, $data) &#123; /* Set up the CURL object and execute it */ $conn = curl_init(); curl_setopt($conn, CURLOPT_HEADER, false); // Suppress display of the response header curl_setopt($conn, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data")); curl_setopt($conn, CURLOPT_RETURNTRANSFER, true); // Return result as a string curl_setopt($conn, CURLOPT_POST, true); // Submit data as an HTTP POST curl_setopt($conn, CURLOPT_POSTFIELDS, $data); // Set the POST field values curl_setopt($conn, CURLOPT_ENCODING, ""); // Prevent GZIP compression of response from LP curl_setopt($conn, CURLOPT_USERPWD, $this->email . ":" . $this->password); // Authenticate curl_setopt($conn, CURLOPT_URL, $url); // Set the service URL curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, false); // Accept any SSL certificate $response = curl_exec($conn); curl_close($conn); /* The response is JSON, so decode it and return the result as an array */ $results = json_decode($response, true); /* Check for Throttling from the API */ if ((isset($results['type']) && $results['type'] == "Error") && (isset($results['error']) && $results['error'] == "Throttled")) &#123; //We're being throttled. Waith 15 seconds and call it again. $this->throttle_message(); sleep($this->throttlewait); return $this->lp_post($url, $data); &#125; return $results; &#125; ``` I get a response from curl_exec, which is: ``` "&#123;"type":"Error","error":"BadArgument","message":"Expected a hash of attribute values for document parameter"&#125;" ``` I have been messing with this a while now, if anyone could help me out or give me some examples I would really appreciate it! Let me know if I can provide you with any more info about the program. Thanks!!