Legacy Dev Forum Posts

 View Only

Sign Up

Using PureCloud Data Action witn Input Contract of Array

  • 1.  Using PureCloud Data Action witn Input Contract of Array

    Posted 06-05-2025 18:14

    agilio | 2018-11-12 16:52:37 UTC | #1

    Is there a way to create a dataaction that has an array as the Input Contract. We are trying to use the PureCloud API /api/v2/outbound/contactlists/{contactListId}/contacts to add contacts to a list. If so can you provide a sample of the input contract

    Thanks

    AG


    Jason_Mathison | 2018-11-12 18:01:36 UTC | #2

    Hi Agilo,

    The input contract for a data action is currently restricted to key-value pairs. You can request array support at https://purecloud.ideas.aha.io/

    If you are trying to add one contact at a time you could use the request template to put a single contact into an array.

    If you are doing this in the context of Architect you could loop through the contacts to build the list of contacts and pass the whole thing as a string into the data action.

    Finally, it might be possible to have multiple inputs into the data action and combine them into an array, however I have never tried to do that and I don't know if it is even possible.

    --Jason


    anon28066628 | 2018-11-12 18:37:06 UTC | #3

    Edit: Jason and I crossed over replies. "If you are doing this in the context of Architect you could loop through the contacts to build the list of contacts and pass the whole thing as a string into the data action." <-- yes, that :)

    Actions can't have array inputs at this time. The input contract must have simple key-value pairs only.

    If you need to send an array, you can configure a static number of inputs (say, 5 or 10), and then use the requestTemplate to structure those inputs into an array. Allow for more than you need, and assume the inputs not used will send empty strings.

    A bit more complex, but you can dynamically size the array. Suppose your data action has one input. With some creativity you can structure the string representation of a JSON array, and then plug that into your request template. For example, in Architect you might concatenate the strings "foo", "bar", and "baz" together as a single input string for your Data Action:

    "foo", "bar", "baz"

    Then the requestTemplate can include the structure around the string. Note that the additional double-quotes and commas must be literal parts of your string; the request template is an Apache Velocity template that deals with strings.

    Try this configuration (httpbin.org offers "echo" endpoints):

        // input contract
        {
          "$schema": "http://json-schema.org/draft-04/schema#",
          "type": "object",
          "properties": {"data": {"type": "string"}}
        }
        // request config
        {
          "requestUrlTemplate": "https://httpbin.org/post",
          "requestType": "POST",
          "headers": {},
          "requestTemplate": "{\"data\": [$input.data]}"
        }

    Then test the action with this input string:

    "foo", "bar", "baz"

    You should see the resolved body template:

    "{\"data\": [\"foo\", \"bar\", \"baz\"]}"

    And the Execute step from httpbin echos back (omitting some details):

    {
      "args": {},
      "data": "{\"data\": [\"foo\", \"bar\", \"baz\"]}",
      "files": {},
      "headers": {
        "Accept-Encoding": "gzip,deflate",
        "Connection": "close",
        "Content-Type": "application/json",
        "Host": "httpbin.org",
        "Transfer-Encoding": "chunked",
        "User-Agent": "PureCloud-Data-Actions"
      },
      "json": {
        "data": [
          "foo",
          "bar",
          "baz"
        ]
      },
      "url": "https://httpbin.org/post"
    }

    agilio | 2018-11-12 18:52:40 UTC | #4

    Here is the PureCloud API body how would you address this based on your example? Data is really a sub object so the validation erros.

    [{

    "data": { "RemoteName":"Test", "ANI":"Test", "DNIS":"Test", "OrderNumber":"", "CustomerNumber":"", "Notes":"", "Queue":"", "Date":"", "Time":""

    }, "callable": true }]

    Here is the base body from the api-explorer

    [{ "id": "", "contactListId": "", "data": {}, "callable": true, "phoneNumberStatus": {} }]


    anon28066628 | 2018-11-12 19:16:47 UTC | #5

    Assuming you're only adding one contact at a time with this method, your input schema should just be a string for each of your data fields (ANI, DNIS, OrderNumber, Queue, Date, etc.).


    agilio | 2018-11-12 21:58:32 UTC | #6

    Unfortunately the data action doesn't allow us to do that. When we try it won't allow sub-objects to be created. Were you able to test on your side to see what I'm referring too?

    Thanks

    AG


    anon28066628 | 2018-11-12 22:42:37 UTC | #7

    Hi Anthony, try importing this action as a custom webservice data dip action:

    <a class="attachment" href="/forum/uploads/db6296/original/2X/4/499c2d6d6d94c0f45e3990107550768357ee5217.json">Test---for-Anthony-20181112174156.custom.json</a> (1.0 KB)

    The resolution of the request template, given inputs "1234" and "5678" looks like this:

    "[{
    	"data": {
    		"OrderNumber": "1234",
    		"CustomerNumber": "5678"
    	},
    	"callable": true
    }]"

    Note that the template must be properly escaped.


    agilio | 2018-11-12 23:16:21 UTC | #8

    Ahhh this makes sense now. Testing looks good thanks for you help!

    Anthony


    system | 2018-12-13 23:30:10 UTC | #9

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