Postman to PHP -cURL

Hello,

I’m a real begginer and working on a project to connect our internal system to an API.

I need first to authenticate and then, once I received the token, I can send request to the app.

When I put all of the information in postman and I click send, it does work well and I received the following response:

{

        "access_token": "bla blan bla bla bla",

        "token_type": "Bearer",

        "expires_in": 3596,

        "scope": "https://api.apiprovider.ca/inquiry/version/app"

    }

Then, I think everything is alright and I click “code” and “php-curl” to retreive de php code for my page. This operation give me the following code:

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.blabla.ca/v2/oauth/token',
  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 => 'grant_type=client_credentials&scope=https:blablabla.ca',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/x-www-form-urlencoded',
    'Authorization: Basic blablablablablabal'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
?>

The problem is that when I access the php page containing this code, nothing happens and I have a blank page.

Anybody can help me ? I specify that curl is enabled on my server and also simplexml.

Thanks in advance !

1 Like

I am having the same issue. Any ideas?

Hey @jkozlowsky :wave:

Welcome to the Postman Community! :postman:

As you’re responding to a topic from over 3 years ago, it would be best for you to fully explain what’s happening for you, in your context.

A lot has changed in that time and you’re particular issue might be something different.