LiquidPlanner Classic Forum

Ask a Question
Back to All

Creating project | php

(edited)

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;
}