Skip to main content

Php

Getting started with PHP

To use the API with PHP use the following example

Using cURL

    <?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://apiv1.pataa.com/get-pataa',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{"api_key":"777XXXXXXXXXXXXXXXXXXXAWVwNpSM=","pc":"HOME006"}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Using HTTP_Request2

    <?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://apiv1.pataa.com/get-pataa');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Content-Type' => 'application/json'
));
$request->setBody('{"api_key":"777XXXXXXXXXXXXXXXXXXXAWVwNpSM=","pc":"HOME006"}');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}