homotechsual / HaloAPI

PowerShell module for the Halo Service Solutions series of software products.
MIT License
48 stars 39 forks source link

[Bug]: Sometimes weird behavior in a Session #53

Closed xasz closed 2 months ago

xasz commented 2 months ago

Contact Details

No response

What happened?

Sometimes it seems that previous Parameter get not cleared,

Version

1.22.1

Which operating systems have you tested on?

What PowerShell version are you running?

7.4.3

Halo Product

Halo PSA

Halo Version

2.152.74

What command did you run?

Example Code::

$query = "SELECT faultid FROM FAULTS WHERE  Status = 8 AND FLastUpdate < DATEADD(day, -5, GETDATE())  AND fdeleted = 0"
$RequestParams = @{
    Method = 'POST'
    Uri = 'https://myinstance.halopsa.com:443/api/Report'
    Body = @{ 
        'sql' = $Query
        _loadreportonly = $true
    } | ConvertTo-Json -AsArray
} 
$response =  Invoke-HaloRequest -WebRequestParams $RequestParams

$ticketIds =  $response.report.rows.faultid

$ticketIds = $ticketIds | Select-Object -First 10

foreach ($ticketId in $ticketIds) {

    Write-Host "Ticket $ticketId wird geschlossen"
    $target = @{
        id = $ticketId
        status_id = 9
        closure_note = "Geloest."
        _force = $true
    }
    Set-HaloTicket -Ticket $target -Verbose
}

What was the output of the command?

Output:

VERBOSE: Running in single-ticket mode because '-TicketID' was provided.
VERBOSE: Building parameters for Get-HaloTicket. Use '-Debug' with '-Verbose' to see parameter values as they are built.
VERBOSE: Building [HttpQSCollection] for New-HaloGETRequest
VERBOSE: Page Size: 0
VERBOSE: Attempt 1 of 10
VERBOSE: Making a GET request to https://ostalbit.halopsa.com:443/api/tickets/7572
VERBOSE: Requested HTTP/1.1 GET with 0-byte payload
VERBOSE: Received HTTP/1.1 29376-byte response of content type application/json
VERBOSE: Request successful.
VERBOSE: Request returned results.
VERBOSE: Performing the operation "Update" on target "Tickets".
VERBOSE: Attempt 1 of 10
VERBOSE: Making a POST request to https://ostalbit.halopsa.com:443/api/ticketsSELECT faultid FROM FAULTS WHERE  Status = 8 AND FLastUpdate < DATEADD(day, -5, GETDATE())  AND fdeleted = 0
VERBOSE: Requested HTTP/1.1 POST with 107-byte payload
VERBOSE: Received HTTP/1.1 response of content type  of unknown size
VERBOSE: Generating Halo error output.

Result is a 404.

What makes me wonder is this line:

`VERBOSE: Making a POST request to https://ostalbit.halopsa.com:443/api/ticketsSELECT faultid FROM FAULTS WHERE  Status = 8 `

Why does the select appear here?
xasz commented 2 months ago

I could resolve it by renaming $query to $queryString in my code. I have no idea, why the method fetches my $query variable in here, but i currently have no time to investigate :)

homotechsual commented 2 months ago

We use $query internally. This isn't getting fixed in v1 but in v2 we'll namespace all internal variables to prevent collisions.