Connect to PSB API with Powershell
I just got access to an API key and would like to pull some data from the PSB portal and compare with AD. Sadly I cannot figure out how to connect via Powershell.
Found this: https://community.f-secure.com/en/discussion/91901/conncet-to-api-via-powershell
where it seemed to be solved but the solutions isn't shown in the posts.
Can anyone point me in the right direction?
/Danny
Best Answer
-
I use this method to obtain and save the token as a variable and then pass it to the authentication header for all subsequent request.
$uri = "<API URL>/authentication/login"
$auth = @{
'X-API-Key' = "<api key>"
}
$body = @{
'username' = '<username>'
'password' = '<password>'
}
$token = (invoke-restmethod -Uri $tokenuri -Method Post -Headers $auth -Body $body).token
$header = @{
'X-API-Key' = "<api key>"
'Authorization' = "Bearer $token"
}
10
Answers
-
Hi @DannyMalvang,
did you get the problem sorted out? If not you can drop the calls you are trying to me in private message and I can check what is going wrong.
Petri
1 -
h41ryb4wb46
I got it working with your help, but mostly I was using a - instead of a _ in the username. DOH! It helps if the credentials is correct
Heres what I did:
$url = "<API URL>"
$apiKey = 'XXXXXXXXXXX'
$auth = @{
'X-API-Key' = $apiKey
}
$body = @{
'username' = "asdsa@dsads.com"
'password' = "123456789"
}
$token = (invoke-restmethod -Uri "$url/authentication/login" -Method Post -Headers $auth -Body $body).token
Now I can use wget to get all computers:
wget -Uri "$url/partners/1234/reports/computers" -Method Get -Headers @{ 'x-api-key' = $apiKey ; Authorization = "Bearer $Token"}
Now I only need to figure out how to reformat the data to something usefull
0
Categories
- All Categories
- 4.7K WithSecure Community
- 3.6K Products
- 1 Get Support