Genesys Cloud - Main

 View Only

Sign Up

  • 1.  Data Actions Help - Integer and String values

    Posted 6 hours ago

    I am hoping to get some help with a custom data action I have built. We are using the action to retrieve customer account details from the customer's external application. One of the values we receive back are the last 4 digits of an account number. The data action is built to receive this as an integer value, but in some cases this value is stored as a string value instead. Seems to be if the first digit is a zero, it's sent as a string, otherwise it is sent as an integer. Unfortunately when the value is sent as a string it causes the data action to fail.

    Is there any logic I can build into the data action so that it always translates the value into a string?


    #API/Integrations

    ------------------------------
    James Foster
    Technical Consultant
    ------------------------------


  • 2.  RE: Data Actions Help - Integer and String values
    Best Answer

    Posted 3 hours ago

    Hi James,

    Yes, you should be able to build what you need.

    I built a test data action to confirm it, and will provide the details below so you can take a look and try to apply it to your case.

    But to summarize, you have to work within the "successTemplate" of your data action to ensure the results are always of the same type (In my case I tried to ensure the results are always a string, as that seems to be what you would need. If it was always an integer the initial 0 would be removed from the strings that you have).

    An example of the final configuration for what I have:

    {
      "translationMap": {
        "price": "$[4].data.price"
      },
      "translationMapDefaults": {},
      "successTemplate": "{\n  \"price\": \"$price.replace('\"', '')\"\n}"
    }
    This is using a GET on this public endpoint for testing: https://api.restful-api.dev/objects
    I also created "price" as an string on the output contracts: 
    ---------
    This public API on the 5th object returns price as an integer:
      {
        "id": "5",
        "name": "Samsung Galaxy Z Fold2",
        "data": {
          "price": 689.99,
          "color": "Brown"
        }
      }
    Which gets converted to a string on the data action.
    You can also check that it works for the value being returned as a string on the API on the 12th object:
      {
        "id": "12",
        "name": "Apple iPad Air",
        "data": {
          "Generation": "4th",
          "Price": "419.99",
          "Capacity": "64 GB"
        }
      }
    But to test the above object you have to change the data action to this:
    {
      "translationMap": {
        "price": "$[11].data.Price"
      },
      "translationMapDefaults": {},
      "successTemplate": "{\n  \"price\": \"$price.replace('\"', '')\"\n}"
    Let me know if this helps, or share some more details of the structure of your action and I can try to help with setting up what's missing.


    ------------------------------
    Marcello Jabur
    ------------------------------