How to store Rest API Endpoint url , method and Authentication Key and values in system property ? how can we call this property in scheduled jobs/

navya4
Tera Contributor

How to store  Rest API Endpoint url , method and Authentication Key and values in system property ? how can we call this property in scheduled jobs.

can you please share examples. Thanks in advance.

8 REPLIES 8

navya4
Tera Contributor

var Endpoint_url = gs.getProperty('EamLinuxUrl');
var API0 = gs.getProperty('X-API-KEY');
var API1 = gs.getProperty('X_API_USER');
var API2 = gs.getProperty('X_API_USER_KEY');

try {


var r = new sn_ws.RESTMessageV2();

r.setEndpoint('Endpoint_url')
r.setHttpMethod('GET');
r.BasicAuth('API_KEY1', API0);
r.BasicAuth('API_KEY2', API1);
r.BasicAuth('API_KEY3', API2);

var response = r.execute();
var httpStatus = response.getStatusCode();
var responseBody = response.getBody();

}

catch(ex)

{

var message = ex.message;

}

 

i used the same script above you mentioned but it is not working

Ed13
Tera Contributor

What error do you receive ? Can you check the logs and send them back ? 

Check    System Logs -> Outbound HTTP Requests 

You should be able to see the results there 

navya4
Tera Contributor

var Endpoint = gs.getProperty('Url');
var API0 = gs.getProperty('KEY0');
var API1 = gs.getProperty('key1');
var API2= gs.getProperty('key2');

try {
var r = new sn_ws.RESTMessageV2();
r.setEndpoint( Endpoint);
r.setHttpMethod('GET');
r.setRequestHeader('API-KEY',API0);
r.setRequestHeader('API_USER', API1);
r.setRequestHeader('API_USER_KEY' , API2);


var response = r.execute();
var httpStatus = response.getStatusCode();
var responseBody = response.getBody();

 

The above code is now working 

Thank all for your inputs.

Ed13
Tera Contributor

Great to hear that, feel free to mark our answers as helpful if they were indeed helpful. 

 

Thanks.

Ed`N