Unable to post .csv to import set (HTTP Status 400 – Attachment could not be successfully extracted)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2020 04:31 PM
When attempting to POST a .csv into servicenow from a powershell script I keep getting a HTTP Status 400 – Attachment could not be successfully extracted error. I've verified the import table exists within servicenow and the user has the import_set_loader role. Is there something that's missing?
$user = "<user>"
$pass = "<pass>"
# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
$headers.Add('Content-Type','application/json')
# Specify endpoint uri
$uri = "https://<instance>.service-now.com/sys_import.do?sysparm_import_set_tablename=u_imp_attached_monitors&sysparm_transform_after_load=true"
# Specify HTTP method (POST, PATCH, PUT)
$method = "POST"
#-Infile Method
$fileToAttach = "C:\Users\31508\Documents\FoundMonitors.csv"
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
$response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri -InFile $fileToAttach
# Print response
$response
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2020 10:15 PM
Hi Jacob,
You can refer below link which is the community link similar to you problem,
Hope this will help you.
Please mark the answer as correct and helpful if it will help to resolve your issue.
Regards,
Akshata.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2020 01:18 AM
Hi Jacob,
kindly check below link, It will help you attach csv file to servicenow incident using powershell.
How to attach CSV file to Service Now incident via REST API using PowerShell?
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2021 01:37 PM
I got exactly the same error when trying to post a CSV file to servicenow's sys_import.do. In my case, the error is with my curl command.
Here's the correct command that works for me:
curl -v "https://{my instance}.service-now.com/sys_import.do?sysparm_import_set_tablename={my staging table name}&sysparm_transform_after_load=true" --user 'user':'password' --form "f=@test.csv"
Changing to use "--form "f=.." made it work for me.
Hope that help.