HTTP request with array body parameter

Issue

So, I need to send a HTTP request with a body parameter named items with the item inside which in turn has the parameters name and price of that specific item. It must be an array. I can’t get this specific part to work.

The structure should be something like this:

[
  {
    "items": {
      "product": {
        "price": 123,
        "name": "Robot"
      }
    }
  }
]

Here is the API which I’m trying to use:
https://hyros.docs.apiary.io/#reference/0/orders/create-order

I don’t need both workflows to work, they are just 2 different ways I’m trying to solve this problem.

Error message

Bad request - please check your parameters.

Workflows

I have made 2 similar workflows which have different outputs.

Workflow 1 is sending body parameter “items” as an array correctly, but I can’t get SET to give the name and price parameters to the body of the first item.
The first code is generating an object and using a function to turn it into an array. I could get the same output easier by just inserting an array directly into the HTTP request body, but I can’t get to set name and price either way.

Workflow 2 is sending body parameter “items” with the name and price parameters contained inside the first item, but as an object and not as an array, so it doesn’t work.

Workflow 1
SENDING ITEMS AS ARRAY BUT CAN’T SET NAME AND PRICE TO FIRST ITEM

Workflow 2
SENDING ITEMS AS OBJECT INSTEAD OF ARRAY

Output returned by the last node

From Workflow 1:
Missing required field Name for Item 1\",\"Missing required field Price for Item 1\
(Can’t get to set Name and Price parameters to Item 1)

From Workflow 2:
Missing required field: Items
(Can’t get to recognize the Set node output, should be an array)

SOLVED

It was right in front of me, in the documentation. The value must be an object inside an array.

{{[{"name":"TEST","price":123}]}}

Here is the solution for anyone who is going through the same:

5 Likes

Nice to see you have sorted it @turak :raised_hands:

@turak big thanks for posting + marking your solution. Super helpful :pray:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.