Skip to content

Invoke-CIPPRestApi is converting hastables to an array #100

Description

@jonwbstr

Description

When running the following code I was getting the error, "Invoke-RestMethod: Error - Could not add task: The property 'ScheduledTime' cannot be found on this object. Verify that the property exists and can be set."

# Get jobs
$BodyPayload = @{
    TenantFilter = "AllTenants"
    ShowHidden = $true
}
$AllJobs = Invoke-CIPPRestMethod -Endpoint "/api/ListScheduledItems" -method POST -Body $BodyPayload

$Job = $AllJobs[0]

$UpdatePayload = @{
        RowKey        = $Job.RowKey
        Name          = $Job.Name
        tenantFilter  = $Job.Tenant
        Hidden        = $Job.Hidden
        Command       = $Job.Command
        Parameters    = $Job.Parameters
        Recurrence    = $Job.Recurrence
        ScheduledTime = $NewScheduleTime
    }
Invoke-CippRestMethod -Endpoint '/api/AddScheduledItem' -Method 'POST' -Body $UpdatePayload|Out-Null

Upon inspection I found Invoke-CIPPRestMethod defines Body as a hashtable array:

[hashtable[]]$Body = @{},

After changing it to the following, the command completed successfully:

[hashtable]$Body = @{}

Environment data

Module Version Number: v10.5.5
CIPP Backend version number: v10.5.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions