Powershell Examples: Using CURL like Formatting

I have been doing quite a bit of automation. And have just hammered out some code today. this is some basic code to do simple queries in Powershell. I will obfuscate the API token to protect the not so innocent.

[Net.ServicePointManager]::SecurityProtocol = “tls12, tls11, tls”
$url = “https://api.monday.com/v2/
$hdr = @{}
$hdr.Add(“Authorization” , “BIG LONG Token”)
$hdr.Add(“Content-Type”,“application/json”)

$bodytxt=‘{“query”:“{boards(limit:1){id name}}”}’

$response = Invoke-WebRequest -Uri $url -Headers $hdr -Method Post -body $bodytxt
$resBoards = ($response.content | ConvertFrom-Json)

$bodytxt = ‘{“query”:"{boards(ids:’ + $($resSheet.data.boards[0].id) + ‘),{columns{archived id title}}}"}’
Write-Host $bodytxt
$response = Invoke-WebRequest -Uri $url -Headers $hdr -Method Post -body $bodytxt
$resColumns = ($response.content | ConvertFrom-Json)

$bodytxt = ‘{“query”:"{boards(ids:’ + $($resSheet.data.boards[0].id) + ‘),{items {creator{id} creator_id group{ id } id name state updates {id}}}}"}’
Write-Host $bodytxt
$response = Invoke-WebRequest -Uri $url -Headers $hdr -Method Post -body $bodytxt
$resitems = ($response.content | ConvertFrom-Json)

2 Likes

Thanks for sharing @stevemcmanus!