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

Custom Action - How to pass only values in an array (rather than name:value pairs)

RussellJ
Deputy Chef II
Deputy Chef II

Hi

My first post here, so please be gentle ๐Ÿ˜€

This feels like an FAQ but after some searching on the forum I can't find what I'm looking for, so apologies in advance!

I'm creating a custom action (connecting to the Maxio application and creating a Subscription).

I've used the Guided Setup to create the custom action, which then needed some manual editing to get it to work. However I'm still stuck at one point.

There are two places in the JSON where I need to specify an array of objects.  The first is for a  list of "components" being passed, the second is for a list of "coupon_codes".

The JSON payload that works when calling the API directly (e.g. via Postman) looks like this...

components_screenshot.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(EDIT: In the original version I stated that this JSON was generated by the guided Setup - that's not correct.  This is sample JSON used when calling the Maxio API directly from another application).

The problem I have is with the coupon_codes section.  Whereas in the components section, there's the usual name:value pair arrangement for each value being passed in the array (e.g. "component_id" : 2413376) for the coupon_codes section (as you can see from the screenshot) this is just a simple list of values ("BAPUK20OFF", "Coupon2") with no "name" being passed each time.

So I'm stuck with how to represent this in the Custom Action schema.

If I edit the Request body parameters for the Action I can create a field of type called "coupon_code", but if I want to create fields "nested" underneath it then I have to supply both a field name and label... and the field name/label is then used in the resulting JSON.

As a second issue, when I edit the Request body parameters for the Action and add a List field I'm not then ALWAYS seeing that reflected in the Data section underneath.  (Might be unconnected with the issue).

I hope/expect it's something obvious that I just can't see for looking!

Any help would be much appreciated.

Thanks

Russell

1 ACCEPTED SOLUTION

gary1
Star Chef I
Star Chef I

Hi, welcome. If I'm understanding the issue correctly, you want to create a primitive array of strings, but the array defaults to an array of objects. You can update the object schema to match the below to create a primitive array of strings.

[
  {
    "label": "Coupon codes",
    "name": "coupon_codes",
    "type": "array",
    "optional": false,
    "of": "string" ## this defaults to "objects"
  }
]

 When assigning a value to coupon_codes, simply pass in a primitive array like this:

coupon_codes = "one,two,three".split(",")
## result = "coupon_codes": ["one", "two", "three"]

 

View solution in original post

4 REPLIES 4

gary1
Star Chef I
Star Chef I

Hi, welcome. If I'm understanding the issue correctly, you want to create a primitive array of strings, but the array defaults to an array of objects. You can update the object schema to match the below to create a primitive array of strings.

[
  {
    "label": "Coupon codes",
    "name": "coupon_codes",
    "type": "array",
    "optional": false,
    "of": "string" ## this defaults to "objects"
  }
]

 When assigning a value to coupon_codes, simply pass in a primitive array like this:

coupon_codes = "one,two,three".split(",")
## result = "coupon_codes": ["one", "two", "three"]

 

You sir, are bang on the money!  Schema updated as suggested and a little split fun, and it's now working as wanted.

The "of": "string" piece was the key. But I don't think (using the GUI) you can set this combination of array/string? And (until now) I lacked this precious knowledge, so was never going to hit upon it.

Is there any documentation on this topic (or related), or Forum posts, around creating custom actions and manual editing of the schema that's worth a read? Feels like the Guided Setup doesn't quite do the whole job here, so manual tweaking is necessary.

Thanks so much for a speedy and accurate reply!

Russell

gary1
Star Chef I
Star Chef I

Glad I could help!

This isn't possible in the GUI as far as I know.

Some actions (like function recipes) allow you to use JSON samples to automatically build the schema. I used {"test": ["a","b","c"]} as the sample, then checked the schema it generated to find "of": "string". I think "of" can be other standard type value like number, boolean, etc.

RussellJ
Deputy Chef II
Deputy Chef II

Thanks for the additional info ๐Ÿ‘