Create/Save new Inbound Call Flow using Architect Scripting SDK in Node.js

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

Hi,

Still stuck on this one. Can anyone help?

Thanks,
Evan

Hi Evan,

If you add a return before pcArchFactoryFlows.createFlowInboundCallAsync( (which makes that line read return pcArchFactoryFlows.createFlowInboundCallAsync(, this should fix your issue.

The reason is because if there's async work to be done via a promise, the scripting library needs to be aware of it in order to know there's more work to be done (via returning the promise). Otherwise, the promise will start execution but then overall Scripting execution will end due to there being no more code to execute in the scope of the callback function and Scripting not having been returned the pcArchFactoryFlows.createFlowInboundCallAsync promise.

We'll be looking at updating the documentation to make the callback/promise behavior more clear.

Thanks for using Architect Scripting!
Scott

AH HA! YES. Simple return statement. This works. Thanks!

For completeness' sake, I also had to add a return statement here:

return theFlow.saveAsync()

Thanks again!
Evan

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.