You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
I like ScriptRunner, however I have been stuck for hours with one specific REST https call(GET) to retrieve an XML document(XML is hardcoded in endpoint).
This is my XML response in Postman:
<?xml version="1.0" encoding="UTF-8"?>
<logged_in_reps xmlns="http://www.bomgar.com/namespaces/API/command">
<rep id="2">
<type>Normal</type>
<display_name>mbluteau</display_name> <public_display_name>mbluteau</public_display_name> <private_display_name>mbluteau</private_display_name>
<direct_link> <a href="https://rslab01.beyondtrust.skytapdns.com/api/start_session?id=2&name=mbluteau">mbluteau</a> </direct_link>
<showing_on_rep_list>1</showing_on_rep_list>
<routing_idle>0</routing_idle>
<routing_busy>0</routing_busy>
<routing_enabled>1</routing_enabled>
<routing_available>1</routing_available>
<support_license>full</support_license>
<presentation_count>0</presentation_count>
<logged_in_since ts="1611085202">01/19/2021 07:40:02 PM</logged_in_since> <support_session_count>0</support_session_count>
</rep>
</logged_in_reps>
---------------
I tried this and RESTClient and bunch of other examples:
String path_key = "/api/command"
def headers= ["Content-Type": "TEXT","Accept":"text/xml","requestContentType":"XML","Authorization": "Bearer "+cfield_Access_Token_value]
def http = new HTTPBuilder( url )
http.get( path: path_key, headers:headers,query : [action:'get_logged_in_reps'] ) { resp, xml ->
UserMessageUtil.success('Status = '+resp.status)
UserMessageUtil.success('xml = '+resp.data) //THIS GIVES NULL
UserMessageUtil.success("It is aaa ${xml} in London.") //THIS GIVES Normalmbluteaumbluteaumbluteaumbluteau10011full001/19/2021 07:40:02 PM0
UserMessageUtil.success("It is <bal-bla/> currently ${xml.logged_in_reps.rep.direct_link.@value.text()} in London.")
UserMessageUtil.success("The temperature is ${xml.logged_in_reps.rep.display_name.@value.text()} degrees Kelvin")
}
However, if I create an XML text string in a var, I can navigate just fine:
def reps = new XmlParser().parseText('<?xml version="1.0" encoding="UTF-8"?><logged_in_reps xmlns="http://www.bomgar.com/namespaces/API/command"><rep id="1"><type>Normal</type><direct_link>https://beyondtrust.com/docs</direct_link></rep><rep id="2"><type>Normal</type><direct_link>https://beyondtrust.com</direct_link></rep></logged_in_reps>')
reps.rep.each{
UserMessageUtil.success('Rep Attribute ID :: '+it.attribute("id")) //GIVES 2
UserMessageUtil.success('Rep Attribute Direct Link :: '+it.direct_link.text()) //GIVES https://www.beyondtrust.com
So I feel I am just missing the step to properly retrieve the XML response without losing all the < and /> tags etc.
Any assistance would be appreciated
Got it partially figured out with something like this:
String url = "https://test11.beyondtrust.mylab.com";
String path_key = "/api/command"
def headers= ["Content-Type": "TEXT","Accept":"text/xml","requestContentType":"XML","Authorization": "Bearer "+cfield_Access_Token_value]
def http = new HTTPBuilder( url )
http.get( path: path_key, headers:headers,query : [action:'get_logged_in_reps'] ) { resp, xml ->
xml.rep.each { UserMessageUtil.success("Rep: ${it.display_name} ID : ${it.@name}" ) }
xml.rep.each { UserMessageUtil.success('Session URL :: <a href="'+url+'/api/start_session?id=2&name='+it.display_name+'" target="_blank">'+'Start Session'+'</a>') }
}
Hello Community! My name is Brittany Joiner and I am a Trello enthusiast and Atlassian Community Leader. In this video, I'll share my favorite Trello templates. Templates mentioned in ...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.