Created
January 21, 2020 23:09
-
-
Save yuhgto/17097c7046772b71d1ac788c21898f5c to your computer and use it in GitHub Desktop.
monday.com Powershell API Example
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
# This example will update a date, person and text column for all items on a board | |
# It will show you how to query the API (read data) and mutate column values for each of the returned items. | |
# set URL and headers for API calls | |
$url = "https://api.monday.com/v2/" | |
$hdr = @{} | |
$hdr.Add("Authorization" , "YOUR_API_KEY_HERE") | |
$hdr.Add("Content-Type","application/json") | |
# set board ID | |
$bid = 433902141 | |
# query to get items on board 298028165 | |
$query = 'query($boardId: Int!){boards(ids:[$boardId]) { items { id }, columns {title id} } }' | |
$vars = @{'boardId'= $bid} | |
# create request object with "query" and "vars" and serialize into JSON | |
$req = @{query = $query; variables = $vars} | |
$bodytxt = $req | ConvertTo-Json | |
$response = Invoke-WebRequest -Uri $url -Headers $hdr -Method Post -body $bodytxt | |
# declare data structures to store column IDs and types | |
$responseData = ($response.content | ConvertFrom-Json) | |
$itemList = $responseData.data.boards.items.id # list of items on board | |
# loop through items on board | |
for ($i=0; $i -lt $itemList.Length; $i++) { | |
# column IDs = "date4", "people", "text" | |
# declare item ID and column values hash table | |
$currentItem = $itemList[$i] | |
# create hash table for date value | |
# (see monday docs for structure of other column types) | |
$date = @{"date" = "2019-12-06"} | |
# create hash table for people column, based on column structure in docs | |
$personList = @() | |
$personList += @{"id" = 4012689; "kind" = "person"} | |
$people = @{"personsAndTeams" = $personList} | |
# create hash table for text column | |
$text = "ERP 12345" | |
# construct colValues hash table | |
$colValues = @{"date4" = $date; "text" = $text; "people" = $people} | |
# $colValues[$currentId] = $currentDate | |
$colValuesJson = ($colValues | ConvertTo-Json -Depth 4) | |
$query = 'mutation($board:Int!, $item:Int!, $vals: JSON!) {change_multiple_column_values(board_id:$board, item_id:$item, column_values:$vals) {id} }' | |
$vars = @{'board' = $bid; 'item' = [int]$currentItem; 'vals' = $colValuesJson} | |
$vars.vals | |
# create request from "query" and "vars" and make API call | |
$req = @{query = $query; variables = $vars} | |
$bodytxt = $req | ConvertTo-Json | |
$response = Invoke-WebRequest -Uri $url -Headers $hdr -Method Post -body $bodytxt | |
Write-Host $response | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like Monday change their API, can you update the code?