Automatically request IT Glue Quick Notes from your team
We’ve been using the IT Glue API to automate our customers’ documentation. It’s worked well for much of the structured data, however we were looking for a way to automate the non-structured stuff. The things that are handy to know that don’t fit in a standard configuration or flexible asset – or if they do, they haven’t been entered due to lack of time or inclination.
This information could be notes about contacts, relationships to be aware of, common gotchas, non-standard setups and general customer history. Adding this information into the quick notes feature of an IT Glue organisation means that it’s visible to our team whenever they view the customer in IT Glue. We decided to automate the collection of these notes by requesting them from the team each day.
Every weekday, our techs are sent a request to provide quick notes for a randomly selected customer. They can add notes directly into the approval request, or reassign it to someone who knows the customer better. The notes that they add to the approval are added to the quick notes for that customer. These notes can also be entered via the Microsoft Flow mobile apps for iOS and Android.
This solution uses Azure Functions, Microsoft Flow and the IT Glue API.
Prerequisites
- An IT Glue admin account with access to the API
- A Microsoft Azure Subscription with the ability to create resources
- An Azure Function App – Create one here. This solution can run on a free/cheap consumption plan.
- Office 365 with Microsoft Flow (included in nearly every plan)
The solution is made up of three components:
A Timer Triggered PowerShell Azure Function
This script connects to IT Glue, randomly selects organisations and triggers a Microsoft Flow for each of your specified technicians. You enter the email addresses of the technicians that will be receiving the approvals into this script.
A Microsoft Flow with an Approval step
This flow assigns an approval task to each member of your team requesting info about the specific organisation. These requests can be approved, rejected or reassigned to someone else. If the request is approved, the notes from the approval comments are sent via a HTTP call to…
A HTTP Triggered PowerShell Azure Function
This function receives the notes from the tech and the company’s IT Glue ID and adds them to the company in IT Glue. If quick notes have been added to the company already, the new notes are appended to existing ones.
How to automatically request quick notes for IT Glue from your team
Create a timer triggered PowerShell Azure Function
- Once you’ve created an Azure Function App, create a new Azure Function by clicking the + icon on the left menu next to your function app name.
- Enable Experimental language support
- If this is your first function and you’re on the quick start experience, click create your own custom function.
- Choose PowerShell under Timer Trigger and give it a name like TT-UpdateITGlueQuickNotes
- Define a schedule using a cron trigger in UTC time. For example, this script will execute every week day morning at 8:30 AM Australian Eastern Standard Time:
0 30 22 * * 0-4
- Click Create, then paste in the first of the two scripts at the bottom of this page.
- Retrieve or create an API Key in IT Glue under Account, API Keys, Custom API Keys
- Add the API key into the $key variable of the script
- Some tenants hosted on EU infrastructure need to modify the IT Glue API base uri as follows:
$baseURI = "https://api.eu.itglue.com"
- Enter your Office 365 email address into the value for the $users variable. You can test the script with one address until you are happy with it.
Create a Microsoft Flow to send the requests for quick notes
- Sign into Microsoft Flow at https://flow.microsoft.com
- Click My Flows, New, Create from Blank
- Click Search hundreds of connectors and triggers, then give your flow a name on the top left. Eg – Request Quick Notes
- In the search box on the page, search for HTTP Request and choose ‘When a HTTP Request is received‘
- On the When a ‘HTTP Request is received’ trigger, click the button to use sample payload to generate schema, then copy and paste this example:
{ "name": "name", "id": "id", "approver":"approver" }
- Add in an Approval step after the Request Trigger.
- In the Approval step fields, enter the below information. You can copy and paste the provided values, or build them yourself using the outputs from the HTTP Trigger Request body. If you’re copying and pasting the values here, don’t worry if they don’t become colourful placeholders right away, they’ll display as plain text until you save and reopen the flow.
- Approval type: choose Anyone from the assigned list
- Title: What do you know about name? Replace name with the dynamic name value from the trigger action, or copy and paste the following:
What do you know about @{triggerBody()?['name']}?
- Assigned to: Use the ‘approver’ output from the trigger action here. If you don’t see any values, click see more.
- Requestor: Enter your own email address, or the email of the user you’d like to appear as the requestor.
- Details: These notes appear in the body of the approval request. You can copy and paste this one:
Hi there, We're improving our documentation by adding helpful quick notes to our customers who don't have any. Today, you've been randomly assigned @{triggerBody()?['name']}. Feel free to approve this request and add any helpful info into the approval comments. Your comments will be added to the organisation in IT Glue. If you think someone else knows this customer better, you can reassign this approval to them. Thanks! YourCompany
- Item link: This is a link that’s included in the approval request. Modify this one to represent your IT Glue URL:
https://yoursubdomain.itglue.com/@{triggerBody()?['id']}
- Item link description: Ours says FYI, here’s the customer in IT Glue
- Add a condition step following the approval step and set the condition to response is equal to Approve. Where response is the output of the Approval step.
- In the Yes branch, add in a HTTP action, change the Method to POST, add a header called Content-Type with a value of application/json and leave the URI blank for now.
- In the Body field, construct a JSON Object like the one in the above screenshot or copy and paste the following:
{ "id": "@{triggerBody()?['id']}", "notes": "@{body('Start_an_approval')?['comments']} - @{body('Start_an_approval')?['responder']?['displayName']}" }
Create a HTTP Triggered PowerShell Azure Function
- To retrieve a URI for this HTTP action in Microsoft Flow, we’ll need to setup our HTTP Triggered Azure Function. Open a new tab and open your Azure Function app again.
- Create a new PowerShell Azure Function with a HTTP Trigger. Remember to click Experimental Language Support to display the PowerShell options
- Give it a name, eg HT-UpdateITGQuickNotes
- Copy and paste the second script at the bottom of this page into the function.
- Enter your IT Glue API key into the $key value and click Save.
- Click Get function URL, then copy it
- Paste the function URL into the URI field of the HTTP Action in your Microsoft Flow.
- Save your Microsoft Flow. It should look like this:
- Once the flow is saved, copy the HTTP POST URL from the When a HTTP request is received trigger.
- Paste this copied HTTP POST URL into the $flowuri variable in your first Timer Triggered Azure Function (the first script)
- Click Save and Run to test the timer triggered Azure Function
- You should receive a Microsoft Flow approval request with the name of a customer in the title. Click Approve, enter your notes into the comment field and submit them. The notes should then be added to the company in IT Glue.
- Once you are happy with the solution, enter the Office 365 email addresses for the rest of your support team, each one in quotes, separated by a comma. eg:
[array]$users = "[email protected]", "[email protected]", "[email protected]"
- It’s recommended that you replace your IT Glue API keys with Azure Function Application Settings/Environment variables, so they are not stored in plain text in your script. See the bottom of this article for instructions on how to do this.
PowerShell Script for Timer Triggered Azure Function for IT Glue Quick Notes
Write-Output "PowerShell Timer trigger function executed at:$(get-date)"; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # Only one email is specified for the below variable for testing purposes. # When you are happy with the script, you can add more addresses, each in double quotes separated by commas. # eg: [array]$users = "[email protected]", "[email protected]", "[email protected]" [array]$users = "[email protected]" # IT Glue Settings $ITGkey = "ENTERITGLUEAPIKEYHERE" $ITGbaseURI = "https://api.itglue.com" $ITGheaders = @{"x-api-key" = $ITGkey} $flowURI = "Enter Flow HTTPPOSTURI Value Here" function Get-GCITSITGItem($Resource) { $array = @() $body = Invoke-RestMethod -Method get -Uri "$ITGbaseUri/$Resource" -Headers $ITGheaders -ContentType application/vnd.api+json $array += $body.data Write-Host "Retrieved $($array.Count) items" if ($body.links.next) { do { $body = Invoke-RestMethod -Method get -Uri $body.links.next -Headers $ITGheaders -ContentType application/vnd.api+json $array += $body.data Write-Host "Retrieved $($array.Count) items" } while ($body.links.next) } return $array } $organizations = Get-GCITSITGItem -Resource organizations $noQuickNotes = $organizations | Where-Object {!$_.attributes.'quick-notes'} [array]$randomNoQuickNotes = Get-Random -InputObject $noQuickNotes -Count $users.Count for ($i = 0; $i -lt $users.Count; $i++) { #Start Microsoft Flow requesting info on these Orgs $body = @{ name = $randomNoQuickNotes[$i].attributes.name id = $randomNoQuickNotes[$i].id approver = $users[$i] } | ConvertTo-Json Invoke-RestMethod -Method POST -Uri $flowURI -Body $body -ContentType application/json }
PowerShell Script for HTTP Triggered Azure Function for IT Glue Quick Notes
# POST method: $req $requestBody = Get-Content $req -Raw | ConvertFrom-Json $id = $requestBody.id $notes = $requestBody.notes # IT Glue Settings $ITGkey = "ENTERITGLUEAPIKEYHERE" $ITGbaseURI = "https://api.itglue.com" $ITGheaders = @{"x-api-key" = $ITGkey} function Get-GCITSITGItem($Resource) { $array = @() $body = Invoke-RestMethod -Method get -Uri "$ITGbaseUri/$Resource" -Headers $ITGheaders -ContentType application/vnd.api+json $array += $body.data Write-Host "Retrieved $($array.Count) items" if ($body.links.next) { do { $body = Invoke-RestMethod -Method get -Uri $body.links.next -Headers $ITGheaders -ContentType application/vnd.api+json $array += $body.data Write-Host "Retrieved $($array.Count) items" } while ($body.links.next) } return $array } function Update-GCITSITGItem ($Resource, $existingItem, $Body) { $updatedItem = Invoke-RestMethod -Method Patch -Uri "$ITGbaseUri/$Resource/$($existingItem.id)" -Headers $ITGheaders -ContentType application/vnd.api+json -Body $Body return $updatedItem } function New-GCITSITGOrgQuickNoteAsset($QuickNotes, $ExistingItem) { if ($ExistingItem.attributes.'quick-notes') { $QuickNotes = "$($ExistingItem.attributes.'quick-notes')<br><br>$QuickNotes" } $body = @{ data = @{ type = "organizations" attributes = @{ 'quick-notes' = $QuickNotes } } } $body = $body | ConvertTo-Json -Depth 10 return $body } $organization = Get-GCITSITGItem -Resource "organizations/$id" $body = New-GCITSITGOrgQuickNoteAsset -QuickNotes $notes -ExistingItem $organization Update-GCITSITGItem -Resource organizations -existingItem $organization -Body $body Out-File -Encoding Ascii -FilePath $res -inputObject "Submitted"
Leave a Reply
Want to join the discussion?Feel free to contribute!