The CreatorCon Call for Content is officially open! Get started here.

Updating cost_center using REST API

kshitishchodank
Mega Contributor

Hi Guys,

I am trying to update the cost center, location of a user in ServiceNow(Geneva) using REST api. I am using

https://devxxxxx.service-now.com/api/now/v1/import/(table) with POST type.

My input is

{

      "cost_center":" ",

      "user_sys_id":"<user-id>"

}

This gives me "No field values changed" message. When I change the type to patch with the following url

https://devxxxxx.service-now.com/api/now/v1/import/(table)/<user-id>

I get "Method not Supported" message.I even tried with X-http-method-override but it wasn't helpful. I went through this doc but was not able to understand what I was doing wrong. Please advice.

1 ACCEPTED SOLUTION

tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi Kshitiah,



As you are on Geneva and using an import set table this is the documentation URL that refers:


Import Set API



The import set table needs to be specified


Only POST and GET are supported methods - PUT and PATCH are not possible.


However a POST to import set table imp_user will update an existing user record based on user_id.



Any questions arising add them to this thread 🙂



If the reply was informational, please like, mark as helpful or mark as correct!




Also there is a sample CURL request mentioned:


curl "https://instance.service-now.com/api/now/import/imp_user" \
--request POST \
--header "Accept:application/json"\
--header "Content-Type:application/json" \
--data "{'first_name':'John','last_name':'Public','user_id':'john.public','email':'john.public@company.com'}" \
--user 'admin':'admin'





View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Kshitish,



Following links should be helpful to you:


Updating record requires sys_id but I think you are not sending that in your URL



http://wiki.servicenow.com/index.php?title=Getting_Started_with_REST#gsc.tab=0



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks bawiskar for the reply. I am using <user-id> in the url but it has not solved the problem.I had checked the link that you have given but the problem remains.


Hi Kshitish,



So what value you are sending in the <user-id> in the URL? Is it the sys_id of the record you want to update.


also are you giving correct tablename in the URL



I was able to update incident record using PATCH method using following URL


https://dev17945.service-now.com/api/now/table/incident/2db06b194f4e1a00fc11fa218110c7da


and following request body


{"description":"test","short_description":"test1"}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Harsh Vardhan
Giga Patron

Hi Kshitish,



if you are using post api



then pass the user sys_id in body



Note: if you want to post something in reference field then you must need to pass sys_id.



api.png