homotechsual / HaloAPI

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

[Bug]: Can't create a ticket via the API #10

Closed athornfam2 closed 2 years ago

athornfam2 commented 2 years ago

Contact Details

No response

What happened?

No matter what I enter into New-HaloTicket or New-HaloTicketType it always error's.

Version

1.0.1

Which operating systems have you tested on?

What PowerShell version are you running?

7.2.0-preview.8

Halo Product

Halo ISTM

Halo Version

2.81.18

What command did you run?

New-HaloTicket & New-HaloTicketType

What was the output of the command?

cmdlet New-HaloTicket at command pipeline position 1
Supply values for the following parameters:
Ticket[0]: 1
Ticket[1]: Test
Ticket[2]: Create
Ticket[3]: 
Invoke-HaloPreFlightCheck: /Users/matthew.wolf/Downloads/HaloAPI-main/Public/New/New-HaloTicket.ps1:17:5
Line |
  17 |      Invoke-HaloPreFlightCheck
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~
     | The term 'Invoke-HaloPreFlightCheck' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was
     | included, verify that the path is correct and try again.

New-HaloError: /Users/matthew.wolf/Downloads/HaloAPI-main/Public/New/New-HaloTicket.ps1:23:9
Line |
  23 |          New-HaloError -ErrorRecord $_
     |          ~~~~~~~~~~~~~
     | The term 'New-HaloError' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included,
     | verify that the path is correct and try again.
homotechsual commented 2 years ago

It doesn't look like the module is installed / imported correctly. It's failing to find private commands which are only loaded when the psm1 file is imported with Import-Module -Name HaloAPI or if you've downloaded from GitHub (only useful if you're developing the module really) Import-Module /Path/To/HaloAPI/HaloAPI.psm1

athornfam2 commented 2 years ago

I went through the process again to make sure I wasn't missing anything. Other commands are working like Get-HaloTicket -TicketID 399

PS C:\Users\mwolf> Install-Module haloapi

Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): a PS C:\Users\mwolf> Import-Module HaloAPI PS C:\Users\mwolf> Connect-HaloAPI -ClientID "#####" -Tenant "@@@@" -URL "https://###.haloitsm.com" -ClientSecret "####" -Scopes "all" Connected to the Halo API with tenant URL https://###.haloitsm.com:443/ PS C:\Users\mwolf> New-HaloTicket

cmdlet New-HaloTicket at command pipeline position 1 Supply values for the following parameters: Ticket[0]: Test Ticket[1]: Temp1234 Ticket[2]: New-HaloError: C:\Users\mwolf\Documents\PowerShell\Modules\HaloAPI\1.9.0\Public\New\New-HaloTicket.ps1:23 Line | 23 | New-HaloError -ErrorRecord $_ | ~~~~~~~~~ | The Halo API said {"[0]":["Error converting value \"Test\" to type 'HaloClassLibrary.Models.Faults'. | Path '[0]', line 2, position 8."],"[1]":["Error converting value \"Temp1234\" to type | 'HaloClassLibrary.Models.Faults'. Path '[1]', line 3, position 12."]}. The API returned the following | HTTP error response: 400 Bad Request

PS C:\Users\mwolf>

homotechsual commented 2 years ago

You're passing a string as a ticket object.

A ticket needs to look something like this:

New-HaloTicket -Ticket @{ summary = "Ticket Subject"; tickettype_id = 1 }

There are 20/30 more properties you can (and might want to) set - Get-HaloTicket will give you the object structure/property names.

What the module is doing is PowerShell saying "you need to have something in the -Ticket parameter, give me the value." unfortunately for you it's going to keep asking for more values (Ticket[0], Ticket[1]) because the -Ticket parameter accepts an array of ticket objects which Halo will batch-process.

athornfam2 commented 2 years ago

Thanks @homotechsual that helped. I'll look at the example API documentation Halo to see where I need to add... for example the category_1 when we submit tickets.

I tried to perform the Get-Help on the command but it looked like the -Examples were a little lite. I presume a work in progress? but good work to both of you on this. Saved me a ton of time not reinventing the wheel.

homotechsual commented 2 years ago

Better documentation is coming - I'm reworking the entire documentation site/layout at the moment and then expanding content.