How to find the encoded value associated with a tag (sys_tags)?

Jason57
Kilo Explorer

Hello, I'm interfacing with our servicenow app via the REST API.  I have associated a specific tag 'R18_2018' to a couple of incidents.  I know that I can use this GET request to find the incidents:

https://{{Company Service-Now URL}}/api/now/table/incident?sysparm_query=sys_tags.0d8c13aedba5ab801b05894d0b96197e=0d8c13aedba5ab801b05894d0b96197e

 ... works great!

My question is: 

H̶o̶w̶ ̶c̶a̶n̶ ̶I̶ ̶f̶i̶n̶d̶ ̶t̶h̶e̶ ̶v̶a̶l̶u̶e̶ ̶o̶f̶ ̶'̶0̶d̶8̶c̶1̶3̶a̶e̶d̶b̶a̶5̶a̶b̶8̶0̶1̶b̶0̶5̶8̶9̶4̶d̶0̶b̶9̶6̶1̶9̶7̶e̶'̶ ̶w̶h̶e̶n̶ ̶I̶ ̶k̶n̶o̶w̶ ̶i̶t̶s̶ ̶s̶t̶r̶i̶n̶g̶ ̶e̶q̶u̶i̶v̶a̶l̶e̶n̶t̶ ̶i̶s̶ ̶'̶R̶1̶8̶_̶2̶0̶1̶8̶'̶?̶ ̶ ̶

W̶h̶a̶t̶ ̶i̶f̶ ̶t̶h̶e̶ ̶n̶e̶x̶t̶ ̶t̶a̶g̶ ̶I̶ ̶w̶a̶n̶t̶ ̶t̶o̶ ̶u̶s̶e̶ ̶i̶s̶ ̶'̶X̶Y̶Z̶_̶1̶2̶3̶'̶,̶ ̶w̶h̶a̶t̶ ̶w̶i̶l̶l̶ ̶t̶h̶a̶t̶ ̶e̶n̶c̶o̶d̶e̶d̶/̶h̶a̶s̶h̶ ̶v̶a̶l̶u̶e̶ ̶b̶e̶?̶ ̶ ̶

I̶'̶m̶ ̶s̶u̶r̶e̶ ̶t̶h̶e̶r̶e̶ ̶i̶s̶ ̶a̶n̶ ̶A̶P̶I̶ ̶c̶a̶l̶l̶ ̶t̶h̶a̶t̶ ̶w̶i̶l̶l̶ ̶d̶o̶ ̶t̶h̶i̶s̶,̶ ̶b̶u̶t̶ ̶I̶'̶m̶ ̶s̶u̶p̶e̶r̶ ̶n̶e̶w̶ ̶t̶o̶ ̶t̶h̶i̶s̶ ̶p̶l̶a̶t̶f̶o̶r̶m̶.̶

 

11/13/2018 Update...

I have blindly stumbled upon this AJAX query call that will return me an XML object that contains the sys_id of the tag.  So using this combination:

[HTTPGET]

https://{{Your ServiceNow Domain}}/xmlhttp.do?sysparm_processor=Reference&sysparm_name=label_entry.label&sysparm_chars=R18_2018

 

[Request Headers] 

X-UserToken: {{???}}

Cookie: {{???}}

[Request Paramaters]

sysparm_processor:Reference
sysparm_name:label_entry.label
sysparm_chars:R18_2018

 

Returns me this XML object:

<?xml version="1.0" encoding="UTF-8"?>
<xml query_type="STARTSWITH" row_count="1" sysparm_chars="R18_2018" sysparm_max="15" sysparm_name="label_entry.label" sysparm_processor="Reference">
    <item label="R18_2018" name="0d8c13aedba5ab801b05894d0b96197e" sys_class_name="Tag" sysparm_name="label_entry.label"/>
</xml>

 

Super!  Now I can find the sys_id for my tag 'R18_2018'.

But.....

How do you find/generate the Request Header keys 'X-UserToken' and 'Cookie'?

I put ??? for these keys above because I can only get these from the Network Tab in Chrome Dev tools for a request called 'xmlhttp.do' when I'm on the internal ServiceNow site.

 

find_real_file.png

 

11/14/2018 Update...

I discovered why the sys_tags weren't showing up in my query results.

The user adding the tags (UI_user) to the Incident in the Service-Now UI WAS NOT granting access to the user who is making the REST API calls (REST_user).  Once UI_user granted REST_user access rights, then the sys_tags were included in the results of my query.

 

But.... How do you query JUST sys_tags via REST API?

 

 

 

Jason

2 REPLIES 2

Ct111
Giga Sage

Hi,

 

Follow the below link

https://community.servicenow.com/community?id=community_question&sys_id=65770f69db1cdbc01dcaf3231f961997

 

Mark my ANSWER as CORRECT and HELPFUL if it helped you

Thank you for the reponse @creativethinker, but this is finding the tags sys_id via the ServiceNow UI.  I wanted to know if there is a way to find the tag's sys_id via REST API.

 

Jason