Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Integration/OutboundRestDynamicEndpoint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
This is a server-side Script Include that contains the core logic. It reads the endpoint configurations from a System Property, parses the JSON, and returns the appropriate URL based on the current instance's name.

System Property: x_my_scope.api.endpoints
This property stores a JSON object containing the endpoint URLs for each environment. It must be created and populated in each instance that uses the utility.

Sample JSON object:
{
"dev": "https://dev-instance.example.com/api",
"test": "https://test-instance.example.com/api",
"prod": "https://prod-instance.example.com/api"
}

Usage:
var endpointConfig = new EndpointConfig();
var endpointUrl = endpointConfig.getEndpoint();
if (endpointUrl)
{
gs.info("Endpoint URL: " + endpointUrl);
//Use the endpointUrl in your REST call
var request = new sn_ws.RESTMessageV2();
request.setEndpoint(endpointUrl);
// ... rest of your integration logic
} else {
gs.error("Failed to retrieve endpoint URL.");
}

54 changes: 54 additions & 0 deletions Integration/OutboundRestDynamicEndpoint/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

//Create a sample system Property called x_my_scope.api.endpoints having below object as example. make sure your company instance includes those key such as dev,prod,test or modify it with your instance name

// {
// "dev": "https://dev-instance.example.com/api",
// "test": "https://test-instance.example.com/api",
// "prod": "https://prod-instance.example.com/api"
// }

var EndpointConfig = Class.create();
EndpointConfig.prototype = {
initialize: function() {
// No hardcoded object here. It will be fetched from the System Property.
},

getEndpoint: function() {
var propertyName = 'x_my_scope.api.endpoints';
var endpointObjectStr = gs.getProperty(propertyName);
if (gs.nil(endpointObjectStr)) {
gs.error("EndpointConfig: System property '" + propertyName + "' not found or is empty.");
return null;
}

try {
var endpoints = JSON.parse(endpointObjectStr);
var instanceName = gs.getProperty('instance_name');
var environmentKey;

if (instanceName.includes('dev')) {
environmentKey = 'dev';
} else if (instanceName.includes('test') || instanceName.includes('uat')) {
environmentKey = 'test';
} else if (instanceName.includes('prod')) {
environmentKey = 'prod';
} else {
gs.error("EndpointConfig: Could not determine environment for instance '" + instanceName + "'.");
return null;
}

if (endpoints.hasOwnProperty(environmentKey)) {
return endpoints[environmentKey];
} else {
gs.error("EndpointConfig: Configuration not found for environment '" + environmentKey + "'.");
return null;
}

} catch (ex) {
gs.error("EndpointConfig: Failed to parse JSON from system property '" + propertyName + "'. Exception: " + ex);
return null;
}
},

type: 'EndpointConfig'
};
Loading