Skip to content

Invoke-LMAPIRequest

Terminal window
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>]
Terminal window
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>]

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.

Terminal window
Invoke-LMAPIRequest -ResourcePath "/setting/integrations" -Method GET

Get a custom resource not yet supported by a dedicated cmdlet.

Terminal window
$data = @{
name = "My Integration"
type = "slack"
url = "https://hooks.slack.com/services/..."
}
Invoke-LMAPIRequest -ResourcePath "/setting/integrations" -Method POST -Data $data

Create a resource with custom payload.

Example 3: Create Device with Custom Properties

Section titled “Example 3: Create Device with Custom Properties”
Terminal window
# 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 $data
Terminal window
$updates = @{
description = "Updated description"
}
Invoke-LMAPIRequest -ResourcePath "/device/devices/123" -Method PATCH -Data $updates

Update a resource with PATCH.

Terminal window
Invoke-LMAPIRequest -ResourcePath "/setting/integrations/456" -Method DELETE

Delete a resource (will prompt for confirmation).

Terminal window
$queryParams = @{
size = 500
filter = 'status:"active"'
fields = "id,name,status"
}
Invoke-LMAPIRequest -ResourcePath "/device/devices" -Method GET -QueryParams $queryParams -Version 3

Get with query parameters and custom version.

Terminal window
$rawJson = '{"name":"test","customField":null}'
Invoke-LMAPIRequest -ResourcePath "/custom/endpoint" -Method POST -RawBody $rawJson

Use raw body for special formatting requirements.

Terminal window
Invoke-LMAPIRequest -ResourcePath "/report/reports/123/download" -Method GET -OutFile "C:\Reports\report.pdf"

Download a report to file.

Terminal window
# Use existing format definition
Invoke-LMAPIRequest -ResourcePath "/device/devices" -Method GET -TypeName "LogicMonitor.Device"
# Or pipe to Format-Table
Invoke-LMAPIRequest -ResourcePath "/device/devices" -Method GET |
Format-Table id, name, displayName, status

Control output formatting.

Terminal window
$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.

The API resource path (e.g., “/device/devices”, “/setting/integrations/123”). Do not include the base URL or query parameters here.

Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

The HTTP method to use. Valid values: GET, POST, PATCH, PUT, DELETE.

Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

Optional hashtable of query parameters to append to the request URL. Example: @{ size = 100; offset = 0; filter = ‘name:“test”’ }

Type: Hashtable
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

Optional hashtable containing the request body data. Will be automatically converted to JSON. Use this for POST, PATCH, and PUT requests.

Type: Hashtable
Parameter Sets: Data
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

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: String
Parameter Sets: RawBody
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

The X-Version header value for the API request. Defaults to 3. Some newer API endpoints may require different version numbers.

Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 3
Accept pipeline input: False
Accept wildcard characters: False

The Content-Type header for the request. Defaults to “application/json”.

Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: application/json
Accept pipeline input: False
Accept wildcard characters: False

Maximum number of retry attempts for transient errors. Defaults to 3. Set to 0 to disable retries.

Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 3
Accept pipeline input: False
Accept wildcard characters: False

Switch to completely disable retry logic and fail immediately on any error.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

Path to save the response content to a file. Useful for downloading reports or exports.

Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

Optional type name to add to the returned objects (e.g., “LogicMonitor.CustomResource”). This enables proper formatting if you have custom format definitions.

Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

Switch to return the response as a hashtable instead of a PSCustomObject.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

You cannot pipe objects to this command.

Returns the API response as a PSCustomObject by default, or as specified by -AsHashtable.

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.