Hello! I'm making cURL request to neteller API and it returns 401 not authorized. My IP is whitelisted in neteller test account.
I have the following code:

        $url = 'https://test.api.neteller.com/v1/oauth2/token;
        $clientId = NETELLER_CLIENT_ID;
        $clientSecret = NETELLER_CLIENT_SECRET;
        $grantType = 'grant_type=client_credentials';
        $curl = curl_init($url); 
        curl_setopt($curl, CURLOPT_POST, true); 
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_USERPWD,  $clientId.":".$clientSecret);
        curl_setopt($curl, CURLOPT_HEADER, false); 
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($curl, CURLOPT_POSTFIELDS, $grantType); 
        $response = curl_exec($curl);
        if (curl_error($curl)) {
            throw new \Exception('System error. Can not get neteller token');
        $jsonResponse = json_decode($response, true); // Convert the result from JSON format to a PHP array
        return $jsonResponse;

But when I run cURL request in command line in the following way, it returns access token:

curl -XPOST -H "Cache-Control:no-cache"   -H "Content-Type:application/json"   --user NETELLER_CLIENT_ID:NETELLER_CLIENT_SECRET   'https://test.api.neteller.com/v1/oauth2/token?grant_type=client_credentials'

Where I am wrong in my PHP code, as command line request returns access token but using php code returns 'invalid client'? Thansk!

Recommended Answers

Hi, have you tried to set the headers like in command line?

Jump to Post

All 2 Replies

Hi, have you tried to set the headers like in command line?

I have tried this:

 $headers = array(
        'Authorization: Basic '. $clientId.':'.$clientSecret,

 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

but still the same result?
How should be cURL request in PHP to be the same as the cURL request from command line? I have tried many ways.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.