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 + 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 = @() 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/Private/Invoke-IDNWRestMethod.ps1 b/PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 similarity index 94% rename from PSIdentityNow/Private/Invoke-IDNWRestMethod.ps1 rename to PSIdentityNow/Public/Invoke-IDNWRestMethod.ps1 index e9e4b1b..8f32410 100644 --- a/PSIdentityNow/Private/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. @@ -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 @@ -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", @@ -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 = @{ 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")){ 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)