Legacy Dev Forum Posts

 View Only

Sign Up

Parser rawResult - Object into Array

  • 1.  Parser rawResult - Object into Array

    Posted 06-05-2025 18:41

    msalas | 2020-07-01 03:26:02 UTC | #1

    Hello!! I am taking my first steps on purecloud, and I cannot solve this problem.

    Our client provides us with a service that is returning the following JSON: { "Dues": [ { "OpenAmount": { "OpenAmount": 1308.67, "currencyCode": "ARS" }, "Due": 12123213 }, { "OpenAmount": { "OpenAmount": 308.67, "currencyCode": "ARS" }, "Due": 23213 } ] } I need to sum all the values ​​in the OpenAmount field.

    Set up the action and run successful tests. But when using it in the IVR, it indicates that the OpenAmount field is string instead of a number. But the Due field takes it as a number.

    The call drops when this action is performed. But if I don't assign a variable to the OpenAmount field, the call continues normally.

    Do you know how I could solve this problem?


    Jerome.Saint-Marc | 2020-07-01 09:05:46 UTC | #2

    Hello,

    Could you share the definition of your Data Action (Input/Output contracts, Request/Response configuration)?

    Regards,


    msalas | 2020-07-01 14:14:33 UTC | #3

    msalas, post:1, topic:8157
    Dues

    Hello Jerome, I copy the definition of my data action:

    Action Contracts Input Contract { "title": "Request", "type": "object", "properties": { "NroContrato": { "type": "string" } }, "additionalProperties": true }

    Output Contract { "title": "Response", "type": "object", "properties": { "Dues": { "type": "array", "items": { "title": "Item 1", "type": "object", "properties": { "OpenAmount": { "type": "object", "properties": { "OpenAmount": { "type": "number" }, "currencyCode": { "type": "string" } }, "additionalProperties": true }, "Due": { "type": "number" } }, "additionalProperties": true } } }, "additionalProperties": true }

    Action Configuration Request { "requestUrlTemplate": "https://example.com/dev/v1?NroContrato=${input.NroContrato}", "requestType": "GET", "headers": { "Authorization": "Bearer ${authResponse.access_token}" }, "requestTemplate": "${input.rawRequest}" }

    Response { "translationMap": { "Dues": "$.CashPointOpenItemSummaryByElementsResponseMessage.CashPointResponseMessage.CashPointOpenItemSummary.CashPointOpenItem", "Deudas": "$.deudas" }, "translationMapDefaults": { "Dues": "[]", "Deudas": "[]" }, "successTemplate": "{\"Dues\" : ${Dues}, \"Deudas\" : ${Deudas}}" }

    Regards.


    Jerome.Saint-Marc | 2020-07-01 15:12:31 UTC | #4

    And how do you make the sum in Architect flow? Just adding Dues[$index].OpenAmount.OpenAmount values via +?


    msalas | 2020-07-01 15:26:00 UTC | #5

    I haven't gotten to that step yet, because the call drops when the data action is used.

    When trying to assign a list of numbers to a list of strings.


    Jerome.Saint-Marc | 2020-07-01 16:52:59 UTC | #6

    I have just tried to create a REST service calling it via a Data Action from an Architect Chat Flow and it didn't generate an error. The output variable is also tagged as a String Collection and not a Decimal collection. I haven't tried with an Architect Inbound Call Flow (in case that is different).

    I had noticed a typo in your Response Configuration (probably just a typo while copying it to the post).

    This is the data my service is sending back:

    { "CashPointOpenItemSummaryByElementsResponseMessage": { "CashPointResponseMessage": { "CashPointOpenItemSummary": { "CashPointOpenItem": [ { "OpenAmount": { "OpenAmount": 1308.67, "currencyCode": "ARS" }, "Due": 12123213 }, { "OpenAmount": { "OpenAmount": 308.67, "currencyCode": "ARS" }, "Due": 23213 } ] } } } }

    And this is my Response Configuration:

    { "translationMap": { "Dues": "$.CashPointOpenItemSummaryByElementsResponseMessage.CashPointResponseMessage.CashPointOpenItemSummary.CashPointOpenItem", "Deudas": "$.deudas" }, "translationMapDefaults": { "Dues": "[]", "Deudas": "[]" }, "successTemplate": "{\"Dues\" : ${Dues}, \"Deudas\" : ${Deudas}}" }

    If you had something different (HTTP JSON Response or Response Configuration), let me know. Otherwise, I'll try the same from an Architect Voice Flow. I just want to understand if your exception was caused by the difference of types or by something else. If it was something else, and if the OpenAmount are stored as a Collection of Srting, then you can use the Decimal function to convert a string variable/value back to a decimal (Decimal(xxxxx)).


    msalas | 2020-07-01 19:35:45 UTC | #7

    With the help of a partner, we come to this:

    { "translationMap": { "fecvto": "$.deudas[0:].fecvto", "DueDate": "$.CashPointOpenItemSummaryByElementsResponseMessage.CashPointResponseMessage.CashPointOpenItemSummary.CashPointOpenItem[0:].DueDate", "iobligac": "$.deudas[0:].iobligac", "OpenAmount": "$.CashPointOpenItemSummaryByElementsResponseMessage.CashPointResponseMessage.CashPointOpenItemSummary.CashPointOpenItem[0:].OpenAmount.OpenAmount" }, "translationMapDefaults": { "fecvto": "[]", "DueDate": "[]", "iobligac": "[]", "OpenAmount": "[]" }, "successTemplate": "{\"OpenAmount\" : ${OpenAmount},\"DueDate\" : ${DueDate},\"iobligac\" : ${iobligac},\"fecvto\" : ${fecvto}}" }

    It works perfectly.

    Jerome, thanks for your time.


    system | 2020-08-01 19:35:47 UTC | #8

    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: 8157