I'm trying to use ServiceNow's REST API to add an attachment to a record, but I want to upload the attachment from memory as bytes/base64/etc., without a physical saved file path.
Currently working when providing a file path
$splat = @{
URI = "https://instanceName.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id=$($SysId)&file_name=$($FileName)"
Method = "POST"
Headers = @{
"Authorization = "Basic $creds"
"Content-Type" = "text/plain"
}
InFile = "C:\Users\Me\Documents\test.txt"
}
Invoke-RestMethod @params
Desired
In my mind it would be something like this,
$fileContent = "This is the file content to upload"
$file = [System.Text.Encoding]::ASCII.GetBytes($fileContent)
$splat = @{
URI = "https://instanceName.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id=$($SysId)&file_name=$($FileName)"
Method = "POST"
Headers = @{
"Authorization = "Basic $creds"
"Content-Type" = "text/plain"
}
InFile = $file
}
Invoke-RestMethod @params
I've found a few questions that I believe are similar, but I can't understand the language used, and how to convert it to something I do know (PowerShell/Python) :D
Upload Attachment to ServiceNow using SOAP and Base64 via BluePrism
Also
In the docuemntation, there are 2 different endpoints
- Attachment - POST /now/attachment/file
- Attachment - POST /now/attachment/upload
The "upload" endpoint description reads
Uploads a multipart file attachment.
Does it matter which endpoint to use? What is a multipart file?