I'm trying to get started using the PureCloud Architect Scripting API in node.js. After much trial and error, I have gotten my code to authenticate, but can't seem to get it to create a new flow. Here is my code sample:
/*** START CODE ***/
var pureCloud = require('purecloud-flow-scripting-api-sdk-javascript');
var archSession = pureCloud.environment.archSession;
var pcArchFactoryFlows = pureCloud.factories.archFactoryFlows;
var clientId = "redacted";
var clientSecret = "redacted";
var orgLocation = 'prod_us_east_1';
var cvCreateFlow = function() {
var flowName = 'MyScriptedFlow';
var flowDesc = 'This was created using the purecloud node SDK';
archSession.startWithClientIdAndSecret(
orgLocation,
function(){
pcArchFactoryFlows.createFlowInboundCallAsync(
flowName,
flowDesc,
'',
function(theFlow) {
theFlow.saveAsync()
.then(function(savedFlow){
console.log("The saved flow: "+savedFlow);
})
.catch(function(e){
console.log("Problem saving flow: "+e);
});
}
)
.then(function(){
console.log("createFlowInboundCallAsync returned");
})
.catch(function(e){
console.log("Problem creating inbound flow: "+e);
});
},
clientId,
clientSecret
);
} //end cvCreateFlow()
cvCreateFlow();
/*** END CODE ***/
The output I see in the node console is:
Architect Scripting running under Node version '8.11.3'
ArchSessionId:redacted
navigator unavailable - setting operating system to unknown
- core environment configuration. env: 'prod', host: 'apps.mypurecloud.com', region: 'us-east-1', clientId: 'redacted', clientSecret: 'redacted' -- [ArchSession, ArchSessionId:'redacted]
- getting discovery properties... -- [ArchSession, ArchSessionId:'redacted]
- core environment discovery properties loaded. -- [ArchSession, Environment:'prod', Host:'apps.mypurecloud.com', Region:'us-east-1', ArchSessionId:'redacted']
- core environment initialized. Now logging in... -- [ArchSession, Environment:'prod', Host:'apps.mypurecloud.com', Region:'us-east-1', ArchSessionId:'redacted']
- setting auth token 'redacted' -- [ArchSession, Environment:'prod', Host:'apps.mypurecloud.com', Region:'us-east-1', ArchSessionId:'redacted']
- authenticated name: '' , id: 'redacted' -- [ArchSession, Environment:'prod', Host:'apps.mypurecloud.com', Region:'us-east-1', ArchSessionId:'redacted']
- user authentication level: admin -- [ArchSession, Environment:'prod', Host:'apps.mypurecloud.com', Region:'us-east-1', ArchSessionId:'redacted']
- no language specified for creation of flow 'MyScriptedFlow' ( type: inboundcall ). Defaulting default language to US English -- [ArchFactoryFlows]
- ending with exit code: 0 -- [ArchSession, Environment:'prod', Host:'apps.mypurecloud.com', Region:'us-east-1', ArchSessionId:'redacted']
- Session is configured to terminate the process when ending. -- [ArchSession, Environment:'prod', Host:'apps.mypurecloud.com', Region:'us-east-1', ArchSessionId:'redacted']
- Now exiting the process with exit code: 0 -- [ArchSession, Environment:'prod', Host:'apps.mypurecloud.com', Region:'us-east-1', ArchSessionId:'redacted']
It appears that authentication is working, createFlowInboundCallAsync() is called, but the callback function that I provide as a parameter (that calls theFlow.saveAsync()) is never called. The "then()" clauses are also never invoked (I have tried with and without).
Can you provide assistance in understanding what the correct way to handle the initial creation/save of a new flow is?
Additionally, I have tried following the Architect Scripting documentation to get started with this SDK, but I had to use a debugger + trial and error to figure out that I needed to use the pureCloud.environment.archSession and pureCloud.factories.archFactory properties to even get as far as I did. Is there a set of complete starter examples somewhere that I can use as a template to get started?
Thanks,
Evan