From e2344039d2b82d22c5f2fd5a54f3a2a4a5e3bd66 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:12:06 +0100 Subject: [PATCH 1/9] Updated to work with relative URL --- PSIdentityNow/{Private => Public}/Invoke-IDNWRestMethod.ps1 | 3 +++ 1 file changed, 3 insertions(+) rename PSIdentityNow/{Private => Public}/Invoke-IDNWRestMethod.ps1 (98%) diff --git a/PSIdentityNow/Private/Invoke-IDNWRestMethod.ps1 b/PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 similarity index 98% rename from PSIdentityNow/Private/Invoke-IDNWRestMethod.ps1 rename to PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 index e9e4b1b..5322e5a 100644 --- a/PSIdentityNow/Private/Invoke-IDNWRestMethod.ps1 +++ b/PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 @@ -77,6 +77,9 @@ function Invoke-IDNWRestMethod { # Check if connected to IdentityNow Test-IDNWConnection + # Form complete URL + $Url = ("{0}{1}" -f $($script:IDNWEnv.BaseAPIUrl), $Url) + # Create authorization header $Token = ConvertFrom-SecureString $script:IDNWEnv.SessionToken -AsPlainText $Headers = @{ From 7fb5d4316c9023c1b87527991cfb94caeff73b89 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:12:29 +0100 Subject: [PATCH 2/9] Updated to send relative URL --- PSIdentityNow/Public/Get-IDNWObject.ps1 | 2 +- PSIdentityNow/Public/New-IDNWObject.ps1 | 2 +- PSIdentityNow/Public/Remove-IDNWObject.ps1 | 2 +- PSIdentityNow/Public/Set-IDNWObject.ps1 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PSIdentityNow/Public/Get-IDNWObject.ps1 b/PSIdentityNow/Public/Get-IDNWObject.ps1 index 152c3c3..9901d68 100644 --- a/PSIdentityNow/Public/Get-IDNWObject.ps1 +++ b/PSIdentityNow/Public/Get-IDNWObject.ps1 @@ -71,7 +71,7 @@ function Get-IDNWObject { $Splat = @{} # Configure the Url - $url = "$($script:IDNWEnv.BaseAPIUrl)/$ObjectType" + $url = "/$ObjectType" switch ($PSCmdlet.ParameterSetName) { 'byId' { diff --git a/PSIdentityNow/Public/New-IDNWObject.ps1 b/PSIdentityNow/Public/New-IDNWObject.ps1 index cc96607..0d605d4 100644 --- a/PSIdentityNow/Public/New-IDNWObject.ps1 +++ b/PSIdentityNow/Public/New-IDNWObject.ps1 @@ -53,7 +53,7 @@ function New-IDNWObject { $Body = $Data | ConvertTo-Json -Depth 100 # Configure the Url - $url = "$($script:IDNWEnv.BaseAPIUrl)/$ObjectType" + $url = "/$ObjectType" # ShouldProcess to support -WhatIf if ($PSCmdlet.ShouldProcess($ObjectType, "Create object")){ diff --git a/PSIdentityNow/Public/Remove-IDNWObject.ps1 b/PSIdentityNow/Public/Remove-IDNWObject.ps1 index e3c297a..1b154d8 100644 --- a/PSIdentityNow/Public/Remove-IDNWObject.ps1 +++ b/PSIdentityNow/Public/Remove-IDNWObject.ps1 @@ -44,7 +44,7 @@ function Remove-IDNWObject { $Method = 'DELETE' # Configure the Url - $url = "$($script:IDNWEnv.BaseAPIUrl)/$ObjectType/$Id" + $url = "/$ObjectType/$Id" # ShouldProcess to support -WhatIf if ($PSCmdlet.ShouldProcess($Id, "Delete $ObjectType")) { diff --git a/PSIdentityNow/Public/Set-IDNWObject.ps1 b/PSIdentityNow/Public/Set-IDNWObject.ps1 index bc815b7..b5caaa0 100644 --- a/PSIdentityNow/Public/Set-IDNWObject.ps1 +++ b/PSIdentityNow/Public/Set-IDNWObject.ps1 @@ -58,7 +58,7 @@ function Set-IDNWObject { $Body = ConvertTo-Json @($Data) -Depth 100 # Configure the Url - $url = "$($script:IDNWEnv.BaseAPIUrl)/$ObjectType/$Id" + $url = "/$ObjectType/$Id" # ShouldProcess to support -WhatIf if ($PSCmdlet.ShouldProcess($ObjectType, "Update object")){ From d956965ce0e2a3f16f7e1c2e17984449dbe087c1 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:12:50 +0100 Subject: [PATCH 3/9] Updated version number format to include prerelease label if present --- PSIdentityNow/Public/Connect-IDNW.ps1 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/PSIdentityNow/Public/Connect-IDNW.ps1 b/PSIdentityNow/Public/Connect-IDNW.ps1 index aef9c9a..7e6ab92 100644 --- a/PSIdentityNow/Public/Connect-IDNW.ps1 +++ b/PSIdentityNow/Public/Connect-IDNW.ps1 @@ -71,6 +71,15 @@ function Connect-IDNW { } $script:IDNWEnv = Get-IDNWEnvironment @Parameters + + # Concatenate full version string with prerelease label if present + $PrereleaseLabel = $MyInvocation.MyCommand.Module.PrivateData.PSData['Prerelease'] + $ModuleVersion = $MyInvocation.MyCommand.Module.Version + if (-not [string]::isNullOrEmpty($PrereleaseLabel)) { + $VersionString = ("{0}-{1}" -f $ModuleVersion, $PrereleaseLabel) + } else { + $VersionString = $ModuleVersion + } # Build formatted output using a here-string for alignment $identityNowInfo = @" @@ -85,7 +94,7 @@ Org: $($script:IDNWEnv.SessionTokenDetails.org) Authorities: $($script:IDNWEnv.SessionTokenDetails.Authorities -join ', ') Base URL: $($script:IDNWEnv.BaseAPIURL) API Version: $($script:IDNWEnv.APIVersion) -Module Version: $($MyInvocation.MyCommand.Module.Version) +Module Version: $($VersionString) Token Expires: $($script:IDNWEnv.SessionTokenDetails.expiryDateTime) "@ From fbd52b568c7362dab47f534701d984cb99455d7b Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:15:30 +0100 Subject: [PATCH 4/9] Added Invoke-IDNWRestMethod to Exported Functions --- PSIdentityNow/PSIdentityNow.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSIdentityNow/PSIdentityNow.psd1 b/PSIdentityNow/PSIdentityNow.psd1 index a20e05e..42ed5e9 100644 --- a/PSIdentityNow/PSIdentityNow.psd1 +++ b/PSIdentityNow/PSIdentityNow.psd1 @@ -69,7 +69,7 @@ # NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. - FunctionsToExport = @('Connect-IDNW', 'Disconnect-IDNW', 'Get-IDNWObject', 'Get-IDNWOrg', 'New-IDNWObject', 'Remove-IDNWObject', 'Set-IDNWObject') + FunctionsToExport = @('Connect-IDNW', 'Disconnect-IDNW', 'Get-IDNWObject', 'Get-IDNWOrg', 'Invoke-IDNWRestMethod', 'New-IDNWObject', 'Remove-IDNWObject', 'Set-IDNWObject') # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. # CmdletsToExport = @() From 508f6e05492574c917b54fa38d503b9412e4deac Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:16:16 +0100 Subject: [PATCH 5/9] Revert "Updated version number format to include prerelease label if present" This reverts commit d956965ce0e2a3f16f7e1c2e17984449dbe087c1. --- PSIdentityNow/Public/Connect-IDNW.ps1 | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/PSIdentityNow/Public/Connect-IDNW.ps1 b/PSIdentityNow/Public/Connect-IDNW.ps1 index 7e6ab92..aef9c9a 100644 --- a/PSIdentityNow/Public/Connect-IDNW.ps1 +++ b/PSIdentityNow/Public/Connect-IDNW.ps1 @@ -71,15 +71,6 @@ function Connect-IDNW { } $script:IDNWEnv = Get-IDNWEnvironment @Parameters - - # Concatenate full version string with prerelease label if present - $PrereleaseLabel = $MyInvocation.MyCommand.Module.PrivateData.PSData['Prerelease'] - $ModuleVersion = $MyInvocation.MyCommand.Module.Version - if (-not [string]::isNullOrEmpty($PrereleaseLabel)) { - $VersionString = ("{0}-{1}" -f $ModuleVersion, $PrereleaseLabel) - } else { - $VersionString = $ModuleVersion - } # Build formatted output using a here-string for alignment $identityNowInfo = @" @@ -94,7 +85,7 @@ Org: $($script:IDNWEnv.SessionTokenDetails.org) Authorities: $($script:IDNWEnv.SessionTokenDetails.Authorities -join ', ') Base URL: $($script:IDNWEnv.BaseAPIURL) API Version: $($script:IDNWEnv.APIVersion) -Module Version: $($VersionString) +Module Version: $($MyInvocation.MyCommand.Module.Version) Token Expires: $($script:IDNWEnv.SessionTokenDetails.expiryDateTime) "@ From 14507c8dabee2b2acddbc0ceb003eb839f9e9ad1 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:49:17 +0100 Subject: [PATCH 6/9] Updated Parameters --- PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 b/PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 index 5322e5a..2ca7a33 100644 --- a/PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 +++ b/PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 @@ -1,12 +1,12 @@ <# .SYNOPSIS - Invoke a REST method to the IdentityNow API. + Invoke the IdentityNow REST API. .DESCRIPTION This function is used to invoke a REST method to the IdentityNow API. It will handle pagination and retries. .PARAMETER Url - The URL to call. + The relative URL to call. .PARAMETER UrlParams The parameters to add to the URL. @@ -44,24 +44,24 @@ function Invoke-IDNWRestMethod { PositionalBinding = $True) ] param ( - [Parameter()] + [Parameter(Mandatory = $true)] [String] $Url, - [Parameter()] + [Parameter(Mandatory = $false)] [Hashtable] $UrlParams, - [Parameter()] + [Parameter(Mandatory = $false)] [ValidateSet("GET", "PATCH", "POST", "PUT", "DELETE")] [String] $Method = "GET", - [Parameter()] + [Parameter(Mandatory = $false)] [String] $Body, - [Parameter()] + [Parameter(Mandatory = $false)] [String] $ContentType = "application/json", From 2f74090e3db871af41a58e45274cac8fbc325a72 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:50:24 +0100 Subject: [PATCH 7/9] Added documentation --- Documentation/Invoke-IDNWRestMethod.md | 94 ++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Documentation/Invoke-IDNWRestMethod.md diff --git a/Documentation/Invoke-IDNWRestMethod.md b/Documentation/Invoke-IDNWRestMethod.md new file mode 100644 index 0000000..d566c57 --- /dev/null +++ b/Documentation/Invoke-IDNWRestMethod.md @@ -0,0 +1,94 @@ +# Invoke-IDNWRestMethod + +## SYNOPSIS +Invoke the IdentityNow REST API. + +## SYNTAX +``` +Invoke-IDNWRestMethod [-Url] [[-UrlParams] ] [[-Method] ] [[-Body] ] [[-ContentType] ] [[-MaxRetries] ] [[-PauseDuration] ] [] +``` + +## DESCRIPTION +This function is used to invoke a REST method to the IdentityNow API. It will handle pagination and retries. + +## EXAMPLES +```powershell +-------------------------- EXAMPLE 1 -------------------------- +Invoke-IDNWRestMethod -Url '/roles' -Method 'GET' + +``` + +## PARAMETERS +### -Url +The relative URL to call. +``` +Required? true +Position? 1 +Default value +Accept pipeline input? false +Accept wildcard characters? false +``` +### -UrlParams +The parameters to add to the URL. +``` +Required? false +Position? 2 +Default value +Accept pipeline input? false +Accept wildcard characters? false +``` +### -Method +The HTTP method to use. +``` +Required? false +Position? 3 +Default value GET +Accept pipeline input? false +Accept wildcard characters? false +``` +### -Body +The body of the request. +``` +Required? false +Position? 4 +Default value +Accept pipeline input? false +Accept wildcard characters? false +``` +### -ContentType +The content type of the request. +``` +Required? false +Position? 5 +Default value application/json +Accept pipeline input? false +Accept wildcard characters? false +``` +### -MaxRetries +The maximum number of retries to attempt. +``` +Required? false +Position? 6 +Default value 3 +Accept pipeline input? false +Accept wildcard characters? false +``` +### -PauseDuration +The duration to pause between retries. +``` +Required? false +Position? 7 +Default value 2 +Accept pipeline input? false +Accept wildcard characters? false +``` + + +## INPUTS +None + +## OUTPUTS +System.Object[] + +## RELATED LINKS + From 864840b0eb6561435e6ee2f427b8aa437c2c02f3 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:50:58 +0100 Subject: [PATCH 8/9] Updated Example --- PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 b/PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 index 2ca7a33..8f32410 100644 --- a/PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 +++ b/PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 @@ -27,7 +27,7 @@ The duration to pause between retries. .EXAMPLE - Invoke-IDNWRestMethod -Url 'https://$($script:IDNWEnv.BaseAPIUrl)/roles' -Method 'GET' + Invoke-IDNWRestMethod -Url '/roles' -Method 'GET' .INPUTS None From f662c9ad4f4648753bd474c4144c6535b4679020 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:52:19 +0100 Subject: [PATCH 9/9] Added Invoke-IDNWRestMethod Function --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 56a3110..67d7052 100644 --- a/readme.md +++ b/readme.md @@ -150,6 +150,8 @@ Disconnects from IdentityNow. Get the specified objects from IdentityNow. #### [Get-IDNWOrg](Documentation/Get-IDNWOrg.md) Get the IdentityNow Organisation. +#### [Invoke-IDNWRestMethod](Documentation/Invoke-IDNWRestMethod.md) +Invoke the IdentityNow REST API. #### [New-IDNWObject](Documentation/New-IDNWObject.md) Create a new object in IdentityNow. #### [Remove-IDNWObject](Documentation/Remove-IDNWObject.md)