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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-05-2022 11:22 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-05-2022 11:30 PM
Is there any specific reason for not storing these details in the REST Message, and Auth Profile tables?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-05-2022 11:32 PM
for security key and values should not be open for everyone to check
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-06-2022 01:45 AM
i created sys_properties for 3 key values key1, key2, key3.
How can we call this sys_property in rest message
i am using this below code but it is not working throwing 400 error, could you please guide
try{
var r = new sn_ws.RESTMessageV2('Name of rest message', 'Default GET');
var API0 = gs.getProperty('KEY1');
var API1 = gs.getProperty('kEY2');
var API2 = gs.getProperty('KEY3');
var response = r.execute();
var httpStatus = response.getStatusCode();
var responseBody = response.getBody();
}
catch(ex)
{
var message = ex.message;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-06-2022 04:29 AM
To set endpoint :
var sm = new sn_ws.RESTMessageV2();
sm.setEndpoint("http://web.service.endpoint");
To set method :
var sm = new sn_ws.RESTMessageV2();
sm.setHttpMethod("post");
To set authentication :
var sm = new sn_ws.RESTMessageV2("<REST_message_record>","get"); //Might throw exception if message doesn't exist or not visible due to scope.
sm.setBasicAuth("username","password");
Your code will look something similar with:
var API0 = gs.getProperty('KEY1'); // holds the endpoint which should already be part of the rest message
var API1 = gs.getProperty('kEY2'); // holds the httpmethod which should already be part of the rest message
var API2 = gs.getProperty('KEY3'); //holds the password of the profile
try{
var r = new sn_ws.RESTMessageV2('Name of rest message', 'Default GET');
r.setEndpoint(API0);
r.setHttpMethod(API1);
r.setBasicAuth('username',API2);
var response = r.execute();
var httpStatus = response.getStatusCode();
var responseBody = response.getBody();
}
catch(ex)
{
var message = ex.message;
}
I would advise you to use the REST messages settings and also check the variable substitutions :
Here is more of the REST API scoped documentation :
You could either use the messages inside the scheduled scripts or use Async Business Rules which helps a lot with the trigger conditions and does not put any pressure on the performance of the system.
If you stay with the scheduled scripts you could also try to add a function on it,this way you can use some conditions like.. if the company is X then use this API.