NIFDO.COM
NIFDO.COM

Reputation: 53

Get json from API using PHP

I have this API

mywebsite.com/v1/api/Endorsements/xxxxxx/User/5003C2D5-6FD6-49BA-A309-EBB81A89FB60/RequestType/All/PageNo/1/PageSize/6/Object/null/Category/null/Search/null/Latitude/null/Longitude/null/Radius/null/StartDate/null/EndDate/null?Auth-Token=A682CCB8-C5D6-47C3-BDF5-8EEC00A164ABapi.salamplanet.com/v1/api/Endorsements/81158/User/5003C2D5-6FD6-49BA-A309-EBB81A89FB60/RequestType/All/PageNo/1/PageSize/6/Object/null/Category/null/Search/null/Latitude/null/Longitude/null/Radius/null/StartDate/null/EndDate/null

and Auth-Token = "XXXXXXXXXX"

I want to get JSON from this API using PHP.

Note: I am new in PHP please help.

Upvotes: 2

Views: 2605

Answers (2)

Saurabh Mandeel
Saurabh Mandeel

Reputation: 101

This can also be done as..

$url='http://your_url';
$result = file_get_contents($url);
$resultData = json_decode($result);
echo "<pre>";
print_r($resultData);

Upvotes: 4

Rohit Dhiman
Rohit Dhiman

Reputation: 2741

Use json_decode to convert json data to array.

$url='http://your_url';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'rohit');
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
$resultArray = json_decode($result);
echo "<pre>";
print_r($resultArray);

Upvotes: 4

Related Questions