Wednesday - last edited Wednesday
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...
... 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...
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
Wednesday
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.
Wednesday - last edited Wednesday
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)...?
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!
Wednesday
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?
Wednesday
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.