Legacy Dev Forum Posts

 View Only

Sign Up

DataAction with inputs as arrays

  • 1.  DataAction with inputs as arrays

    Posted 06-05-2025 18:41

    agilio | 2020-01-21 14:05:51 UTC | #1

    I'm creating a data action but the inputs require an array. To get around the limitation of no arrays in inputs I've manually constructed the requestTemplate.

    "requestTemplate": "{\"queueId\": \"$input.queueId\",\"callbackUserName\": \"$input.callbackUserName\",\"callbackNumbers\": \"[$input.callbackNumbers]\",\"callbackScheduledTime\": \"$input.callbackScheduledTime\",\"countryCode\": \"$input.countryCode\",\"validateCallbackNumbers\": \"$input.validateCallbackNumbers\"}"

    The response I get back from PC is :slight_smile: Execute: The request could not be understood by the server due to malformed syntax.

    • REST call for action execute failed. Message:Request to backend service failed. Response from web service: {"status":400,"code":"bad.request","message":"The request could not be understood by the server due to malformed syntax.","contextId":"c415dbc4-ef47-4bf5-ba8e-fe75ca68aec5","details":[],"errors":[]} [50aa8037-2b91-408c-a7cb-4279e6aacf92]

    JSON

    What am I missing?


    anon28066628 | 2020-01-21 15:17:38 UTC | #2

    Can you post the entire constructed request body from the Test tool here? It's hard to tell w/o seeing the inflated request. Your general approach should work, though. Be sure you're concatenating the numbers with appropriate quotes and comma delimeters:

    "+13172220155","+13172345678","......"


    Jason_Mathison | 2020-01-21 15:21:13 UTC | #3

    I would suggest running the action in test mode and seeing what is returned by the execute step. Look to make sure it looks like what you expect. You can run the output through something like https://jsonlint.com/ to ensure it is valid JSON. You can also use that as your body in a postman request to see what the endpoint returns.

    Quick Edit: I can see in our logs that we cannot deserialize a JSON array out of the JSON we are being sent. I don't have any other details in the logs beyond that.


    agilio | 2020-01-21 16:20:17 UTC | #4

    Attached is the data action <a class="attachment" href="/forum/uploads/db6296/original/2X/c/cd07f26b22a27c94aadc2988d3325378393d89b0.json">CallBackWithDateandTime-20200121100928.custom.json</a> (2.2 KB)

    Hopefully that makes it clearer


    Jason_Mathison | 2020-01-21 16:31:47 UTC | #5

    What is being returned by the execute step in test mode? Did you verify that it is valid JSON?


    agilio | 2020-01-21 17:37:38 UTC | #6

    When I run the test this is what the Resolve body template shows.

    "{\"queueId\": \"2e8fa413-b6d7-45f2-bb43-4a5ae9808c44\",\"callbackUserName\": \"Test\",\"callbackNumbers\": \"[+13125154609]\",\"callbackScheduledTime\": \"2020-01-21T11:40:00.000Z\",\"countryCode\": \"1\",\"validateCallbackNumbers\": \"true\"}"

    Which I assume should translate properly.


    Jason_Mathison | 2020-01-21 18:03:21 UTC | #7

    So while "callbackNumbers": "[+13125154609]" is valid JSON, it isn't what you want. "[+13125154609]" is a string that happens to have square brackets in it, it is not an array. You probably want something like

    "callbackNumbers": ["+13125154609"]


    agilio | 2020-01-21 18:11:31 UTC | #8

    {"queueId": "$input.queueId","callbackUserName": "$input.callbackUserName","callbackNumbers": "[$input.callbackNumbers]","callbackScheduledTime": "$input.callbackScheduledTime","countryCode": "$input.countryCode","validateCallbackNumbers": "$input.validateCallbackNumbers"}

    Shouldn't the fact that I'm adding those literals in the Resolve template be the same thing?


    anon28066628 | 2020-01-21 18:41:22 UTC | #9

    agilio, post:8, topic:6929
    "[$input.callbackNumbers]"

    That is likely the issue - the quotes outside the brackets shouldn't be there:

    "callbackNumbers": [$input.callbackNumbers]

    The quotes and commas inside the brackets come from your string concatenation. Careful with adding a trailing comma after the last list item; the json spec disallows that. Either avoid appending it or slice it off.

    ["A","B","C",] // bad

    ["A","B","C"] // good


    agilio | 2020-01-21 19:07:04 UTC | #10

    So I removed the quotes from outside the brackets. In my input I have this as the phone number ["+13125154609"] and I'm getting this error.

    REST call for action execute failed. Message:Request to backend service failed. Response from web service: {"status":400,"code":"bad.request","message":"The request could not be understood by the server due to malformed syntax.","contextId":"59d00521-1f47-4696-8bba-967bebf20829","details":[],"errors":[]} [86c31f97-db00-4c42-ac93-1ee9d195e723]


    Jason_Mathison | 2020-01-21 19:09:07 UTC | #11

    What does the resolved body look like now?


    agilio | 2020-01-21 19:30:29 UTC | #12

    "Request body is malformed. Error: Unexpected character ('1' (code 49)): was expecting comma to separate Object entries\n at [Source: (String)\"{\"queueId\": \"b8081e27-4c3d-4e91-9566-aa28b160d8fd\",\"callbackUserName\": \"test\",\"callbackNumbers\": \"[\"13125154609\"]\", \"callbackScheduledTime\": \"2020-01-21T13:23:00.000Z\",\"countryCode\": \"1\",\"validateCallbackNumbers\": \"true\"}\"; line: 1, column: 102]", "messageParams": {}, "contextId": "ba25a91d-b773-447b-b16a-3c962f5fc9ae",


    agilio | 2020-01-22 13:22:41 UTC | #14

    Morning. Any thoughts?


    Jason_Mathison | 2020-01-22 13:55:56 UTC | #15

    Looks like this might be down to a quote escaping issue. Please upload the current version of your data action.


    agilio | 2020-01-22 22:16:31 UTC | #16

    <a class="attachment" href="/forum/uploads/db6296/original/2X/6/682a0b104a39589e3063bff331f68ad19570140f.json">CallBackWithDateandTime-20200122161528.custom.json</a> (2.2 KB)

    Here is the latest


    Jason_Mathison | 2020-01-23 11:38:52 UTC | #17

    I tested this version far enough to make sure that it was sending valid JSON: <a class="attachment" href="/forum/uploads/db6296/original/2X/a/ab0109e9f43ebea6e8302453fb5aeca62cbb9f83.json">CallBackWithDateandTime---Exported-2020-01-22--1615-2020012363208.custom.json</a> (2.2 KB)

    I changed "callbackNumbers": "$input.callbackNumbers"

    to "callbackNumbers": [$input.callbackNumbers],

    The data action expects the callbackNumbers to be values like "13125154609" "13125154609","13125154608"


    agilio | 2020-01-23 16:50:38 UTC | #18

    Hi Jason,

    I imported the changes you made and this is the error I'm getting plus what I'm sending into the test REST call for action execute failed. Message:Request to backend service failed. Response from web service: {"status":400,"code":"bad.request","message":"A callback number cannot be parsed as a phone address","contextId":"15c76719-d53c-4ebc-ad75-fb31a6ffc827","details":[],"errors":[]} [e28a76a6-171d-4d10-962f-fab9cf3ae129]


    tim.smith | 2020-01-23 16:55:20 UTC | #19

    The data action expects the callbackNumbers to be values like..

    in the JSON payload. Remove the quotes from your input value. What you've entered creates this in JSON: "callbackNumbers": [ "\"13125154609\"" ]. The quotes inside the string aren't valid characters for a phone number.


    agilio | 2020-01-23 17:47:40 UTC | #20

    Sorry I'm still getting this error?

    REST call for action execute failed. Message:Request to backend service failed. Response from web service: {"status":400,"code":"bad.request","message":"A callback number cannot be parsed as a phone address","contextId":"4c913fc0-ada9-4782-81bf-5ddfd6fb3132","details":[],"errors":[]} [0704d185-960c-4f3a-a174-9f3c88b6e62a]


    tim.smith | 2020-01-23 18:01:52 UTC | #21

    Sorry, I misread the logs originally. You do need the quotes in the request as they're not in your template. The payload that's currently being sent is "callbackNumbers": [+13125154609]. The previous request had an error stating it couldn't parse an object for the callback number. Try again with the value "+13125154609" for callbackNumbers.


    agilio | 2020-01-23 18:17:28 UTC | #22

    Unfortunately no when I add the quotes I get this error

    Validate output against schema: JSON failed schema validation for the following reasons: Schema: # @/properties/callbackIdentifiers/items/0. Error location: /callbackIdentifiers/0. instance type (object) does not match any allowed primitive type (allowed: ["string"]), Schema: # @/properties/callbackIdentifiers/items/1. Error location: /callbackIdentifiers/1. instance type (object) does not match any allowed primitive type (allowed: ["string"])


    anon28066628 | 2020-01-24 15:40:34 UTC | #23

    Looks like the input schema expects a string, but is getting an object instead.

    Can you try escaping the quotes on your input string?

    Try again with the value "+13125154609"

    try:

    Try again with the value \\"+13125154609\\"


    Jason_Mathison | 2020-01-24 15:49:27 UTC | #24

    Hi agilio,

    I believe that the request to make a callback succeeded, the failure was in dealing with the output from that request. I took a crack at updating the output contract to match.

    <a class="attachment" href="/forum/uploads/db6296/original/2X/e/e991d8955b28a63ea903b8fa1ce32038d5c313a0.json">CallBackWithDateandTime---Exported-2020-01-22--1615---Exported-2020-01-23--632-20200124104739.custom.json</a> (2.5 KB)


    agilio | 2020-01-24 17:00:34 UTC | #25

    Thanks All! That seems to work.


    anon28066628 | 2020-01-24 17:25:43 UTC | #26

    I need to distinguish "input" from "output"... glad it's sorted out :)


    system | 2020-02-24 17:25:44 UTC | #27

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