Displaying REST API message response in html

bretelson_patri
Kilo Contributor

I am new to developing custom widgets and have found some sample code to capture the REST API message response into a variable (responseBody).  See the below server script:

(function() {   /* populate the 'data' object */   /* e.g., data.table = $sp.getValue('table'); */ try {   var r = new sn_ws.RESTMessageV2('Yahoo Finance', 'get');   

var response = r.execute(); 

var responseBody = response.getBody(); 

var httpStatus = response.getStatusCode(); }

catch(ex) {  var message = ex.getMessage(); }  })();

What I would like to do is display the contents of the variable "responseBody" in a page (sc_home) within the service portal.  Has anyone done this before?

 

1 ACCEPTED SOLUTION

Bhagyashree8
Kilo Guru

Hi,

 

Simply put that variable as property of Data object, then you can use it in HTML and client script part of the widget.

 

Server script. After below line

var responseBody = response.getBody(); 

data.responseBody  = responseBody 

 

now on HTML

<pre>{{data.responseBody | json}}</pre>

 

Hope this helps

 

Please mark Correct/Helpful if it helps.

View solution in original post

2 REPLIES 2

Bhagyashree8
Kilo Guru

Hi,

 

Simply put that variable as property of Data object, then you can use it in HTML and client script part of the widget.

 

Server script. After below line

var responseBody = response.getBody(); 

data.responseBody  = responseBody 

 

now on HTML

<pre>{{data.responseBody | json}}</pre>

 

Hope this helps

 

Please mark Correct/Helpful if it helps.

That is to easy.  I will give that a try.  Thanks for the quick response!