Snow-Shell/servicenow-powershell

Add-ServiceNowAttachment Error - "Item has already been added. Key in dictionary: 'Content-Type' Key being added: 'Content-Type'"

Closed this issue · 2 comments

Hiya, Not sure if Add-ServiceNowAttachment is supposed to do multiple files.

If it is, I think the Content-Type header might be duplicated in the ForEach loop here:

$invokeRestMethodSplat.Headers += @{'Content-Type' = $ContentType }

I think with multi-file you'll want the type to be multipart or octet-stream. Haven't tried fixing it yet, currently just working around by sending one file at a time.

Environment

Operating System: Windows Powershell
ServiceNow module version: 3.4.1
PowerShell version:  5.1

Steps to reproduce

Use a splat containing two filepath

$addServiceNowAttachmentSplat = @{
    ID          = $Ticket.Number
    Table       = 'incident'
    File        = $LogFilePath, $OutputFilePath
}

Add-ServiceNowAttachment @addServiceNowAttachmentSplat

Expected behavior

Multiple files upload to service now incident

Actual behavior

First item is uploaded, next files generate error
"Item has already been added. Key in dictionary: 'Content-Type' Key being added: 'Content-Type'"

Screenshots

Web capture_14-10-2022_15813_github com

Thanks for reporting this @JasonDTX. Would you mind testing the fix #208?

Looks good, posting in 208, closing 207.