Create Incident with new tag or tags using the API

cristianlie
Tera Contributor

Hi community,

 

When I create a task (incident) using the API and include values in the `sys_tags` field, the incident is created successfully, but the tags are not created or linked to the incident. I've read some posts suggesting that this might be possible by first creating new tags using a POST request to `https://xxxxxx.service-now.com/api/now/table/label` and then linking them using a POST request to `https://xxxxxx.service-now.com/api/now/table/label_entry`. However, even after trying this in Postman, I still don't see the tags associated with the incident when I retrieve it. Where can I find more documentation on this? I work with very large clients who have thousands of tags.

 

 

8 REPLIES 8

Kieran Anson
Kilo Patron

Can you share the post entry you're doing to label_entry?

 

Disclaimer: I've never done tagging via an API. I'm not a massive fan of tags 😄 

cristianlie
Tera Contributor

Hi Kieran,

https://xxxxx.service-now.com/api/now/table/label_entry

 

{
  "label": "1614a45e3b739a108a6ed29aa4e45af7", // sys_id of the label
  "table": "incident",
  "table_key": "81a8fcd6ebbf9a101a4df4f2bad0cde6" // sys_id of the incident
}

 

 

 

 

 

cristianlie
Tera Contributor

Hi Kieran

 

POST -->https://xxxx.service-now.com/api/now/table/label_entry

 

{
  "label": "1614a45e3b739a108a6ed29aa4e45af7", // sys_id of the label
  "table": "incident",
  "table_key": "81a8fcd6ebbf9a101a4df4f2bad0cde6" // sys_id of the incident
}

 

Thank you for the fastest respond.

Looks like writing to table and table key is the issue. I would look at creating a scripted REST API, and use the undocumented GlideLabelUtil to add a label. This Glide API will create a label_entry record with all of the correct field values. You can see its use in the script include 'LabelsAJAX'