Connect to API via PHP Curl
My request looks like this.
$config = array(
'url' => 'https://eu1.psb.fsapi.com/mp/v1/authentication/login',
'key' => 'myKey'
);
$data = array(
'username' => 'myUsername',
'password' => 'myPassword'
);
$headers = array(
'Content-Type: application/x-www-form-urlencoded',
'X-API-Key: '.$config['key']
);
/*list of curl options*/
$options = array(
CURLOPT_URL => $config['url'],
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => $headers,
);
/*curl handler*/
$ch = curl_init();
/*set options*/
curl_setopt_array($ch, $options);
/*excute*/
$result = curl_exec($ch);
For some reason i get this:
{"errors":[{"code":3030,"message":"login.error.badCredentials","lockDuration":1800000,"maxFailedLogins":5}]}
Comments
-
Hi,
Can you share the complete response including transactionId?
Regards,
Robin
0 -
Hi,
This is all I get in my browser, when I run my php code. I'm using localhost if that helps. After the execution i close the curl handler and echo the result.
How can i check the transaction id?0 -
Hi,
Here is what we get as response including headers:
HTTP/1.1 401 Unauthorized Access-Control-Allow-Headers: Content-Type, Authorization, Content-Length, X-Requested-With, Current-Password, X-Api-Key, If-None-Match
Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location
Access-Control-Max-Age: 600 cache-control: no-cache,no-store
Content-Type: application/json; charset=utf-8
Date: Tue, 19 Sep 2017 11:53:49 GMT
ETag: W/"6c-0Anr2S6GsVfmq5bMK1OfHw"
X-TX: c40aba9df13048cc8bf785a4cb281f2a
Content-Length: 108
Connection: keep-alive
{"errors":[{"code":3030,"message":"login.error.badCredentials","lockDuration":1800000,"maxFailedLogins":5}]}
That's all we get as response!
BR,
Dobri
0 -
Could you try with this ?
#!/usr/bin/env php <?php $curl = curl_init(); $username = urlencode(‘user-name’); $password = urlencode(‘password’); curl_setopt_array($curl, array( CURLOPT_URL => "https://eu1.psb.fsapi.com/mp/v1/authentication/login", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "username=$username&password=$password", CURLOPT_HTTPHEADER => array( "content-type: application/x-www-form-urlencoded", "x-api-key: your-api-key”, ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
6 -
Thank you! Your code resolved the problem1
Categories
- All Categories
- 3.5K WithSecure Community
- 3.5K Products
- Get Support