Get JSON data from API

Hi all,

I am trying to get json data from an API-set, and the code I got from the API-provider is like this:

// This sample uses the Apache HTTP client from HTTP Components (

require_once 'HTTP/Request2.php';
$request = new Http_Request2('');
$url = $request->getUrl();
$headers = array(
    // Request headers
    'Authorization' => 'Token YOUR_TOKEN',
                'Accept' => 'application/json',
$parameters = array(
    // Request parameters
// Request body
    $response = $request->send();
    echo $response->getBody();
catch (HttpException $ex)
    echo $ex;

I do not get any data in return.

Can You please guide me?

Best regards and thank You.

It appears you are missing (to begin with) two things:

1.You need to fill in your token which the provider will assign when you subscribe to their service
2. I am certain is not a valid link

Hi Parkin T and thanks for the reply,

I have the Token and the correct Url. I have left them out in the example.

When I use the correct Token and Url I still do not get any data i return.
When I use the Token and Url in a Rest Client I get json data.

Best regards,

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.