Conncet to API via powershell

$apiKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
Invoke-WebRequest -Uri https://eu1.psb.fsapi.com/mp/v1/authentication/login -Method Post -Headers @{ 'x-api-key' = $apiKey ; "username" = "XXXXXXXXXX" ; "password"="XXXXXXXXXXXX" }

 

ITHe Apikey work fine but i get this erro no matter what 

 

{"errors":[{"code":3030,"message":"login.error.badCredentials","lockDuration":1800000,"maxFailedLogins":5}]}

 

i ty this way to

$apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
$Credential = Get-Credential
Invoke-WebRequest -Uri https://eu1.psb.fsapi.com/mp/v1/authentication/login -Method Post -Headers @{ 'x-api-key' = $apiKey } -Credential $Credential

 

 

 

Best Answer

  • PetriKuikkaPetriKuikka Posts: 205 F-Secure Employee
    Accepted Answer

    Hi,

     

    I haven't used powershell, but I noticed that your first example is missing one header

    "Content-Type: application/x-www-form-urlencoded"

     

    And also the username + password should be part of body data. 

     

    This is how curl call looks like:

    curl -X POST -H "x-api-key: $apiKey" -H "Content-Type: application/x-www-form-urlencoded" -d 'username=XXXXXXXXXX&password=xxxxxxxxxxxxx' "https://eu1.psb.fsapi.com/mp/v1/authentication/login"

     

    Here is how it looks for wget:

    wget --quiet \
      --method POST \
      --header 'x-api-key: $apiKey' \
      --header 'content-type: application/x-www-form-urlencoded' \
      --body-data 'username=XXXXXXXXXX&password=xxxxxxxxxxxxx' \
      --output-document \
      - https://eu1.psb.fsapi.com/mp/v1/authentication/login

     

    So I think that just moving the username and password to body part will fix your problem. Let me know if this helped you and if not, I'll dig deeper and try this out with powershell.

     

    Petri

Comments

  • This info help alot thx 

  • i get the token fine now but this it's wierd i ty to get companies or any other GET

     

     

    $Token = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

     

    $apiKey = 'XXXXXXXXXXXXXX'
    Write-Output (Invoke-WebRequest -Uri "https://eu1.psb.fsapi.com/mp/v1/partners/102/companies?page=1&perPage=2" -Method Get -Headers @{ 'x-api-key' = $apiKey ; Authorization = "Bearer $Token" }

     

     

    {"errors":[{"code":3030,"message":"login.error.badCredentials"}]}

  • PetriKuikkaPetriKuikka Posts: 205 F-Secure Employee

    Hmm, odd, your call looks really right to me as following curl command works fine:

     

    curl -X GET -H "X-Api-Key: $api-key" -H "Authorization: Bearer $token" "https://eu1.psb.fsapi.com/mp/v1/partners/216/companies?page=1&perPage=max"

     

    Are you sure the 102, is the same partner ID, you login in?

     

    Petri

  • PetriKuikkaPetriKuikka Posts: 205 F-Secure Employee

    I quickly checked our logs and your calls are getting rejected either by following 2 reasons:

     

    "resource":"/mp/v1/partners/102/companies?page=1&perPage=2","message":"No authorization token was found","backendStatus":401

     

    So somehow the token is not in the message.

     

    "resource":"/mp/v1/partners/102/companies?page=1&perPage=2","message":"Format is Authorization: Bearer [token]","backendStatus":401

     

    Or somehow the format is not correct how you give the token to authorization.

This discussion has been closed.