Conncet to API via powershell

Invoke-WebRequest -Uri -Method Post -Headers @{ 'x-api-key' = $apiKey ; "username" = "XXXXXXXXXX" ; "password"="XXXXXXXXXXXX" }


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




i ty this way to

$apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
$Credential = Get-Credential
Invoke-WebRequest -Uri -Method Post -Headers @{ 'x-api-key' = $apiKey } -Credential $Credential




Best Answer

  • PetriKuikkaPetriKuikka Posts: 205 F-Secure Employee
    Accepted Answer



    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' ""


    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 \


    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.




  • 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





    $apiKey = 'XXXXXXXXXXXXXX'
    Write-Output (Invoke-WebRequest -Uri "" -Method Get -Headers @{ 'x-api-key' = $apiKey ; Authorization = "Bearer $Token" }




  • 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" ""


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



  • 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.