No response from GET Products php

No response from GET Products php

I have no response from the server. Eh opted for several ways to make the request following the documentation of the api using PHP, I need help in which I am failing please.
I attach the result that I should get from the request, this result I obtained using Postman.


function getProducts(){ $ch = curl_init();

$username = ‘***’;
$password = ‘***’;
$url = ‘https://api.ordoro.com/product/’;

// $params = array(‘status’=>‘active’);
// $url .= ‘?’. http_build_query($params);

$credentials = $username.’:’.$password;
$headers = array('Authorization: Basic '. base64_encode($credentials));

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_USERPWD, $credentials);
curl_setopt($ch,CURLOPT_HTTPHEADER,array(‘accept:application/json’));
curl_setopt($ch,CURLOPT_HEADER,TRUE);
curl_setopt($ch,CURLOPT_HEADER,$headers); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,‘GET’);

$response = curl_exec($ch);
print ’ Print Response: ';
print $response;
curl_close($ch);
}


Hi @nitramD,

If I put <?php at the top of the script, i am able to run your php code and receive a response as expected.

Does this help?

Thank you @sophie . But that is not the problem … and I corrected the publication. My code is in a function.
Maybe I need to import some library?

@nitramD

I am able to copy and paste your code and enter my ordoro credentials to get a response with no problems.

Are you able to get any request with php?

If i send a request like this:

$ch = curl_init();
$url = 'https://api.ordoro.com/product/';
curl_setopt($ch,CURLOPT_URL,$url);
$response = curl_exec($ch);
print $response;

i get {"error_message": "Unauthenticated", "param": null}.

Do you have any logging to share that might help us debug this with you? It seems like you have proper credentials based on the Postman results.

~sophie

@sophie
My credentials: Basic XXX

Using my credentials I get no response.
Using var_dump ($ response) prints me bool (false).
Only with postman get a response…

I feel like this is a php or network issue rather than an api issue.

Can you run a php that curls anything, like my previous example without any credentials?

If i use your code and credentials, I get a proper response back. Have you tried running from the command-line or interactive shell?

Here is my result of running php interactively.

php > $ch = curl_init();
php > $headers = array('Authorization: Basic <your basic auth here>');
php > curl_setopt($ch,CURLOPT_URL,$url);
php > curl_setopt($ch,CURLOPT_USERPWD, $credentials);
php > curl_setopt($ch,CURLOPT_HTTPHEADER,array('accept:application/json'));
php > curl_setopt($ch,CURLOPT_HEADER,TRUE);
php > curl_setopt($ch,CURLOPT_HEADER,$headers);
php > curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
php > curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'GET');
php > $response = curl_exec($ch);
php > var_dump($response);
string(149366) "HTTP/1.1 200 OK
cache-control: no-cache,max-age=0,must-revalidate
Content-Type: application/json
Date: Fri, 17 Mar 2017 16:44:37 GMT
pragma: no-cache
Server: gunicorn/19.3.0
X-API-REQUEST-ID: b1976415-e98e-4866-83a5-f1ca3d8c7d8e
X-Ordoro-API-Server: i-00a8f39fb3e4a3d2d 1.228.0
X-ORDORO-HANDLED-BY: ip-172-31-36-199
Content-Length: 148991
Connection: keep-alive

{"count": 314, "product": [... removed actual products for length and demonstration purposes ...], "limit": 10, "offset": 0}"

Not work in octobercms …

$url = ‘https://api.ordoro.com/product/’;
$credentials=’:’;
$ch = curl_init();
$headers = array('Authorization: Basic ');
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_USERPWD, $credentials);
curl_setopt($ch,CURLOPT_HTTPHEADER,array(‘accept:application/json’));
curl_setopt($ch,CURLOPT_HEADER,TRUE);
curl_setopt($ch,CURLOPT_HEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,‘GET’);
$response = curl_exec($ch);
var_dump($response);

Hi @nitramD,

From your post it seems like you are having an october cms issue, and should contact them about configuring your setup for using php requests.

I have also removed your credentials from the previous public posts as a security measure.

Hope you can get the php working through that platform!

Sophie