Skip to content

Instantly share code, notes, and snippets.

@dwaldmannDE
Last active December 10, 2017 13:14
Show Gist options
  • Save dwaldmannDE/b32464a8286031ab02f935fe8c05119f to your computer and use it in GitHub Desktop.
Save dwaldmannDE/b32464a8286031ab02f935fe8c05119f to your computer and use it in GitHub Desktop.
Using the Podio API with PowerShell (Authentification, Getting Items from an app). We are pretending that the podio app, that we want to access, stores a list of people and we want to retrieve the first- and last names
function Get-PodioAPIAuthorization() {
$PostParams = @{grant_type = "app"; app_id = ""; app_token = ""; client_id = ""; redirect_uri = ""; client_secret = ""}
#Params for the Authentification have to be hardcoded
$Result = Invoke-RestMethod -Uri https://podio.com/oauth/token -Method POST -Body $postParams
return $Result.access_token
}
function Get-PodioApiAppItems($AccessToken) {
#The Access token will be set in the header of the post request
$HeaderParams = @{Authorization = "Bearer " + $AccessToken}
$PostParams = @{limit = 500} | ConvertTo-Json
#This API needs the postparams as JSON Object"
$Result = Invoke-RestMethod -Uri https://api.podio.com/item/app/xxxxxxxx/filter/ -Method POST -Headers $HeaderParams -Body $postParams -ContentType "application/json"
$Result = $Result.items
#The actual app items are stored in $result.items. Instead of working with Select-Object -ExpandProperty items, this allows for debugging.
$AppItems = New-Object System.Collections.Generic.List[System.Object]
foreach ($item in $Result) {
#Process every item
#Parse Attributes and store them in temporary variables
$id = $item.app_item_id_formatted
$FirstName = $item.fields | Where-Object {$_.label -like "FirstName"} | Select-Object -ExpandProperty Values | Select-Object -ExpandProperty Value
$LastName = $item.fields | Where-Object {$_.label -like "LastName"} | Select-Object -ExpandProperty Values | Select-Object -ExpandProperty Value
# Build a custom object and store it in the AppItems List.
$AppItems.Add([PSCustomObject]@{PSTypeName = "Item"; ID = $id; FirstName = $FirstName; LastName = $LastName})
}
return $AppItems
}
Get-PodioApiAppItems(Get-PodioAPIAuthorization)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment