Celerium.ITGlue
Buy me a coffee
Whether you use this project, have learned something from it, or just like it, please consider supporting it by buying me a coffee, so I can dedicate more time on open-source projects like this :)
About The Project
The Celerium.ITGlue PowerShell wrapper offers a way to read & (with safeguards) change the data of IT Glue’s documentation platform, such as organizations, configurations, contacts, locations, passwords, flexible assets, & documents. This module serves to abstract away the details of interacting with IT Glue’s API endpoints in such a way that is consistent with PowerShell nomenclature. This gives system administrators and PowerShell developers a convenient and familiar way of using IT Glue’s API to create documentation scripts, automation, and integrations.
- :book: Celerium.ITGlue project documentation can be found on Github Pages
- :book: ITGlue’s REST API documentation can be found in the ITGlue developer guide & the (unofficial) OpenAPI spec is published in the ITGlue-OpenAPI repository
A function is generated for every endpoint in the ITGlue OpenAPI spec (ITGlue-1.118.132.20261114.json) and every endpoint is tracked in the endpoints.csv file.
:warning: Any function that is not a read-only Get- function can change data. See Write functions.
In order to maintain PowerShell best practices, only approved verbs are used and PowerShell’s verb-noun nomenclature is respected. Each noun is prefixed with ITGlue in an attempt to prevent naming problems.
- GET ->
Get-ITGlue* - POST ->
New-ITGlue* - PATCH ->
Set-ITGlue*(&Publish-ITGlueDocument) - DELETE ->
Remove-ITGlue*
For example, one might access the /organizations endpoint by running the following PowerShell command:
Get-ITGlueOrganization
- Most functions cover more than one endpoint with parameter sets.
Get-ITGlueConfigurationlists the configurations of the account,-OrganizationId 12345lists the configurations of an organization,-Id 67890gets one configuration, &-OrganizationId 12345 -Id 67890gets one configuration of an organization - JSON:API query parameters are PowerShell parameters:
filter[organization_id]=-FilterOrganizationId,page[size]=-PageSize,sort=-Sort, &include=-Include(tab completion shows the allowed sort & include values) - By default only the
dataof a response is returned, such as the organizations of/organizations. Use-Rawto return the full JSON:API response, including themeta,links, &includedproperties - Paged endpoints have
-PageNumber&-PageSizeparameters and an-AllResultsswitch that requests every page for you (1000 items per page, the maximum, unless-PageSizeis used)
Write functions
The New-, Set-, Publish-, & Remove- functions change data in ITGlue. Use them with care on a production account:
- Every write function supports
-WhatIf, which shows what would be sent without sending anything - Every write function has a
ConfirmImpactofHigh, so PowerShell asks for confirmation before the request is sent unless-Confirm:$falseis used - A write request is never retried automatically
- The request body is defined with
-Data, the value of the JSON:APIdataproperty, such as@{ type = 'organizations'; attributes = @{ name = 'Celerium' } } - The unit tests, the live tests, & the examples never send a write request (the 1.x example scripts in
examples/Legacydo, they are marked & never run automatically)
# Shows the request that would be sent, nothing is sent
Set-ITGlueOrganization -Id 12345 -Data @{ type = 'organizations'; attributes = @{ name = 'Celerium' } } -WhatIf
Install
This module can be installed directly from the PowerShell Gallery with the following command:
Install-Module -Name Celerium.ITGlue
- :information_source: This module supports Windows PowerShell 5.1 and PowerShell 7+ on Windows, Linux, & macOS. Every change is tested on all of them by the CI workflow.
- :information_source: If PowerShellGet is unavailable, you can manually download the main branch and place the latest version of Celerium.ITGlue from the build folder into the (default)
C:\Program Files\WindowsPowerShell\Modulesfolder.
Celerium.ITGlue project documentation can be found on Github Pages
- A full list of functions can be retrieved by running
Get-Command -Module Celerium.ITGlue. - Help info and a list of parameters can be found by running
Get-Help <command name>, such as:
Get-Help Get-ITGlueConfiguration
Get-Help Get-ITGlueConfiguration -Full
Initial Setup
After installing this module, you will need to configure both the base URI & API access token that are used to talk with the ITGlue API.
- Run
Add-ITGlueBaseURI- By default, ITGlue’s
https://api.itglue.comuri is used (this is also the default when the module is imported) - Use
Add-ITGlueBaseURI -DataCenter EU(https://api.eu.itglue.com) or-DataCenter AU(https://api.au.itglue.com) for the other data centers - If you have your own API gateway or proxy, you can use
Add-ITGlueBaseURI -BaseURI https://myapi.gateway.example.org, onlyhttpsis supported
- By default, ITGlue’s
- Run
Add-ITGlueAPIKey- It will prompt you to enter your API key as a secure string, or use
Add-ITGlueAPIKey -ApiKey 'your-api-key' - Create API keys in ITGlue via Account > Settings > API Keys. Use a key without password access unless passwords are required
- The API key is sent in the
x-api-keyheader
- It will prompt you to enter your API key as a secure string, or use
- [optional] Run
Test-ITGlueAPIKey- Makes a single GET request to the
/regionsendpoint to validate the base uri & API key
- Makes a single GET request to the
- [optional] Run
Export-ITGlueModuleSettings- This will create a config file at
%UserProfile%\Celerium.ITGluethat holds the base uri & API key information. - Next time you run
Import-Module -Name Celerium.ITGlue, this configuration file will automatically be loaded. - :warning: Exporting module settings encrypts your API key in a format that can only be unencrypted by the user principal that encrypted the secret. It makes use of .NET DPAPI, which for Windows uses reversible encrypted tied to your user principal. This means that you cannot copy your configuration file to another computer or user account and expect it to work.
- :warning: However in Linux\Unix operating systems the API key is more obfuscated than encrypted so it is recommend to use environment variables or a more secure & cross-platform storage method.
- This will create a config file at
Environment variables (recommended for CI\CD, Linux, & macOS) are loaded when the module is imported and take precedence over the configuration file:
$env:ITGLUE_BASE_URI = 'https://api.itglue.com' # Optional
$env:ITGLUE_API_KEY = 'your-api-key'
Import-Module -Name Celerium.ITGlue
Usage
Calling an API endpoint is as simple as running its Get-ITGlue* function.
# Get the first 50 organizations (the default page size of the API)
Get-ITGlueOrganization
# Get every organization, 1000 at a time
Get-ITGlueOrganization -AllResults
# Filter, sort, & page
Get-ITGlueOrganization -FilterName 'Celerium' -Sort '-updated_at' -PageNumber 2 -PageSize 10
# The configurations of an organization & a single configuration with its passwords
Get-ITGlueConfiguration -OrganizationId 12345 -AllResults
Get-ITGlueConfiguration -Id 67890 -Include 'passwords'
# Get the meta data (such as the total count), links, & included items
(Get-ITGlueOrganization -PageSize 1 -Raw).meta.'total-count'
# Flexible assets need the flexible asset type
Get-ITGlueFlexibleAsset -FilterFlexibleAssetTypeId 123 -FilterOrganizationId 12345
- The full list of endpoints & their functions is tracked in the endpoints.csv file and on Github Pages.
- Example scripts can be found in the examples folder of this repository. They only use read-only requests. The 1.x example scripts are kept in examples/Legacy for reference: most of them create, change, & delete example data & they use the 1.x response format (
.data)
Supported functions
The module has 114 public functions in 37 categories that cover all 209 endpoints in the spec (86 GET, 36 POST, 54 PATCH, & 33 DELETE). 35 are read-only Get- functions & 79 are write functions. Every endpoint & its function is listed in the endpoints.csv file.
| Category | Functions |
|---|---|
| Organizations | Get-, New-, Set-, & Remove-ITGlueOrganization |
| Configurations | Get-, New-, Set-, & Remove-ITGlueConfiguration, *-ITGlueConfigurationInterface, Status, & Type |
| Contacts & Locations | Get-, New-, Set-, & Remove-ITGlueContact, ITGlueContactType, & ITGlueLocation |
| Documents | *-ITGlueDocument, Publish-ITGlueDocument, *-ITGlueDocumentFolder, DocumentImage, & DocumentSection |
| Flexible assets | *-ITGlueFlexibleAsset, FlexibleAssetType, & FlexibleAssetField |
| Passwords | *-ITGluePassword, PasswordCategory, & PasswordFolder |
| Relationships | *-ITGlueAttachment, RelatedItem, & ResourceAccess |
| Account | *-ITGlueGroup, User, UserMetric, Checklist, Export, Expiration, Domain, & Log |
| Reference data | Get-ITGlueCountry, Region, Manufacturer, Model, OperatingSystem, Platform, & OrganizationStatus\Type |
Upgrading from 1.x
Version 2.0.0 generates every function from the OpenAPI spec. Every function name of version 1.3.0 still exists, but some behavior changed:
- Functions return the
dataof a response instead of the full response. Code such as(Get-ITGlueOrganization).databecomesGet-ITGlueOrganization. Use-Rawfor the full response (data,meta,links, &included) -AllResultsrequests 1000 items per page (unless-PageSizeis used) & returns the items of every page. With-Rawtheincludeditems of every page are returned as well- Write functions ask for confirmation (
ConfirmImpactHigh), use-Confirm:$falsein scripts that must not prompt - The boolean filters & parameters are
[bool]parameters instead of strings or switches, such as-FilterArchived $false,-FilterImportant $true,-FilterEnabled $true, &-ShowPassword $false('true'&'false'strings are no longer accepted) -Sort&-Includeaccept any value (several values can be comma separated), tab completion shows the documented values-Idis only bound from the pipeline by value (12345 | Get-ITGlueOrganization), a piped object is not used as an ID because every ITGlue object has anidproperty-FilterRangeofGet-ITGlueOrganization&Get-ITGlueExpirationwas removed, use-FilterRangeMyGlueAccountId&-FilterRangeExpirationDate-TypeofNew-,Set-, &Remove-ITGlueResourceAccesswas removed, the type is alwaysresource-accessesRemove-ITGlueChecklist,Remove-ITGlueConfiguration,Remove-ITGlueDocument, &Remove-ITGlueDocumentFolderaccept one or more IDs with-Id& send them as a bulk delete- The parameter sets have new names (
List,ById,ByOrganization,ByOrganizationById,BulkUpdate,BulkDestroy, etc.) - New functions:
Remove-ITGlueConfigurationInterface,Remove-ITGlueConfigurationType,Remove-ITGlueContactType,Remove-ITGlueFlexibleAssetType, &Remove-ITGlueOrganizationType, andSet-ITGlueUsercan bulk update users - The API key can be loaded from the
ITGLUE_API_KEY&ITGLUE_BASE_URIenvironment variables. A configuration file created by version 1.x is still loaded - The example scripts of version 1.x, which create & change example data, moved to
examples/Legacy(each one has a LEGACY banner) & a read-only example was added
Development
The module is built from the files in this repository with the scripts in the build folder. The same steps are run by the GitHub Actions workflows in .github/workflows.
| Script | Description |
|---|---|
| Install-Prerequisites.ps1 | Installs the latest ModuleBuilder, Pester, Microsoft.PowerShell.PlatyPS, & PSScriptAnalyzer |
| New-PublicFunctions.ps1 | (PowerShell 7+) Regenerates every public function, the manifest entries, & docs/endpoints.csv from the spec |
| Get-ITGlueSpec.ps1 | (PowerShell 7+) Downloads the online spec (raw.githubusercontent.com) & saves it as docs/ITGlue-<version>.json |
| Compare-ITGlueSpec.ps1 | Compares the newest local spec in docs with the online spec & optionally updates it |
| Invoke-ModuleBuild.ps1 | Builds the module & the spec into build/Celerium.ITGlue/<version> |
| Invoke-PesterTests.ps1 | Runs the Pester tests against the source or built module |
| Invoke-HelpContent.ps1 | Regenerates the GitHub pages documentation in docs with Microsoft.PowerShell.PlatyPS |
| Publish-CeleriumModule.ps1 | Publishes the built module to the PowerShell Gallery |
The scripts never delete files. Public functions that are no longer generated are moved to build/Archive/<date>.
./build/Install-Prerequisites.ps1
./build/Invoke-ModuleBuild.ps1 -Version 2.0.0
./build/Invoke-PesterTests.ps1 -Version 2.0.0 -BuildTarget built
To support a newer version of the API, run ./build/Compare-ITGlueSpec.ps1 to see what changed in the online spec compared with the newest spec in docs. Run ./build/Get-ITGlueSpec.ps1 to download the online spec as docs/ITGlue-<version>.json (a different file with the same name is first copied to build/Archive), then run ./build/New-PublicFunctions.ps1. The function names of the endpoints are defined in the $FunctionNameMap table of New-PublicFunctions.ps1 & the convenience parameters of version 1.x in the $BodyAttributeMap table.
Live tests make real, read-only GET requests (about 12). They are excluded unless the following environment variables are set and the Live tag is included:
$env:ITGLUE_API_KEY = 'your-api-key'
$env:ITGLUE_BASE_URI = 'https://api.itglue.com' # Optional
./build/Invoke-PesterTests.ps1 -Version 2.0.0 -IncludeTag Live -ExcludeTag Online
Contributing
Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag “enhancement”. Don’t forget to give the project a star! Thanks again!
See the CONTRIBUTING guide for more information about contributing.
License
Distributed under the MIT license. See LICENSE for more information.