flycastpartnersinc / FreshservicePS

Powershell Module to interface with Freshworks Freshservice REST API.
MIT License
23 stars 5 forks source link

New-FreshserviceContract attachments not working #12

Open rasimmers opened 1 year ago

rasimmers commented 1 year ago

Expected Behavior

New-FreshserviceContract will create a Contract with specified attachment(s).

Current Behavior

Error message from API:

| {"description":"Validation failed","errors":[{"field":"auto_renew","message":"It should be of type
| Boolean","code":"datatype_mismatch"},{"field":"notify_expiry","message":"It should be of type
| Boolean","code":"datatype_mismatch"},{"field":"notify_to","message":"It should be in the 'valid email
| address' format","code":"invalid_value","nested_field":"notify_to.[0]"}]}

Appears to be an issue with data being passed as multipart/form-data.

Possible Solution

As a workaround, create Contract without attachment(s) and then use Set-FreshServiceContract to attach items.

Steps to Reproduce (for bugs)

  1. Create a new Contract and specify the path to a file with -attachments:
    
    $icd = New-FreshServiceContractItem -item_name License -pricing_model per_unit -cost 18.44 -count 350 -comments 'Per user licensing costs'

$contractParams = @{

id = 6

name               = 'Microsoft O365 Contract V2'
description        = 'Test contract from API'
vendor_id          = 21000085375 #Get-FreshServiceVendor
auto_renew         = $true
notify_expiry      = $true
notify_before      = 30
approver_id        = 21000418005 #Get-FSRequester
start_date         = Get-Date
end_date           = (Get-Date).AddDays(365)
cost               = 6454.00
contract_number    = 'MSFT11'
contract_type_id   = 1
visible_to_id      = 21000188401 #Get-FSAgentGroup
notify_to          = 'john.smith@company.com'
#software_id        = 21000240240 #Get-FSSoftware
#billing_cycle      = 'annual'
# item_cost_details  = @($icd)
# item_cost_details  = @([pscustomobject]@{item_name='Installation'; pricing_model='per_unit'; cost=200; count=1})
 attachments        = 'C:\Scripts\Contract.txt'
 associated_asset_ids = @(1)

}

New-FreshserviceContract @contractParams -Verbose

2. Execute command and API produces: 

| {"description":"Validation failed","errors":[{"field":"auto_renew","message":"It should be of type | Boolean","code":"datatype_mismatch"},{"field":"notify_expiry","message":"It should be of type | Boolean","code":"datatype_mismatch"},{"field":"notify_to","message":"It should be in the 'valid email | address' format","code":"invalid_value","nested_field":"notify_to.[0]"}]}


If the attachment is removed, the code executes successfully.

## Context
<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
Cannot create Freshservice Contract with attachments.
## Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->
* Module version used: 0.1.4
* Operating System and PowerShell version: Windows 11 with Powershell 7.3.4