Unable to post .csv to import set (HTTP Status 400 – Attachment could not be successfully extracted)

Jacob28
Kilo Explorer

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? 

find_real_file.png

 


$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
3 REPLIES 3

Akshata jamdar
Mega Guru

Hi Jacob,

 

You can refer below link which is the community link similar to you problem,

https://community.servicenow.com/community?id=community_question&sys_id=27965200db100c502be0a851ca96...

 

Hope this will help you.

 

Please mark the answer as correct and helpful if it will help to resolve your issue.

 

Regards,

Akshata.

Harshal Gawali
Giga Guru

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

cuong nguyen
Giga Contributor

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.