Invoke-LMAPIRequest
Syntax
Data (Default)
Invoke-LMAPIRequest -ResourcePath <String> -Method <String> [-QueryParams <Hashtable>] [-Data <Hashtable>] [-Version <Int32>] [-ContentType <String>] [-MaxRetries <Int32>] [-NoRetry] [-OutFile <String>] [-TypeName <String>] [-AsHashtable] [-WhatIf] [-Confirm] [<CommonParameters>]RawBody
Invoke-LMAPIRequest -ResourcePath <String> -Method <String> [-QueryParams <Hashtable>] [-RawBody <String>] [-Version <Int32>] [-ContentType <String>] [-MaxRetries <Int32>] [-NoRetry] [-OutFile <String>] [-TypeName <String>] [-AsHashtable] [-WhatIf] [-Confirm] [<CommonParameters>]Description
The Invoke-LMAPIRequest function provides advanced users with direct access to the LogicMonitor API while leveraging the module’s authentication, retry logic, debug utilities, and error handling. This is useful for accessing API endpoints that don’t yet have dedicated cmdlets in the module.
Examples
Example 1: GET Request
Invoke-LMAPIRequest -ResourcePath "/setting/integrations" -Method GETGet a custom resource not yet supported by a dedicated cmdlet.
Example 2: POST with Data
$data = @{ name = "My Integration" type = "slack" url = "https://hooks.slack.com/services/..."}Invoke-LMAPIRequest -ResourcePath "/setting/integrations" -Method POST -Data $dataCreate a resource with custom payload.
Example 3: Create Device with Custom Properties
# Note: customProperties must be an array of name/value objects$data = @{ name = "server1" displayName = "Production Server" preferredCollectorId = 5 customProperties = @( @{ name = "environment"; value = "production" } @{ name = "owner"; value = "ops-team" } )}Invoke-LMAPIRequest -ResourcePath "/device/devices" -Method POST -Data $dataExample 4: PATCH Update
$updates = @{ description = "Updated description"}Invoke-LMAPIRequest -ResourcePath "/device/devices/123" -Method PATCH -Data $updatesUpdate a resource with PATCH.
Example 5: DELETE Resource
Invoke-LMAPIRequest -ResourcePath "/setting/integrations/456" -Method DELETEDelete a resource (will prompt for confirmation).
Example 6: Query Parameters
$queryParams = @{ size = 500 filter = 'status:"active"' fields = "id,name,status"}Invoke-LMAPIRequest -ResourcePath "/device/devices" -Method GET -QueryParams $queryParams -Version 3Get with query parameters and custom version.
Example 7: Raw Body
$rawJson = '{"name":"test","customField":null}'Invoke-LMAPIRequest -ResourcePath "/custom/endpoint" -Method POST -RawBody $rawJsonUse raw body for special formatting requirements.
Example 8: Download File
Invoke-LMAPIRequest -ResourcePath "/report/reports/123/download" -Method GET -OutFile "C:\Reports\report.pdf"Download a report to file.
Example 9: Format Output
# Use existing format definitionInvoke-LMAPIRequest -ResourcePath "/device/devices" -Method GET -TypeName "LogicMonitor.Device"
# Or pipe to Format-TableInvoke-LMAPIRequest -ResourcePath "/device/devices" -Method GET | Format-Table id, name, displayName, statusControl output formatting.
Example 10: Pagination
$offset = 0$size = 1000$allResults = @()do { $response = Invoke-LMAPIRequest -ResourcePath "/device/devices" -Method GET -QueryParams @{ size = $size; offset = $offset } $allResults += $response $offset += $size} while ($response.Count -eq $size)Get paginated results manually.
Parameters
-ResourcePath
The API resource path (e.g., “/device/devices”, “/setting/integrations/123”). Do not include the base URL or query parameters here.
Type: StringParameter Sets: (All)Aliases:
Required: TruePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False-Method
The HTTP method to use. Valid values: GET, POST, PATCH, PUT, DELETE.
Type: StringParameter Sets: (All)Aliases:
Required: TruePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False-QueryParams
Optional hashtable of query parameters to append to the request URL. Example: @{ size = 100; offset = 0; filter = ‘name:“test”’ }
Type: HashtableParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False-Data
Optional hashtable containing the request body data. Will be automatically converted to JSON. Use this for POST, PATCH, and PUT requests.
Type: HashtableParameter Sets: DataAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False-RawBody
Optional raw string body to send with the request. Use this instead of -Data when you need complete control over the request body format. Mutually exclusive with -Data.
Type: StringParameter Sets: RawBodyAliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False-Version
The X-Version header value for the API request. Defaults to 3. Some newer API endpoints may require different version numbers.
Type: Int32Parameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: 3Accept pipeline input: FalseAccept wildcard characters: False-ContentType
The Content-Type header for the request. Defaults to “application/json”.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: application/jsonAccept pipeline input: FalseAccept wildcard characters: False-MaxRetries
Maximum number of retry attempts for transient errors. Defaults to 3. Set to 0 to disable retries.
Type: Int32Parameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: 3Accept pipeline input: FalseAccept wildcard characters: False-NoRetry
Switch to completely disable retry logic and fail immediately on any error.
Type: SwitchParameterParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: FalseAccept pipeline input: FalseAccept wildcard characters: False-OutFile
Path to save the response content to a file. Useful for downloading reports or exports.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False-TypeName
Optional type name to add to the returned objects (e.g., “LogicMonitor.CustomResource”). This enables proper formatting if you have custom format definitions.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False-AsHashtable
Switch to return the response as a hashtable instead of a PSCustomObject.
Type: SwitchParameterParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: FalseAccept pipeline input: FalseAccept wildcard characters: False-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Type: SwitchParameterParameter Sets: (All)Aliases: wi
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False-Confirm
Prompts you for confirmation before running the cmdlet.
Type: SwitchParameterParameter Sets: (All)Aliases: cf
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: FalseCommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
None
You cannot pipe objects to this command.
Outputs
System.Object
Returns the API response as a PSCustomObject by default, or as specified by -AsHashtable.
Notes
You must run Connect-LMAccount before running this command.
This cmdlet is designed for advanced users who need to:
- Access API endpoints not yet covered by dedicated cmdlets
- Test new API features or beta endpoints
- Implement custom workflows requiring direct API access
- Prototype new functionality before requesting cmdlet additions
For standard operations, use the dedicated cmdlets (Get-LMDevice, New-LMDevice, etc.) as they provide better parameter validation, documentation, and user experience.