Multiple cui.js
Objects
Typically, an App instantiates one cui.js
object and uses it for every API call. This is suitable when all the APIs share a common server URL, and a single mode of authentication. However, if limitations arise, an App can use multiple cui.js
objects simultaneously.
Scenarios
Generally, the following scenarios require the use of multiple cui.js
objects:
- An App that simultaneously calls Covisint APIs running on different servers.
- An App that simultaneously calls Covisint and 3rd-party APIs.
- An App that simultaneously depends on different types of Authentication.
- Any combination of the above.
Defining Multiple objects
Each object needs a unique sessionId
when it is created, and a unique reference in the App. In that way, the context of each object is distinct.
In this example, one object targets the STG
environment, and another targets a 3rd-party environment.
var firstCuiJs = {};
var secondCuiJs = {};
var thirdPartyCallDefs = [{...}];
cui.api({
sessionId: 1,
serviceUrl: 'STG',
defs: ['https://cuijs.run.covisintrnd.com/defs/idm.json'],
}).then(function(obj) {
firstCuiJs = obj;
});
cui.api({
sessionId: 2,
serviceUrl: 'https://thid-party-server.io',
defs: [thirdPartyCallDefs],
}).then(function(obj) {
secondCuiJs = obj;
});
Then, the objects can be used as simultaneously, as desired. In this somewhat contrived example, one of the object’s is used for authentication and a second object is used to make an API call.
firstCuiJs.doSysAuth({
clientId: 'YOUR CLIENT ID',
clientSecret: 'YOUR CLIENT SECRET'
}).then(function() {
secondCuiJs.getThirdPartySubjects().then(function(response) {
// do something with response...
});
});