cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Passing Dynamic Name:Value pairs when making a Custom Action API call

RussellJ
Deputy Chef III
Deputy Chef III

I'm making a Custom Action API call to a target system (Maxio).

As part of this, I need to be able to pass two dynamically generated arrays of name:value pairs each time - one contains a list of restricted_products and the other a list of restricted_components.

When using the Guided Setup and supplying sample JSON for the Request Body like this...

JSON Restriction Grab.jpg

... Workato correctly passes the data onto the Target system which takes the necessary action.  So I know the JSON being passed in the intial setup is correct.

But then when I inspect the resulting Custom Action step in my Recipe, Workato has decided that the constituent product and component items which make up each of the arrays are fixed values.  The Request Body Parameters portion of the action looks like this...

Params.jpg

But the number and names of each product and component will vary each time.

How do I tell Workato that restricted_products are restricted_components are dynamic arrays, and pass in appropriate values?

Thanks in advance

6 REPLIES 6

gary1
Star Chef I
Star Chef I

I wrote a response and lost it somehow, so lets try this again:

First off, these are objects (hashes), not arrays!

When you have dynamic object content (meaning you may potentially have different keys in every instance of the same object), you can't pre-define them using object definitions because they don't have a standard definition. 

The easiest way to do what you need is to set the root objects (restricted_components and restricted_objects) to strings and feed them the constructed object contents via formula. When doing this they will behave as objects despite being defined as a strings. You can test this out in a normal variable to see what I mean.

However, there's a more important consideration: you're making a custom connector where the input to the connector is restricted to the expected input format of the API. That's kind of missing the point and not using the connector to its full potential.

Instead, you can pass the data into the connector in whatever format you want and let the connector construct the API call internally.

So instead of requiring input like this to match the API call:

{
  "restricted_products": {
    "key1": "value1",
    "key2": "value2",
    "key3": "value3"
  }
}

 You can pass a standard list (array) variable of key/value pairs like this:

{
  "restricted_products": [
    {
      "key": "key1",
      "value": "value1"
    },
    {
      "key": "key2",
      "value": "value2"
    },
    {
      "key": "key3",
      "value": "value3"
    }
  ]
}

Inside the connector, it's a cake walk to iterate the list and construct the API format.

RussellJ
Deputy Chef III
Deputy Chef III

Hi Gary

Thanks for your reply, although whilst I understood each of your words individually, I'm still not sure how to proceed ๐Ÿ˜”

Setting the root objects to strings and feeding them constructed objects for Workato to take care of sounds great.  But could you give me a pointer as to how to do that?  Iโ€™m starting from a comma separated string of values for both restricted_components and restricted_products .  I guess the bit Iโ€™m missing is โ€œhow to convert a comma separated string into objectsโ€.

Secondly (and this might be key to my confusion), I donโ€™t follow your statement โ€œyouโ€™re making a custom connectorโ€.  Iโ€™m not building a customer connector, but just using the OOTB Maxio Connector and using the Guided Setup to build a Custom *Action* (using a sample request)...?

Custom Action1.jpg

So whilst Iโ€™m sure youโ€™re making a valuable point about passing โ€œthe data into the connector in whatever format you want and let the connector construct the API call internallyโ€ I think you may be assuming too much about where Iโ€™m starting from?

Apologise for the noob questions!

Ah, my bad! My eyes read "custom action" and my brain said "custom connector, got it."

So the real question is "how do you create the formatted payload from a comma delimited string, and then plug it into the custom action?"

To answer that... I would need to see the string! Can you share an example?

 

RussellJ
Deputy Chef III
Deputy Chef III

Huzzah! I think weโ€™re on the same page.

The strings will just literally be of the format โ€œproduct1,product2โ€ and โ€œcomponent1,component2,component3โ€.

Theyโ€™ll each need a โ€œhandle:โ€ prefix and a value of true but Iโ€™m sure I could whizz up a tiny JS block (after your assistance on my last post) to turn that into objecty format.

The biggest mystery is how to configure the fields in the custom action.