Is it possible to call external API with Virtual Agent

Ivan Delchev
Giga Contributor

Hello,

Is it possible to use, for example XMLHttpRequest API and GET, to retrieve information from external API and show it as VA response.

Thank you!

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Sure this is possible.

I did a real quick test, 10 minutes, gave me already Incident details from an other instance.

find_real_file.png

Just added a Script Action Utility with below code. Most of it just generated thru the API Explorer within ServiceNow.

(function execute() {
   
    var request = new sn_ws.RESTMessageV2();
    request.setEndpoint('https://some-instance.service-now.com/api/now/table/incident/fb1fb9e44f67f300e7fe0ab18110c74f');
    request.setHttpMethod('GET');

    //Eg. UserName="admin", Password="admin" for this code sample.
    var user = 'user';
    var password = 'password';

    request.setBasicAuth(user,password);
    request.setRequestHeader("Accept", "application/json");

    var response = request.execute();
    
    vaVars.api = response.getBody();
    
})()

In the Topic, on a Text Utility just added:

(function execute() {

    return vaVars.api;

})()

So yes, very well possible.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

7 REPLIES 7

Ivan Delchev
Giga Contributor

Thank you, Mark, I tested my solution and it was working just fine, thanks to your clarification.

 

Regards,

Ivan

Eli Guttman
Tera Guru

Hi,

For cases that API call take longer that 10 seconds for example - is there a way to "wait" for the response and then continue to the next action?

Hi there,

See my articles list. 2 weeks ago I published an article on a Topic Block "Wait N Seconds". There's also a Share download.
Community article list

It might not be best practice / recommended by ServiceNow, though there's no suitable other option (and something similar is actually being used in one of the out-of-the-box template topics).

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn