Snow-Shell / servicenow-powershell

PowerShell module to automate ServiceNow service and asset management. This module can be used standalone, with Azure Automation, or Docker.
Apache License 2.0
359 stars 170 forks source link

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

Closed JasonDTX closed 1 year ago

JasonDTX commented 1 year ago

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

gdbarron commented 1 year ago

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

JasonDTX commented 1 year ago

Looks good, posting in 208, closing 207.