<?php require_once "../main.php"; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_POST); $Client->addHeader(REST_CLIENT::HEADER_AUTHORIZATION, '[your api key]'); $Client->setData('<?xml version="1.0" encoding="utf-8"?> <request method="invoice.list"> </request>'); $result = $Client->request('https://[username].freshbooks.com/api/2.1/xml-in', REST_CLIENT::CONTENT_XML); echo '<ul>'; foreach ($result->invoices->invoice as $invoice) { echo '<li>' . $invoice->invoice_id . ': ' . $invoice->organization . ' (' . $invoice->status . ')</li>'; } echo '</ul>'; } catch (Exception $e) { echo 'Problems with freshbooks.'; }
<?php include '../../main.php'; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); //$Client->useFopen(); // Also works with Fopen //$Client->addHeader(REST_CLIENT::HEADER_COOKIE, 'Variable1=Value1; Variable2=Value2;'); // String method $Client->addHeader(REST_CLIENT::HEADER_COOKIE, array('Variable1' => 'Value1', 'Variable2' => 'Value2')); // Array method $result = $Client->request('http://localhost/REST_SOCKET_CLIENT/examples/cookies/endpoint.php'); echo $result; } catch (Exception $e) { echo 'Service seems to be offline!'; }
<?php include '../main.php'; try { // Create api client instance $Client = new REST_CLIENT(); // Get token to authenticate our requests $Client->setMethod(REST_CLIENT::METHOD_GET); // This is not required because the default method is GET $Client->addHeader(REST_CLIENT::HEADER_AUTHORIZATION, 'Basic ' . base64_encode('[email]:[password]')); $result = $Client->request('https://www.pivotaltracker.com/services/v3/tokens/active', REST_CLIENT::CONTENT_XML); $token = trim($result->guid); // Get activity log $Client->reset(); $Client->addHeader('X-TrackerToken', $token); $result = $Client->request('http://www.pivotaltracker.com/services/v3/projects/232211/activities?limit=20', REST_CLIENT::CONTENT_XML); // Show activity log echo '<ul>'; foreach ($result->activity as $activity) { echo '<li>' . $activity->description . '</li>'; } echo '</ul>'; // Create a new project // We don't need to set the token again because it is still set from the get activity log above $Client->setMethod(REST_CLIENT::METHOD_POST); $Client->addHeader(REST_CLIENT::HEADER_CONTENT_TYPE, 'application/xml'); $Client->setData('<project><name>Test project by Api Client</name><iteration_length type="integer">2</iteration_length></project>'); $result = $Client->request('http://www.pivotaltracker.com/services/v3/projects', REST_CLIENT::CONTENT_XML); if (isset($result->id)) { echo 'New project is created an has ID: ' . $result->id; }
<?php include '../../main.php'; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); $Client->useFopen(); // Also works with Fopen $Client->addHeader(REST_CLIENT::HEADER_AUTHORIZATION, 'Basic ' . base64_encode('admin:tester')); $result = $Client->request('http://localhost/REST/Examples/basicauth/secured/index.html'); echo $result; } catch (Exception $e) { echo 'Your username/password combination seems to be wrong!'; }
<?php include '../main.php'; try { $Client = new REST_CLIENT(); $Client->setMethod(REST_CLIENT::METHOD_GET); // This is not required because the default method is GET //$Client->useFopen(); // Also works with Fopen $Client->addHeader(REST_CLIENT::HEADER_CUSTOMREQUEST, 'GET /CMD_API_SHOW_USERS? HTTP/1.0'); $Client->addHeader(REST_CLIENT::HEADER_AUTHORIZATION, 'Basic ' . base64_encode('[username]:[password]')); $result = $Client->request('[direct admin url]:2222', REST_CLIENT::CONTENT_QUERYSTRING); print_r($result); } catch (Exception $e) { echo 'Can\'t connect to DirectAdmin!'; }
<?php require_once "../../main.php"; $client = new REST_CLIENT(); $client->setMethod(REST_CLIENT::METHOD_GET); $headers = array("CURLOPT_USERAGENT" => "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5", "CURLOPT_HTTPHEADER" => array("Content-Type: application/x-www-form-urlencoded", "Accept: */*"), "CURLOPT_POST" => TRUE, "CURLOPT_FOLLOWLOCATION" => TRUE, "CURLOPT_RETURNTRANSFER" => TRUE, "CURLOPT_AUTOREFERER" => true, "CURLOPT_SSL_VERIFYPEER" => false, "CURLOPT_MAXREDIRS" => 0); foreach ($headers as $k => $v) { $client->addHeader($k, $v); } $url = "http://wwwa.way2sms.com/jsp/logout.jsp"; $result = $client->request($url, REST_CLIENT::CONTENT_PLAIN); print_r($result);