Error trying to add. comment to an incident from REST API

antoniosignore
Giga Contributor

Hello, I need some help. I'm trying to add a comment to an incident previously create but I get an error. Here is the relevant code snippet:

 

public void addComment(String ticketId, String comment) throws Exception {
String url = this.url + "/api/now/table/incident/" + ticketId;

log.info("URL:{}", url);

String comments = objectMapper.writeValueAsString(new ServiceNowCommentPayload(comment));

Request request = new Request.Builder()
.url(url)
.put(RequestBody.create(comments, MediaType.parse("application/json")))
.addHeader("Content-Type", "application/json")
.build();


The error I receive is:

java.lang.RuntimeException: Failed to add comment: {"error":{"message":"No Record found","detail":"Record doesn't exist or ACL restricts the record retrieval"},"status":"failure"}

Can somebody help, please?





I have also tried to add the authorization header with no luck either

Request request = new Request.Builder()
.url(url)
.put(RequestBody.create(comments, MediaType.parse("application/json")))
.addHeader("Content-Type", "application/json")
.header("Authorization", Credentials.basic(username, password))
.build();


 

2 REPLIES 2

Prasanth Meda
Tera Contributor

Hello ,

 

Please validate if the User you are using to update the data have the necessary roles for Incident and also validate the Incident exists on the system.

 

Thans for the prompt response. The problem what that I was supposed to pass the sys_id and not the incident_it. My bad.