Public/Attachments/New-AspireAttachment.ps1

<#
.SYNOPSIS
    Uploads a new attachment to the Aspire API.
.DESCRIPTION
    Uses Invoke-AspireRequest to perform a POST request to the /Attachments endpoint to upload a file attachment.
.PARAMETER FileName
    The name of the file to upload (required).
.PARAMETER FileData
    The base64-encoded file data (required).
.PARAMETER ObjectId
    The ID of the object to attach the file to (required).
.PARAMETER ObjectCode
    The code representing the type of object (e.g., 'WorkTicket', 'Property') (required).
.PARAMETER AttachmentTypeId
    The ID of the attachment type (required).
.PARAMETER AttachToInvoice
    Optional boolean indicating if the attachment should be attached to an invoice.
.PARAMETER ExposeToCrew
    Optional boolean indicating if the attachment should be exposed to the crew.
.OUTPUTS
    The response from the API containing the attachment details.
.EXAMPLE
    New-AspireAttachment -FileName "example.pdf" -FileData "base64data" -ObjectId 123 -ObjectCode "WorkTicket" -AttachmentTypeId 1
#>

function New-AspireAttachment {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [string]$FileName,
        [Parameter(Mandatory = $true)]
        [string]$FileData,
        [Parameter(Mandatory = $false)]
        [int]$ObjectId,
        [Parameter(Mandatory = $true)]
        [string]$ObjectCode,
        [Parameter(Mandatory = $true)]
        [int]$AttachmentTypeId,
        [bool]$AttachToInvoice = $null,
        [bool]$ExposeToCrew = $null
    )

    $body = @{
        FileName = $FileName
        FileData = $FileData
        ObjectId = $ObjectId
        ObjectCode = $ObjectCode
        AttachmentTypeId = $AttachmentTypeId
    }

    if ($AttachToInvoice -ne $null) {
        $body.AttachToInvoice = $AttachToInvoice
    }

    if ($ExposeToCrew -ne $null) {
        $body.ExposeToCrew = $ExposeToCrew
    }

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