How to add incident comments from different users via REST api

Halyna
Giga Contributor

Hi, all
I'm trying to add multiple comments one by one using Table API: 

/api/now/table/incident/{incident_id}

body: {"comments":"single comment"}

The problem is that all the comments are added for admin user. If there is a way to specify a user for incident comment?

Thank you, regards, Halyna

1 ACCEPTED SOLUTION

Sebastiaan de V
Kilo Guru

Comments are added as the user that connects via the REST API. I you use "admin" for each REST API call, it will always be "admin". If possible you should use the correct user. As an alternative, you can add the user to the comment text, but it will still show "admin" as the user who added the comment.

Since you are using the direct table API, there is no intermediate transformation step where you would be able to handle this.

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Halyna,

I don't think so that is possible. But that needs to be explored.

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

Thank you for replying

So it's possible to save comment only for user witch is authorized in a system?

Regards, Halyna

ryosuke hayashi
Tera Contributor

Hi Halyna,

 

When you call table API, you need to let specific user authorized.
Comments are added for the user.

If you want to add comments for user "rest.test", you can write as follows.

--------------------------------------------
# sample in Python from REST API Reference

username = "rest.test"
password = "pass"

rest_endpoint = "[yourinstance]/api/now/table/incident/[sys_id]";
headers = {"Content-Type":"application/xml","Accept":"application/xml"}

# PUT
r = requests.put(
rest_endpoint,
auth=(username, password), # let username authorized
headers=headers,
data="<request><entry><comments>Single comment</comments></entry></request>"
)

print(r.status_code)
--------------------------------------------

"auth=(username, password)" adds username and password to http header.

The result is as follows.

find_real_file.png

Sebastiaan de V
Kilo Guru

Comments are added as the user that connects via the REST API. I you use "admin" for each REST API call, it will always be "admin". If possible you should use the correct user. As an alternative, you can add the user to the comment text, but it will still show "admin" as the user who added the comment.

Since you are using the direct table API, there is no intermediate transformation step where you would be able to handle this.