servicenow-powershell icon indicating copy to clipboard operation
servicenow-powershell copied to clipboard

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

Open JasonDTX opened this issue 3 years ago • 1 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:

https://github.com/Snow-Shell/servicenow-powershell/blob/19e38411ee978aff2581eb06f5cdb2827042a289/ServiceNow/Public/Add-ServiceNowAttachment.ps1#L173

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

JasonDTX avatar Oct 14 '22 20:10 JasonDTX

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

gdbarron avatar Oct 17 '22 14:10 gdbarron

Looks good, posting in 208, closing 207.

JasonDTX avatar Oct 17 '22 22:10 JasonDTX