Uploading files is fairly easy in SN but what if you need to upload a lot of files?
There are some solutions using the AttachmentCreator service which work great but I wondered if it was possible to do it without any programming at all. So I racked my brain then I remembered a tool: cURL.
cURL is a tool used for making all sorts of web related requests. The best part about is it a command line tool so if you are in need of automating web requests this is the tool to use. Theres several versions for every OS out there and its fairly well documented.
So lets take a look at how to use it…
If you haven’t already grab a copy of cURL from http://curl.haxx.se/
Logging in is a two step process, first we need to initialize our connection and set up a cookie:
curl --cookie-jar cjar -k -o output1.log --location "https://INSTANCE.service-now.com"
The –cookie-jar cjar parameter creates a cookie called cjar so that we can save our information
-k tells cURL to just accept any certificates that the site offers, this gets us by HTTPS if that’s enabled on your instance.
-o output1.log tells curl to output to a log file instead of the screen
–location tells curl to follow any redirects
Finally we put our instance URL.
Once you run this command and you have a cookie jar created you can attempt to log in.
curl --cookie cjar --cookie-jar cjar -k -o output2.log --data user_name=USERNAME --data user_password=PASSWORD --data ni.nolog.user_password=true --data ni.noecho.user_name=true --data ni.noecho.user_password=true --data remember_me=true --data screensize=1920x1080 --data sys_action=sysverb_login --location "https://INSTANCE.service-now.com/login.do"
This command reuses some of the same parameters but also specifies all the data used to log in. Just replace USERNAME, PASSWORD and INSTANCE and you should get a positive response back.
The way to check that everything is working properly is in the output files. If they return the code that would be the homepage you are golden.
Finally once you have your cookie and are logged in you can start uploading files.
curl --cookie cjar --cookie-jar cjar -k -o output3.log --location -F attachFileemail@example.com "https://INSTANCE.service-now.com/sys_upload.do"
In this case I am uploading a PNG file called test that’s located in the same directory as cURL. If this is successful you will now be able to see the newly uploaded file on your instance.
Because this is an image file it will be available in the Image file browser but also at https://INSTANCE.service-now.com/scs/test.png or https://INSTANCE.service-now.com/test.pngx
Note: Theres also no need to keep logging in, once you are in you can continue to upload files.
If you’ve got tons of files no problem, just couple this technique with the `for` command (Windows Systems) and you can loop through all the files in a directory.
Heres a quick tutorial on that command: http://www.suite101.com/content/batch-file-programming-for-command-a37305