Samuel_Polgar | 2019-02-20 20:03:46 UTC | #1
Hello PureCloud Developers
Please may I ask for guidance on pulling out an array from a PureCloud data action and then using it in a second data action?
I am using a GET Emergency Group by ID, and I am looking to grab the below part of the response and then use it in another data action.
"emergencyCallFlows": [ > { > "emergencyFlow": { > "id": "3fd421c8-1fa6-4096-xxxxxxx", > "name": "ONCALL Flow", > "selfUri": "/api/v2/flows/3fd421c8-1fa6-4096-xxxxxxx" > }, > "ivrs": [ > { > "id": "bd182919-a621-4b6b-b53xxxxxxx", > "name": "Samuel", > "selfUri": "/api/v2/architect/ivrs/bd18291xxxxxxx" > } > ] > } > ], > "selfUri": "/api/v2/architect/emergencygroups/cfd91bad-0292-4a72-a3bd-xxxxx" > }
I have been using JSON Path: "emergencyCallFlows": "$.emergencyCallFlows.*" which seems to be working.
It's my first time using the successTemplateUtils.firstFromArray after reading through previous threads, and from my understanding this is what I used: \n\"emergencyCallFlows\": ${successTemplateUtils.firstFromArray(\"${emergencyCallFlows}\", \"{}\")}
When I run the data action, I receive the below error: 10. Apply output transformation: Transform failed to process result using 'successTemplate' template due to error:'Unexpected end-of-input: expected close marker for Object
Please find the data action used attached.
Looking forward to your feedback, and please let me know if I could provide additional information.<a class="attachment" href="/forum/uploads/db6296/original/2X/5/51aa0869df326a840b8db5e7a9cec3b3f839ba08.json">Samuel-3-Get-Emergency-Status-2019022165910.custom.json</a> (1.9 KB)
Jason_Mathison | 2019-02-20 20:10:35 UTC | #2
Hi Samuel_Polgar,
Could you post the entire response you are getting from your call to GET Emergency Group by ID? That would let me accurately reproduce your situation and see if I can come up with a solution.
--Jason
Samuel_Polgar | 2019-02-20 20:15:09 UTC | #3
Hello Jason
Thank you very much for your response.
Please kindly find the JSON response below, and please let me know if anything further is required.
{ "status": 400, "code": "bad.request", "message": "Transform failed to process result using 'successTemplate' template due to error:'Unexpected end-of-input: expected close marker for Object (start marker at [Source: (String)\"{\n\"enabled\":false, \n\"name\":\"Samuel Emergency\", \n\"version\":99, \n\"emergencyCallFlows\": {\"emergencyFlow\":{\"id\":\"3fd421c8-1fa6-4096-9f1xxxx\",\"name\":\"ONCALL Flow\",\"selfUri\":\"/api/v2/flows/3fd421c8-1fa6-4xxxx\"},\"ivrs\":[{\"id\":\"bd182919-a621-4b6b-b53a-0e6257d5599c\",\"name\":\"Samuel\",\"selfUri\":\"/api/v2/architect/ivrs/bd182919-a621-4b6b-b53a-xxxx\"}]}\"; line: 1, column: 1])\n at [Source: (String)\"{\n\"enabled\":false, \n\"name\":\"Samuel Emergency\", \n\"version\":99, \n\"emergencyCallFlows\": {\"emergencyFlow\":{\"id\":\"3fd42xxxx-ef41aexxa7\",\"name\":\"ONCALL Flow\",\"selfUri\":\"/api/v2/flows/xxxx-4096-9f1e-ef41aexx7\"},\"ivrs\":[{\"id\":\"bd182919-a621-4b6b-b53a-0e6257xxc\",\"name\":\"Samuel\",\"selfUri\":\"/api/v2/architect/ivrs/xxxxa621-4b6b-b53a-0e6257d5xxc\"}]}\"; line: 5, column: 688]'\n Template:'{\n\"enabled\":${statusValue}, \n\"name\":${nameValue}, \n\"version\":${versionValue}, \n\"emergencyCallFlows\": ${successTemplateUtils.firstFromArray(\"${emergencyCallFlows}\", \"{}\")}'.", "messageParams": {}, "contextId": "92aabe81-3107-4bb4-a8f7xxxb6", "details": [ { "errorCode": "ACTION.PROCESSING" } ], "errors": [] }
Jason_Mathison | 2019-02-20 20:17:35 UTC | #4
Hi Samuel_Polgar,
You posted the error from the second action, I was hoping for the output from the first action that you are trying to process in the second action. If it is a lot of output you can save it as a .json file and attach it to the thread that way.
--Jason
Samuel_Polgar | 2019-02-21 09:49:34 UTC | #5
Hello @Jason_Mathison
I have not made the second action yet, this is the error from the initial GET Emergency Group by ID. This response is received from the data action posted above.
Please find the full response below:
Please let me know if I could help with further questions.<a class="attachment" href="/forum/uploads/db6296/original/2X/9/9210806a04ec84f1b84c9cdfc951c3891f0ec2d7.json">GetEmergencyError.json</a> (6.9 KB)
Samuel_Polgar | 2019-02-28 23:50:31 UTC | #6
Hello @Jason_Mathison
Hope you've been well.
Looping back on this to check if you had a moment to review the errors? I am looking forward to your feedback, and please let me know if I could provide more information.
Jason_Mathison | 2019-03-04 12:50:22 UTC | #7
Hi Samuel_Polgar,
I dug through your example, and reproduced the error that you are seeing. It appears that the biggest issue is that you need to add an extra } before the final " in your successTemplate. That got my test running running at least.
--Jason
Samuel_Polgar | 2019-03-05 03:36:55 UTC | #8
Hello @Jason_Mathison
My sincere gratitude, thank you very much for following up and helping, and thank you for your response.
I am not sure if what I am trying is possible, or if I am going about it the right way, and apologies that I didn't explain enough.
When the data action executes, I am looking for the emergencyCallFlows array so I can then keep it as a string in the IVR to then update the emergency group again with a second data action.
In Summary
- Get the emergency status with data action 1 and keep the details in the IVR
- Update the emergency status with data action 2 with the details from step 1
The reason why I am looking for the emergencyCallFlows array is because, from my understanding it is required in the update action. Currently I am hard coding the emergencyCallFlows array in the update action. If any changes are made to the queue names for example the update action will not work.
Using the JSON path
$.emergencyCallFlows.*
We can get the array
"emergencyCallFlows": [ { "emergencyFlow": { "id": "52ac420f-379e-4e81-8252-fe8438068642", "name": "DemoxyzMainFlow", "selfUri": "/api/v2/flows/52ac420f-379e-4e81-8252-fe8438068642" }, "ivrs": [ { "id": "bd182919-a621-4b6b-b53a-0e6257d5599c", "name": "Samuel", "selfUri": "/api/v2/architect/ivrs/bd182919-a621-4b6b-b53a-0e6257d5599c" } ] } ]
The output contract of this first data action is now failing, from my understanding because I am trying to put an object into a string, please see the error below and full response attached.
{ "status": 400, "code": "invalid.schema", "message": "JSON failed schema validation for the following reasons: Schema: # @/properties/emergencyCallFlows. Error location: /emergencyCallFlows. instance type (object) does not match any allowed primitive type (allowed: [\"string\"])", "messageParams": {}, "contextId": "5f5a385a-5cd1-4c68-a527-bf77292d2c96", "details": [ { "errorCode": "ACTION.PROCESSING" } ], "errors": [] }
Please kindly find the data action and error., and looking forward to your feedback.
<a class="attachment" href="/forum/uploads/db6296/original/2X/e/e3ea0893655bed9028d30e76d988c5615dcae48b.json">error.json</a> (5.3 KB)
<a class="attachment" href="/forum/uploads/db6296/original/2X/1/1c725bbc2564fe459a7074425913d9657648dbac.json">Samuel-4-Get-Emergency-Status-20190305135207.custom.json</a> (1.9 KB)
Jason_Mathison | 2019-03-05 15:25:07 UTC | #9
If you change the emergencyCallFlows in the output contract to this:
"emergencyCallFlows": { "type": "object" }
The action will succeed, however you won't have easy access to the contents of the object. You can continue to model the data you are getting back from the first endpoint, however I don't know much about that endpoint to know what you are trying to accomplish. Is there specific data from the emergencyCallFlows that can be extracted by JSONPath and inserted back into a template?
--Jason
Samuel_Polgar | 2019-03-12 09:34:59 UTC | #10
Hello Jason
Thank you for checking, and yes when I change the type to object, the data action test is successful, it appears we cannot use objects in the IVR, or output contracts.
Basically I am wanting to use the Emergencygroups API's consecutively. 1st GET api to get the details of the Emergency group for updating (i.e. string Name, Integer Version and object emergencycallflows), then use the PUT api to update it, which requires the string Name and Integer Version, and the emergencycallflows object from the first API.
GET/api/v2/architect/emergencygroups/{emergencyGroupId}
PUT /api/v2/architect/emergencygroups/{emergencyGroupId}
Not sure how it is possible to have this information stored in the IVR for use in the second call, and open to any recommendations.
Jason_Mathison | 2019-03-12 18:16:37 UTC | #11
Before I try to dig any deeper with a data action solution can you walk through the business issue you are facing and how you are trying to solve it (at a non-technical level)? I have never used these routes so I don't understand what you are trying to do with them.
--Jason
Samuel_Polgar | 2019-03-12 21:40:59 UTC | #12
Hello Jason
Certainly, on a non-technical level I would like to turn the emergency mode on from an inbound call flow.
Jason_Mathison | 2019-03-13 12:49:46 UTC | #13
Thanks for business case, that clears up the goal!
It seems to me that the right long term fix would be to add a PATCH /api/v2/architect/emergencygroups/{emergencyGroupId} route that would allow you to toggle the enabled flag. If you agree please submit that idea to https://purecloud.ideas.aha.io/
Even if that idea is approved it won't be available for a while, so here are a couple of options:
In my opinion the worst option is to try to implement this with multiple PureCloud Data Actions and an Architect flow. If the ivrs section of the emergencyCallFlows object never changes it should be possible to build actions that can get all of the data into architect and then rebuild a put to do the update. This is very fragile because it would take building some big templates and if the number of IVRs changed there would be all kinds of problems.
The best short-term suggestion I can come up with is to create an AWS Lambda Data action that takes the emergencyGroupId and a boolean. The lambda would then log into PureCloud and do the get and put. I am by no means a javascript expert, but I think that the javascript SDK that we provide would make it pretty easy to create what you need.
--Jason
Samuel_Polgar | 2019-03-13 20:55:45 UTC | #14
Hello Jason
Thank you very much for the explanation and recommendation.
I will trial the Lambda action with Javascript SDK, meanwhile I have submitted a PureCloud feature request: https://purecloud.ideas.aha.io/ideas/CLPLA-I-683
Thank you very much once again.
anon74207878 | 2019-03-31 15:19:11 UTC | #15
Not sure if this would work for you, but I use the following data actions: <a class="attachment" href="/forum/uploads/db6296/original/2X/a/a402c5f2f68a2cb86f3e4c533b0443d9e440c04a.json">GET-EmergencyGroup-info.json</a> (7.3 KB) <a class="attachment" href="/forum/uploads/db6296/original/2X/6/6183fb6c78e17e1fa4ac62e1ef1f049229b51db7.json">PUT-EmergencyGroup-info.json</a> (7.1 KB)
First I get the emergency group info, after that I PUT the info back, but enable the emergency. This allows you to toggle emergency on or off.
Hope that helps.
Samuel_Polgar | 2019-04-02 09:15:49 UTC | #16
Hello @anon74207878
This works extremely well, thank you very much for sharing these with us, I sincerely appreciate your help.
system | 2019-05-03 09:29:14 UTC | #17
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 4632