
function Revoke-SectigoCertificate {
    [CmdletBinding(SupportsShouldProcess=$true)]
    param (
        [string]$ApiToken=$env:SectigoToken,

        [int]$reasonCode=4,
        [Parameter(Mandatory=$true)]
        [string]$reason,
        [Parameter(Mandatory=$true)]
        [string]$OrderId
    )

   if (-Not $ApiToken) {
        $ApiToken=Read-Host
    }
    . $PSScriptRoot\..\Private\Set-Onload.ps1

    [string]$RevokeUrl = "${BaseAPIUrl}/api/ssl/v1/revoke/${OrderId}"

Write-Verbose -Verbose "RequestUrl: $RevokeUrl"

    $headers = @{
        "Authorization" = "Bearer $ApiToken"
        "Content-Type" = "application/json"  # <-- Cleaned up syntax
    }

    $body = @{
        reasonCode = $reasonCode
        reason = $reasonCode
    }

    $jsonBody = $body | ConvertTo-Json

    # --- API Call ---
    Write-Verbose "Attempting to retrieve certificate for Order ID: $OrderId"

    try {
        $response=Invoke-RestMethod -Uri $RevokeUrl -Method POST -Headers $headers -Body $jsonBody -ContentType "application/json"
        return $response
        "Success"
    } catch {
        Write-Error "API Request Failed: $($_.Exception.Message)"
        return $null
    }
}