christaylorcodes / ConnectWiseManageAPI

PowerShell wrapper for the ConnectWise Manage REST API
MIT License
108 stars 61 forks source link

Add Project Ticket #43

Open JB0710 opened 1 year ago

JB0710 commented 1 year ago

Trying to add a project ticket via PowerShell, when I use the -project with New-CWMTicket I get "New-CWMTicket : Cannot process argument transformation on parameter 'project'. Cannot convert the "386" value of type "System.Int32" to type "System.Collections.Hashtable".

Any assistance would be greatly appreciated!

Here is my code:

$CWMConnectionInfo = @{
   Server      = 'na.myconnectwise.net'
   Company     = 'BLANK'
   pubkey      = 'BLANK'
   privatekey  = 'BLANK'
   clientid    = 'BLANK'
}

# Install/Update/Load the module
if(Get-InstalledModule 'ConnectWiseManageAPI' -ErrorAction SilentlyContinue){ Update-Module 'ConnectWiseManageAPI' -Verbose }
else{ Install-Module 'ConnectWiseManageAPI' -Verbose }
Import-Module 'ConnectWiseManageAPI'

# Connect to your Manage server
Connect-CWM @CWMConnectionInfo -Force -Verbose

# Choose a company to make test a ticket for
#$Companies = Get-CWMCompany -all
#$Company = $Companies | Select-Object ID, Name | Out-GridView -OutputMode Single -Title 'Select Company'
$Company = '457'
$Project = '386'

$NewTicketParameters = @{
    summary = 'Install N-Central Agent on FWGLEX31LPTP'
    # We want to pass Manage objects as hash tables
    company           =    @{"identifier" = "$Company"}
    contactName = 'BLANK'
    contactPhoneNumber = 'BLANK'
    contactEmailAddress = 'BLANK'

}

$NewTicket = New-CWMTicket @NewTicketParameters -project $Project

# To clear your connection information from memory you can terminate the session or issue the disconnect command.
Disconnect-CWM
Absoblogginlutely commented 1 year ago

Long time since you posted this, but in case it helps others, you need to pass the project through as a hash table too. That will fix this particular experience but it will still show up as a service ticket. $newticket = new-cwmticket @NewTicketParameters -project @{id=$project}

Or you can add this to your NewTicketParameters splat