Created
November 25, 2023 06:32
-
-
Save nathanmcnulty/44552e0f39df5b855c0dacd54261e533 to your computer and use it in GitHub Desktop.
AirThings API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get Access Token | |
$auth = @{ | |
Method = "POST" | |
Uri = "https://accounts-api.airthings.com/v1/token" | |
Body = [Ordered] @{ | |
"grant_type" = "client_credentials" | |
"client_id" = "49e83d9d-994b-4e8a-962d-a92cc9dfb874" | |
"client_secret" = "58c5318a-afc0-4d0a-b517-42e650c2289e" | |
"scope" = "read:device:current_values" | |
} | |
} | |
$token = Invoke-RestMethod @auth | |
# Device list | |
# https://developer.airthings.com/consumer-api-docs#tag/Devices/paths/~1v1~1devices/get | |
$list = @{ | |
UseBasicParsing = $true | |
Uri = "https://ext-api.airthings.com/v1/devices" | |
Method = "GET" | |
Headers = @{ | |
"Authorization" = "$($token.token_type) $($token.access_token)" | |
} | |
ContentType = "application/json" | |
} | |
$deviceList = ((Invoke-WebRequest @list).Content | ConvertFrom-Json).devices | |
# Device samples latest-values | |
# https://developer.airthings.com/consumer-api-docs#tag/Devices/paths/~1v1~1devices~1%7BserialNumber%7D~1latest-samples/get | |
$deviceList.Id | ForEach-Object { | |
$samples = @{ | |
UseBasicParsing = $true | |
Uri = "https://ext-api.airthings.com/v1/devices/$_/latest-samples" | |
Method = "GET" | |
Headers = @{ | |
"Authorization" = "$($token.token_type) $($token.access_token)" | |
} | |
ContentType = "application/json" | |
} | |
[array]$deviceSamples += ((Invoke-WebRequest @samples).Content | ConvertFrom-Json) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment