Post comments to requested item using curl

knchaitanya9
Tera Contributor

Hello

I would like to post comments to existing Requested Items (RITM), I'm using the curl script below to post comments on a particular RITM and it's not working and throwing errors, can anyone tell me what was wrong with my curl command


CURL COMMAND:
curl -X POST "https://<INSTANCE URL>/api/now/table/sc_req_item" -H "Authorization: Basic <TOKEN>" -H 'Content-Type: application/json' -d '{\"comments\":\"STATUS IS COMPLETED, PLEASE VALIDATE\",\"requested_item\":\"RITM789124\"}'


ERROR:

 

{"error":{"message":"Exception while reading request","detail":"The payload is not valid JSON."},"status":"failure"}

1 ACCEPTED SOLUTION

@knchaitanya9  This is an example of PUT API to update comment using curl, make changes based on your need. 

 

 

 

curl "https://<YourInstanceID>.service-now.com/api/now/table/sc_req_item/0495fdf11bfbb9507514415dee4bcb5c" \
--request PUT \
--header "Accept:application/json" \
--header "Content-Type:application/json" \
--data "{\"comments\":\"Adding Test Comment\"}" \
--user 'USERID':'YourPassword'

 

 

 

Hope it will help you. 

 

Thanks,

Harsh

View solution in original post

5 REPLIES 5

Harsh Vardhan
Giga Patron

@knchaitanya9  I think it should be PUT or PATCH method, POST used to create record .

Try with PUT or PATCH to update comment on ritm record. 

@knchaitanya9  This is an example of PUT API to update comment using curl, make changes based on your need. 

 

 

 

curl "https://<YourInstanceID>.service-now.com/api/now/table/sc_req_item/0495fdf11bfbb9507514415dee4bcb5c" \
--request PUT \
--header "Accept:application/json" \
--header "Content-Type:application/json" \
--data "{\"comments\":\"Adding Test Comment\"}" \
--user 'USERID':'YourPassword'

 

 

 

Hope it will help you. 

 

Thanks,

Harsh

Thanks for the quick response and @Harsh Vardhan 
I see that after sc_req_item you have added an id, is that the sys_id of a RITM?

if yes, do you have a sample curl handy to get the sys_id of an RITM? 

You can use REST API explorer to test it and you will get sample example also.  

You can first get the RITM id using GET method, you will get sys_id of the record in payload then you can use PUT method to update the comments using sys_id. 

 

Hope it will help you.