Adding multiple objects in data action breaks variable collection

raw_result.json (2.2 KB)
Hi there! I will say first off that I am a Genesys Engineer that dabbles in Data Action creation, rather than a developer. I have a feeling my ask is quite rudimentary.

I am developing a data action response for account lookups via phone number in a custom CRM we have deployed. Most of the information we need is in an array with multiple objects. This is needed because we are trying to identify if a phone number returns multiple account results.

I can return most of the information just fine using ${rawResult} if I only call for one of the objects - the information appears to return fine. If I do this, I can capture, for example, account_number just fine.

As soon as I add a second object to grab data from, such as items.customer_oid, test stops showing the data collected. I assume I need to do some work with the translation map.

I have tried storing everything in an items array, and pulling the data there - once I do this, I get a "too many results" error.

Here's that response template I tried:

"response": {
"translationMap": {
"items": "$.items",
"account_number": "$.items[0].account_number",
"account_number2": "$.items[1].account_number"
},
"translationMapDefaults": {
"account_number": ""oopsie"",
"account_number2": ""oopsie""
},
"successTemplate": "$items,{\r\n"account_number":${account_number},\r\n"account_number2":${account_number2}"

I've uploaded the raw result I get if I just pull the GET, and also a copy of my data action containing my response template.

I can make this work with rawResult and a single object for account_number, but I am looking to pull in more data than that. It feels to me like getting the first one right, I will be able to use that to create the rest.

Get-Account-By-Phone-Number-Azure-Dip-2023010394704.custom.json (1.5 KB)
raw_result.json (2.2 KB)





raw_result.json (2.2 KB)

Here is the approach that I suggest, model the response from your remote endpoint as the output contract and return the raw result. So an output contract like

{
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "account_number": {
            "type": "string"
          },
          "customer_oid": {
            "type": "number"
          }
        },
        "additionalProperties": true
      }
    }
  },
  "additionalProperties": true
}

After the flattening step you will have items.account_number and items.customer_oid which are a couple of string arrays that will have the values you got back.

--Jason

1 Like

Thanks Jason - I have done this before and it works if I am only trying to look into one of the arrays. As soon as I add the second, I get blank results in test, which is what I'm trying to figure out.

Example: Following your template, I built in the customer_oid portion:

    {
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": [
        {
          "title": "account_number",
          "type": "object",
          "properties": {
            "account_number": {
              "type": "string"
            }
          },
          "additionalProperties": true
        },
        {
          "title": "customer_oid",
          "type": "object",
          "properties": {
            "customer_oid": {
              "type": "integer"
            }
          },
          "additionalProperties": true
        }
      ]
    },
    "_count": {
      "type": "integer"
    }
  },
  "additionalProperties": true
}

Using this, I still get a 200 from the remote end, but now test shows no variables being pulled at all. This is where I expect I need to set up a translation map. Am I looking in the right direction?

As an update to this, I messed around with my translation map and added the following, after test was not giving me any feedback besides a 200 OK when I added the second object:

{
  "translationMap": {
    "customer_oidvalue": "$..customer.oid",
    "account_numbervalue": "$..account_number"
  },
  "translationMapDefaults": {
    "customer_oidvalue": "0"
  },
  "successTemplate": "{\"customer_oid\":${customer_oidvalue},\"account_number\":${account_numbervalue}"
}

In execute, I can see my data - customer_oid is pulling a null value, which is interesting to me, but I don't think is the reason for my error now - account_number is pulling fine, and I see both values.

Then I am getting an end-of-input error:

{
  "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)\"{\"customer_oid\":[ ],\"account_number\":[ \"1130106922\", \"1120543144\" ]\"; line: 1, column: 1])\n at [Source: (String)\"{\"customer_oid\":[ ],\"account_number\":[ \"1130106922\", \"1120543144\" ]\"; line: 1, column: 68]'\n Template:'{\"customer_oid\":${customer_oidvalue},\"account_number\":${account_numbervalue}'.",
  "code": "bad.request",
  "status": 400,
  "messageParams": {},
  "contextId": "44dede59-0ed2-4f07-bc8d-5329c4ef8dff",
  "details": [
    {
      "errorCode": "ACTION.PROCESSING"
    }
  ],
  "errors": []
}

feels like I am missing something simple.

my account number values are there. I probably have to mess with the oid formatting, but does anything stick out that I may not be seeing?

Your output contract had an error.
You had:
A top level object (good)
That holds an array (good)
With the items expected to be a couple of strings (wrong, and maybe something we can/should detect)

The array should be configured to hold objects, with the objects having two strings.

This seemed to work for me:

{
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "account_number": {
            "type": "string"
          },
          "customer_oid": {
            "type": "number"
          }
        },
        "additionalProperties": true
      }
    },
    "_count": {
      "type": "integer"
    }
  },
  "additionalProperties": true
}

I am going to create a ticket to see if having an array configured to hold more than one thing is an error that we can reject, since that would have certainly helped get you going in the right direction.

--Jason

1 Like

Jason, this makes total sense now that I am looking at it - I appreciate the response and the patience, as this is definitely something I am looking to get better at.

I see what you're saying, and I will give this a whirl today!

No worries, we are always looking to smooth out the rough edges. This isn't nearly as straightforward as I would like it to be. Always feel free to point out pain points or make suggestions!

--Jason

This not only solved my issue, but allowed me to fix two other actions I was working on.

Much appreciated!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.