devanand_gawande | 2023-08-11 01:11:01 UTC | #1
Hello Team, Greetings, I am getting output of API(Campaign Details), but unable to save it in one variable. as I want to use it for next PUT operation. Plz help with the Translation Map/Success Template syntax details. and a logic to understand the same.(a documentation/Video link plz)
Below is the output of the API request: I have one output contract variable "campaigndata", and want to save all the output in that variable. (as of now I could see a flat JSON output)
Thanks a lot..!!!
Query: GET /api/v2/outbound/campaigns/{campaignId}
Output:
{ "id": "148abdewewewewew48f-84cf-efXXXbf2", "name": "SNOWINCMgmt", "dateCreated": "2023-08-10T03:14:31.842Z", "dateModified": "2023-08-10T08:58:00.723Z", "version": 42, "contactList": { "id": "cc0wewedb6-4669-b7fc-3ebXXXX4f0", "name": "Shift1IncMgrSnow", "selfUri": "/api/v2/outbound/contactlists/cc03efcd-XXXX669-b7fc-3eb5wewewe4f0" }, "dialingMode": "agentless", "site": { "id": "0b1502wewewew9-4405-a60f-92c4f6ae1dfa", "name": "Cawewearszawa (PL)", "selfUri": "/api/v2/telephony/providers/edges/sites/0b150218XXX05-a60f-92c4f6ae1dfa" }, "campaignStatus": "off", "phoneColumns": [ { "columnName": "ContactNo", "type": "Cell" } ], "abandonRate": 5, "dncLists": [], "callAnalysisResponseSet": { "id": "0afwe-4b79-404a-bb19-95XXXx9ef", "name": "SNOWOB", "selfUri": "/api/v2/outbound/callanalysisresponsesets/0afd8dfdfb79-404a-bb19-9594dda689ef" }, "callerName": "weweni ServiceNow", "callerAddress": "+442dddddf84", "outboundLineCount": 1, "ruleSets": [], "skipPreviewDisabled": false, "previewTimeOutSeconds": 0, "singleNumberPreview": false, "alwaysRunning": false, "contactSort": { "fieldName": "ContactNo", "direction": "ASC", "numeric": false }, "contactSorts": [ { "fieldName": "ContactNo", "direction": "ASC", "numeric": false } ], "noAnswerTimeout": 20, "callAnalysisLanguage": "en-GB", "priority": 5, "contactListFilters": [], "division": { "id": "bweww070-4c -d9fb412e8b1a", "name": "Home", "selfUri": "/api/v2/authorization/divisions/bweewDDD ec5DDD412e8b1a" }, "dynamicContactQueueingSettings": { "sort": false }, "selfUri": "/api/v2/outbound/campaigns/14wewewec-6c -efc77b7d9bf2" }
I tried with the below given one translationMap, but its not working.
{ "translationMap": { "campaigndata": "$.campaigndata" }, "translationMapDefaults": {}, "successTemplate": "${campaigndata}" }
Charaf | 2023-08-11 08:13:05 UTC | #2
Hi @devanand_gawande,
To create a JSON response, you must escape strings using the following macro:
$esc.jsonString(${input.json})
To learn more about velocity macros, you can refer to this link.
So, within your success template, you should apply the macro to the campaignData defined in your output contract:
{
"translationMap": {},
"translationMapDefaults": {},
"successTemplate": "{\"campaignData\": \"$esc.jsonString(${rawResult})\"}"
}
Below, the response:
If you prefer to get rid of entities and directly access the array containing campaign data, you can add a temporary variable in the translationMap as the following:
{
"translationMap": {
"temp": "$.entities[*]"
},
"translationMapDefaults": {
"temp": "[]"
},
"successTemplate": "{\"campaignData\": \"$esc.jsonString(${temp})\"}"
}
Response:
Attached, you will find the Data Action, all set and ready for you to use :slight_smile: Get-Campaign-Data-20230811101211.custom.json|attachment (906 Bytes)
Best regards,
Charaf
devanand_gawande | 2023-08-15 09:53:32 UTC | #3
Thanks a lot Charaf..!! It worked as expected.
Need one more help plz, How to pass the Raw Request (String) as a input to the data action. Now I have the campaigndata in one variable, using replace function I replaced the "campaignstatus" :"off or on" to "CampaignStatus" : "${input.campaignStatus}". But now I have to pass the new variable value as a Raw Request Template. I tried to create an input contract but its not working. plz guide.
Thanks, Dev Gawande.
Charaf | 2023-08-16 11:33:17 UTC | #4
Hi @devanand_gawande,
I assume you are targetting the following API endpoint to toggle the campaign status:
PUT /api/v2/outbound/campaigns/{campaignId}
You need to provide the campaignId as input to update the desired campaign status, along with a JSON object in the request body.
The body should be structured as follows:
{
"name": "",
"version": 0,
"contactList": {
"id": "",
"name": "",
"selfUri": ""
},
"queue": {
"id": "",
"name": "",
"selfUri": ""
},
"dialingMode": "",
"script": {
"id": "",
"name": "",
"selfUri": ""
},
"edgeGroup": {
"id": "",
"name": "",
"selfUri": ""
},
"site": {
"id": "",
"name": "",
"selfUri": ""
},
"campaignStatus": "",
"phoneColumns": [
{
"columnName": "",
"type": ""
}
],
"abandonRate": {},
"dncLists": [
{
"id": "",
"name": "",
"selfUri": ""
}
],
"callableTimeSet": {
"id": "",
"name": "",
"selfUri": ""
},
"callAnalysisResponseSet": {
"id": "",
"name": "",
"selfUri": ""
},
"callerName": "",
"callerAddress": "",
"outboundLineCount": 0,
"ruleSets": [
{
"id": "",
"name": "",
"selfUri": ""
}
],
"skipPreviewDisabled": true,
"previewTimeOutSeconds": 0,
"alwaysRunning": true,
"contactSort": {
"fieldName": "",
"direction": "",
"numeric": true
},
"contactSorts": [
{
"fieldName": "",
"direction": "",
"numeric": true
}
],
"noAnswerTimeout": 0,
"callAnalysisLanguage": "",
"priority": 0,
"contactListFilters": [
{
"id": "",
"name": "",
"selfUri": ""
}
],
"division": {
"id": "",
"name": "",
"selfUri": ""
},
"dynamicContactQueueingSettings": {
"sort": true
}
}
Ensure you have filtered out the campaignData array to only include the campaign you intend to update Here's an example where I passed the JSON body as input to data action, and the update worked successfully:
 |
 |
I hope that helped.
Best regards,
Charaf
devanand_gawande | 2023-08-16 12:15:56 UTC | #5
Hello Charaf,
Thanks a lot. its working(with hardcoding the value eg. on,off), but is there any way I can set the status of campaign by giving input to the Data Action using variable. I used "replace" function but lot of values got modified and the operation failed.
Like I want to stop the campaign here, so I used the "replace" function and modified the value of the Template from "on">>> "${input.campaignStatus}" then I passed the value "off" to this input. but the stop operation failed.
The error message is: [${input.campaignStatus}] is not valid field type [campaignStatus]. Allowable values are on, stopping,off..etc
xxxa60f-92c4f6ae1dfa" }, "campaignStatus" : "${input.campaignStatus}", "phoneColumns" : [ { "columnName" : "ContactNo", "type" : "Cell" } ], "abandonRate" : 5.0, "dncLists" : [ ], "callAnalysisResponseSet" : { "id" : "0afd.......
Thanks.
Dev Gawande.
devanand_gawande | 2023-08-16 15:47:59 UTC | #6
For time being, I replaced the string,
"campaignStatus" : "${input.campaignStatus}"
using below given architect function and it worked.
Replace((Flow.s_CampaignData),"\"campaignStatus\" : \"on\"", "\"campaignStatus\" : \"off\"")
Thanks a lot for your help.
Dev
system | 2023-09-16 15:48:07 UTC | #7
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: 21466