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

Jeff Currier
ServiceNow Employee
ServiceNow Employee

While I have not seen an example of this, it should be possible as you can use scripts with VA.

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

Hi Mark, 

Do we have option to show response in virtual agent through external api without using any script. 

Regards,

Neha Gupta

I think what you are looking for is 'Actions'
I have set these up with spokes for both internal and external services.