Planfix API: Example of getting a list of projects on PHP

From Planfix
Jump to: navigation, search

A simple example of getting a list of projects and outputting it.

<?php
<?php

$api_server = 'https://api.planfix.com/xml/';
$api_key = 'APIKey-YOUR_APPLICATION';// 
$api_token = 'AUTHORIZATION_TOKEN';

/** get the list of available projects and output it
 * using functions on: https://t.ly/B0Zqs
 */
$requestXml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><request method="project.getList"><account></account></request>');

$requestXml->account = 'your_account';
$requestXml->pageCurrent = 1;
// he rest of the parameters are optional, experiment yourself

$ch = curl_init($api_server);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // do not output the response to stdout
curl_setopt($ch, CURLOPT_HEADER, 1);   // get headers
// do not check SSL certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// do not check Host SSL certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $api_key . ':' . $api_token);

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXml->asXML());
echo $requestXml->asXML();

$response = curl_exec($ch);
$error = curl_error($ch);
var_dump($error);

$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$responseBody = substr($response, $header_size);

curl_close($ch);

var_dump($responseBody);
?>


Go To