Public/Tasks/New-AspireTasks.ps1

<#
.SYNOPSIS
    Creates a new task in the Aspire API.
.DESCRIPTION
    Uses Invoke-AspireRequest to perform a POST request to the /Tasks endpoint.
.PARAMETER AssignedTo
    The user or entity the task is assigned to (required).
.PARAMETER Subject
    The subject of the task (required).
.PARAMETER DueDate
    The due date of the task (optional).
.PARAMETER Notes
    Additional notes for the task (optional).
.PARAMETER OpportunityID
    The ID of the related opportunity (optional).
.PARAMETER Priority
    The priority of the task (optional).
.PARAMETER PropertyID
    The ID of the related property (optional).
.PARAMETER StartDate
    The start date of the task (optional).
.PARAMETER WorkTicketID
    The ID of the related work ticket (optional).
.OUTPUTS
    The response from the API containing the result.
.EXAMPLE
    New-AspireTasks -AssignedTo "user@example.com" -Subject "Complete report"
#>

function New-AspireTasks {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [string]$AssignedTo,
        [Parameter(Mandatory = $true)]
        [string]$Subject,
        [datetime]$DueDate = $null,
        [string]$Notes = $null,
        [int]$OpportunityID = $null,
        [string]$Priority = $null,
        [int]$PropertyID = $null,
        [datetime]$StartDate = $null,
        [int]$WorkTicketID = $null
    )

    $body = @{
        AssignedTo = $AssignedTo
        Subject = $Subject
    }

    if ($DueDate) {
        $body.DueDate = $DueDate.ToString("o")
    }
    if ($Notes) {
        $body.Notes = $Notes
    }
    if ($OpportunityID) {
        $body.OpportunityID = $OpportunityID
    }
    if ($Priority) {
        $body.Priority = $Priority
    }
    if ($PropertyID) {
        $body.PropertyID = $PropertyID
    }
    if ($StartDate) {
        $body.StartDate = $StartDate.ToString("o")
    }
    if ($WorkTicketID) {
        $body.WorkTicketID = $WorkTicketID
    }

    return Invoke-AspireRequest -Method POST -Path "/Tasks" -Body $body
}