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

Need to get custom array from custom connector to a recipe step

bhavesh-patel
Deputy Chef III
Deputy Chef III

I have created a recipe. On step 2 I have used custom connector which get some api and perform some logic to create a custom array for me which I have declared inside the code.

Now I am unable to send this array as an output so I can use it on step 3 of recipe as an input. I want to use repeat action step to do some other stuff on this array.

How to achieve this?

I have tried the below thing as per document, but I guess it worked when the response is directly came from API and not for custom array created by me inside code:

output_fields: lambda do
          [
            {
              name: "star_wars",
              label: "Person's Height List",
              type: "array",
              of: "string"
            }
          ]
        end

Example of arrays: =>

height_array ["172", "167", "96", "202", "150", "178", "165", "97", "183", "182"]

comapny_id_array [1, 2, 3, 4 , 5, 10]

2 ACCEPTED SOLUTIONS

gary1
Executive Chef II
Executive Chef II

I checked one of my connectors and you're configuring the output field correctly. The issue may be related to how you're constructing the custom array, or how you're passing the custom array to your output.

Here's how I managed it:

Output field:

{
   "type": "array",
   "of": "string",
   "label": "List of Asset IDs to Download",
   "name": "list_of_asset_ids_to_download"
}

Sample API Output:

{"asset_items": [
   {"id": 1},
   {"id": 2},
   {"id": 3}
]}

Execute:

# API call
response = get("/api/v1/search?query=blahblahblah")
# create custom array and add it to response as a new key 
response[:list_of_asset_ids_to_download] = response['asset_items'].pluck('id')

Now I can access "list_of_asset_ids_to_download" as an array of strings data pill on the connector output, like this:

list_of_asset_ids_to_download:
   [
      8005903,
      8005899,
      8005896
   ]

Hope this helps!

View solution in original post

Thanks for helping me here.
 
What worked for me is to add my response into a new hash with the same key as given in output field name. In my example - height_array. Then it automatically picked up the array and gave it to output of the step.
 
My code for reference:
 
execute: lambda do |connection, input|
  # API Call from star wars free API
  all_people = get("https://swapi.dev/api/people")
  all_height_array = {
    "height_array" => all_people['results'].pluck('height')
  }
end,

output_fields: lambda do
  [
    {
      name: "height_array",
      label: "Height Array",
      type: "array",
      of: "string"
    },  
  ]
end

View solution in original post

2 REPLIES 2

gary1
Executive Chef II
Executive Chef II

I checked one of my connectors and you're configuring the output field correctly. The issue may be related to how you're constructing the custom array, or how you're passing the custom array to your output.

Here's how I managed it:

Output field:

{
   "type": "array",
   "of": "string",
   "label": "List of Asset IDs to Download",
   "name": "list_of_asset_ids_to_download"
}

Sample API Output:

{"asset_items": [
   {"id": 1},
   {"id": 2},
   {"id": 3}
]}

Execute:

# API call
response = get("/api/v1/search?query=blahblahblah")
# create custom array and add it to response as a new key 
response[:list_of_asset_ids_to_download] = response['asset_items'].pluck('id')

Now I can access "list_of_asset_ids_to_download" as an array of strings data pill on the connector output, like this:

list_of_asset_ids_to_download:
   [
      8005903,
      8005899,
      8005896
   ]

Hope this helps!

Thanks for helping me here.
 
What worked for me is to add my response into a new hash with the same key as given in output field name. In my example - height_array. Then it automatically picked up the array and gave it to output of the step.
 
My code for reference:
 
execute: lambda do |connection, input|
  # API Call from star wars free API
  all_people = get("https://swapi.dev/api/people")
  all_height_array = {
    "height_array" => all_people['results'].pluck('height')
  }
end,

output_fields: lambda do
  [
    {
      name: "height_array",
      label: "Height Array",
      type: "array",
      of: "string"
    },  
  ]
end