Genesys Cloud - Main

 View Only

Discussion Thread View
Expand all | Collapse all

Read the output from json response to output variables in Data action contract.

  • 1.  Read the output from json response to output variables in Data action contract.

    Posted 07-30-2024 11:22
    Edited by Karthik Ageer 07-31-2024 09:16

    Hi All,

    We have a table in Google BigQuery that contains a list of orders. I am working on fetching the list of orders and their attributes for a particular customer using Data action. Since one customer can have multiple orders, the API will return multiple rows.

    I am able to make the API request using a Data Action and retrieve the list of order IDs for a particular customer. However, I am unable to parse the JSON response and assigning it to an output variable/contract. 

    Can you please guide me on this. 

    {
      "rows.f.v": [
        [
          "test@test.com",
          "112335",
          "2024-04-15",
          "Pending",
          "Visa Card ending 1234",
          "2S100023546785",
          "CustomerName"
        ],
        [
          "test@test.com",
          "657845",
          "2024-03-15",
          "Shipped",
          "Visa Card ending 1234",
          "2S100023546785",
          "CustomerName"
        ],
        [
          "test@test.com",
          "566542",
          "2024-03-25",
          "Shipped",
          "Visa Card ending 1234",
          "2S100023546785",
          "CustomerName"
        ]
      ]
    }


    #API/Integrations
    #Implementation

    ------------------------------
    Karthik Ageer
    Computer Generated Solutions, Inc.
    ------------------------------



  • 2.  RE: Read the output from json response to output variables in Data action contract.

    Posted 07-30-2024 17:41

    Hello Karthik,

    Are you getting any errors when you try to parse the JSON response with a Data Action?



    ------------------------------
    Jason Kleitz
    Genesys - Employees
    ------------------------------



  • 3.  RE: Read the output from json response to output variables in Data action contract.

    Posted 07-31-2024 09:38

    No errors now after i matched the output contract to the response. Thank you. How can i access this rows object from the architect ? 



    ------------------------------
    Karthik Ageer
    Computer Generated Solutions, Inc.
    ------------------------------



  • 4.  RE: Read the output from json response to output variables in Data action contract.

    Posted 07-30-2024 18:38

    Hi Karthik

    That looks like the flattened results, when testing the data action untick flatten results, the base raw results is what you want to build your output contract around not the flattened results.



    ------------------------------
    Anton Vroon
    ------------------------------



  • 5.  RE: Read the output from json response to output variables in Data action contract.

    Posted 07-31-2024 09:37

    Thank you it is worked for me after i matched the output contract to unflattened json response.  I am just thinking about the next steps how can i access this rows object from the architect ? 

    {
      "rows": [
        {
          "f": [
            {
              "v": "test@test.com"
            },
            {
              "v": "112335"
            },
            {
              "v": "2024-04-15"
            },
            {
              "v": "Pending"
            },
            {
              "v": "Visa Card ending 1234"
            },
            {
              "v": "2S100023546785"
            },
            {
              "v": "CustomerName"
            }
          ]
        },
        {
          "f": [
            {
              "v": "test@test.com"
            },
            {
              "v": "657845"
            },
            {
              "v": "2024-03-15"
            },
            {
              "v": "Shipped"
            },
            {
              "v": "Visa Card ending 1234"
            },
            {
              "v": "2S100023546785"
            },
            {
              "v": "CustomerName"
            }
          ]
        },
        {
          "f": [
            {
              "v": "test@test.com"
            },
            {
              "v": "566542"
            },
            {
              "v": "2024-03-25"
            },
            {
              "v": "Shipped"
            },
            {
              "v": "Visa Card ending 1234"
            },
            {
              "v": "2S100023546785"
            },
            {
              "v": "CustomerName"
            }
          ]
        }
      ]
    }


    ------------------------------
    Karthik Ageer
    Computer Generated Solutions, Inc.
    ------------------------------



  • 6.  RE: Read the output from json response to output variables in Data action contract.

    Posted 07-31-2024 12:19

    I have published the data action and noticed that the output for the data action is showing as rows.f.v. with in the architect how can i verify/view the value assigned to the output ? 



    ------------------------------
    Karthik Ageer
    Computer Generated Solutions, Inc.
    ------------------------------



  • 7.  RE: Read the output from json response to output variables in Data action contract.

    Posted 07-31-2024 17:33

    So once your output contracts is working switch it back to flatten to see what it will look like in Architect. 

    I don't have any similar datasets on hand to replicate my end sorry, so would help seeing your output contract and example of the assigned outputs in the test data action.

    But what you have is an array of arrays, where all the fields in that nested array have all the same name "v", which I feel is going to make things difficult.

    But if you can provide some screenshots, of the output contract and what you get in those outputs when you run the data action in test, it will help.

    But in general you access lists/arrays in Genesys architect with either GetAt() function or through standard [] eg flow.myArry[0]



    ------------------------------
    Anton Vroon
    ------------------------------



  • 8.  RE: Read the output from json response to output variables in Data action contract.

    Posted 08-01-2024 02:02

    I agree with Anton's comments and suggestion to provide some screenshots. 

    Meanwhile, please refer to this post on the Developer forum and see if it may help: return-entire-json-object-with-data-action .  



    ------------------------------
    Tatjana Knezevic

    www.startelecom.cloud

    https://www.linkedin.com/company/star-telecom-www-startelecom-ca-/
    ------------------------------



  • 9.  RE: Read the output from json response to output variables in Data action contract.

    Posted 08-01-2024 07:22

    1) if i select the flatten output option i get the error " cannot flatten schemas with nested arrays", Attached screen shot of the error. 

    2) if i uncheck the flatten output option i am able to parse the output to variable in data action, attached screen shot. 

    3) attached the screen shots of response from google bigquery and the output parsed in data action. 

    Please help me in how  can i use this output from dataaction in architect, the  contents are basically the customeremail, orderID, orderedDate, status, paymentmethod, trackingID and customername. 



    ------------------------------
    Karthik Ageer
    Computer Generated Solutions, Inc.
    ------------------------------



  • 10.  RE: Read the output from json response to output variables in Data action contract.

    Posted 08-01-2024 09:45

    One thing to consider doing here, when you have complex, hierarchical data being returned by a Data Action, is to define "Rows" as an array in the Output Contract so that you return the entire JSON array to Architect.  You can then use all the newer JSON parsing functions in Architect to extract data from the JSON.  Working with the JSON parsing functions is much easier, in my opinion, then trying to use transforms and output contracts.



    ------------------------------
    Jim Crespino
    Senior Director, Developer Evangelism
    Genesys
    https://developer.genesys.com
    ------------------------------



  • 11.  RE: Read the output from json response to output variables in Data action contract.

    Posted 08-02-2024 07:24
      |   view attached

    I have tried to map rows to Array like in the attached screen shot, I get the error "there was an error updating Getthe Orderdetails".Can you please help me. Is there a devcast tutorial or example flow that i can refer please?



    ------------------------------
    Karthik Ageer
    Computer Generated Solutions, Inc.
    ------------------------------



  • 12.  RE: Read the output from json response to output variables in Data action contract.
    Best Answer

    Posted 08-04-2024 20:41

    If there is any chance of your backend responding with an array of objects instead of an array of array's that will make everything so much easier for you.

    Otherwise. To check the value in architect, I usually write it as participant data to see the raw output. But again if using an array of array architect is not going to like that. There is not data type for that. Which is why we then suggest you consider using the raw json and then use a Json data type in Genesys, which is itself a learning curve if you are not use to the syntax.

    So here is an example, where I map an output called raw_json to the full rawResults, but you could do it mapped to the row array instead if you want.

    Then in Architect you are going take the string output from the data action and assign it to a Json data type:

    to something like:

    Maybe with a check before hand to ensure it is valid json first.

    Then you can use the elements within with standard JSON parsing, there is also some function to check in the expression help section

    It is entirely up to you to ensure the naming and data structure is right though, there is no inbuilt checker.

    Here are some of the functions that are available for json objects in architect:



    ------------------------------
    Anton Vroon
    ------------------------------



  • 13.  RE: Read the output from json response to output variables in Data action contract.

    Posted 08-12-2024 06:11

    Thanks a lot, I am able to access the data action ouput as string and parse them using the JSON functions available in the architect. 



    ------------------------------
    Karthik Ageer
    Computer Generated Solutions, Inc.
    ------------------------------



  • 14.  RE: Read the output from json response to output variables in Data action contract.

    Posted 08-01-2024 23:44

    The flattened value is what architect will use which is why array of array's are problematic. Even though architect uses flattened values you do the mapping with the unflattened values which yeah a little annoying.

    If you can't change how the data is being presented from your Google BigQuery then I would recommend as Jim to essentially grab that top level array as raw json, then use architect newish Json data types to get the values you are after instead. 



    ------------------------------
    Anton Vroon
    ------------------------------



  • 15.  RE: Read the output from json response to output variables in Data action contract.

    Posted 08-02-2024 07:05

    Is there a way to verify if the data action is actually passing/assigning output in the architect ? i have assigned the data action output to a string collection and then tried to read the value using GetAT(stringcollectionvariable, 0). When i reach this point GetAT in architect the flow seems to throw the error "Sorry, an error occurred. One moment, please, while I put you through to someone who can help.". 



    ------------------------------
    Karthik Ageer
    Computer Generated Solutions, Inc.
    ------------------------------



  • 16.  RE: Read the output from json response to output variables in Data action contract.

    Posted 08-05-2024 11:58

    If you are returning the JSON object as a string from the Data Action to Architect then in Architect you will need to define a flow variable with a JSON type and then use JsonParse() function to convert that string back into a JSON object.  After you do that then you can use the other Json functions to query data from the JSON object.



    ------------------------------
    Jim Crespino
    Senior Director, Developer Evangelism
    Genesys
    https://developer.genesys.com
    ------------------------------



  • 17.  RE: Read the output from json response to output variables in Data action contract.

    Posted 08-01-2024 23:38
    Edited by Muhammad Zubair Awan 08-01-2024 23:59

    Working with JSON in architect seems better approach here as others suggested. 






Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources