Am I able to use CURL command on a developer instance?

chooi
Tera Expert

Am I suppose to be able to use CURL command on a developer instance?

I tried the following sample REST API call (replacing instance and username and password with admin and password for my instance).

curl "https://instance.service-now.com/api/now/table/problem?sysparm_limit=1" \
--request GET \
--header "Accept:application/json" \
--user 'username':'password'

I got back the following error.

{"error":{"detail":"Required to provide Auth information","message":"User Not Au

thenticated"},"status":"failure"}curl: (6) Could not resolve host: \

curl: (6) Could not resolve host: \

curl: (6) Could not resolve host: \

2 REPLIES 2

Chuck Tomasi
Tera Patron

Hi Chooi,



Yes, you can use CURL on a developer instance. Use the REST API Explorer to help construct your command. In that screen, you will find a link to the CURL command. Click it and you'll get your code snippet.



find_real_file.png


find_real_file.png



Getting Started with REST - ServiceNow Wiki


REST API Explorer - ServiceNow Wiki


REST API  


J39
Mega Expert

Hi Chooi,


I encountered this same issue.   The curl code snippet provided by ServiceNow's REST API Explorer doesn't work (at least it didn't for me).



When using the REST API Explorer (in Geneva), it works fine with the credential I configured.   The credential I created was granted only the ITIL and snc_read_only roles, since I only needed it to do a GET.   When attempting to use the curl snippet provided by the API Explorer, however, I would constantly get the following error:


{"error":{"detail":"Required to provide Auth information","message":"User Not Authenticated"},"status":"failure"}


It wasn't until I base64 encoded the username:password, and defined the Authorization header that I was able to get a successful curl result from ServiceNow using curl.



So the code snippet is a good start but is non-functioning until you base64 encode the username:password pair.



Here's an example curl command that worked for me where "bXl1c2VybmFtZTpteXBhc3N3b3Jk" is the base64-encoded string "myusername:mypassword" (without quotes).   You can use postman to encode your username:password pair.


curl "https://myinstance.service-now.com/api/now/table/incident?sysparm_limit=1&sysparm_display_value=true&sysparm_fields=number%2Cshort_description%2Ccaller_id&sysparm_view=default" --request GET --header "Accept:application/json" --header "Authorization:basic bXl1c2VybmFtZTpteXBhc3N3b3Jk'


I know this is pretty late, but I hope this helps,


-Joe