Rest API failed with cURL

Hi there,
I am trying to call rest API with php without luck!
I am able to call www.xxx.erpnext.com demo account with rest API throw php cURL but not able to call www.xx.xx.xx.x:83 my server !
I try to call them both with postman and it successful but with php cURL for my server it is failed!

I use this code :

<?php

$ch = curl_init( "https://b8ak.erpnext.com/api/method/login" );
# Setup request to send json via POST.

curl_setopt( $ch, CURLOPT_POSTFIELDS,  array(
'usr' => 'mhbuxx@gmail.com',
'pwd' => 'xxxxxxx' )  );

curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

$result = curl_exec($ch);
curl_close($ch);
# Print response.
echo "<pre>$result</pre>";

Is your port 83? You need to specify that in your request in the code.

thanks for you reply but it is the same, i add this to code :

curl_setopt( $ch, CURLOPT_PORT, '83' );

not working!

Are you calling your ip with https protocol as well?

What’s your curl error for the failed request?

@Felipe_Orellana no, I dont get any error but the request take long time to respond and return 0!

you can try my code hear :

<?php

$ch = curl_init( “http://52.30.74.246:83/api/method/login” );

curl_setopt( $ch, CURLOPT_POSTFIELDS, array(
‘usr’ => ‘Administrator’,
‘pwd’ => ‘12345678’ ) );

curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_PORT, ‘83’ );

$result = curl_exec($ch);
curl_close($ch);

echo $result;

So, I just tried your code and it seems to work for me:

{“home_page”:“/desk”,“message”:“Logged In”,“full_name”:“Administrator”}

My guess is that either your server or isp where you are doing the call from is blocking outgoing port 83 connections?

Not really sure

1 Like

but i tried with postman and it is working fine with 83
It is not working only with cURL!

Are you using postman on the same machine your are running curl from?

Include CURLOPT_USERAGENT