Skip to main content
Solved

API authentication

  • November 3, 2022
  • 3 replies
  • 245 views

Forum|alt.badge.img

 

Hi Everyone

I’m new to the API.  guess im doing something wrong related to authentication. I can query through postman without any issues using my key but no luck with the below code :

 

Here is what Im tryin to run through PS but I always get an “(401) Unauthorized.” error message


$headers=@{
Authorization="MyAccessKeyStringhere";
Content='application/json'
}


$uri = "https://console.automox.com/api/reports/prepatch"


$result = Invoke-restmethod -Uri $uri -Headers $headers -method get

$result  | select -expandproperty profile |select name

 

 

Thanks a lot for any help. 

Diego

 

Best answer by ElmerP-Automox

Hello Diego,

You will need to specify your orgID in the URI. For example:

$orgid='<your_org_id>'

$apiKey = '<your_api_key>'

$headers=@{

Authorization = "Bearer $apiKey"

Content='application/json'

}

$url = "https://console.automox.com/api/reports/prepatch?o=$orgid"

$response = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content | ConvertFrom-Json

Write-Output $response

Try that out.

Kind regards,

View original
How helpful was this post to you?

3 replies

  • Automox Employee
  • 19 replies
  • Answer
  • November 4, 2022

Hello Diego,

You will need to specify your orgID in the URI. For example:

$orgid='<your_org_id>'

$apiKey = '<your_api_key>'

$headers=@{

Authorization = "Bearer $apiKey"

Content='application/json'

}

$url = "https://console.automox.com/api/reports/prepatch?o=$orgid"

$response = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content | ConvertFrom-Json

Write-Output $response

Try that out.

Kind regards,


And adding to ElmerP’s code here, I was able to break it down to the device info, which might be what you were looking for with the Name property.
 

$orgid='<your_org_id>'

$apiKey = '<your_api_key'

$headers=@{

Authorization = "Bearer $apiKey"

Content='application/json'

}

$url = "https://console.automox.com/api/reports/prepatch?o=$orgid"



$response = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content | ConvertFrom-Json

Write-Output $response.prepatch.devices

 


Forum|alt.badge.img
  • Author
  • Rookie
  • 3 replies
  • November 4, 2022

 

Thank you so much to both !!!

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings