How to assign list to an array which is in the request of a REST API?

Hi Guys,

I'm trying to assign a list to the request which is taking array as input but I'm getting 400 error code saying bad request in a MOBILE APPLICATION.

This is my request pattern:

{

  "orderItems": [

    {

      "notes": "order item notes",

      "productFeatureIds": [

        "string"

      ],

      "productId": "string",

      "quantity": {

        "action": "ADD",

        "quantity": 1

      }

    }

  ]

}

 But the request that is going is this:

 "Request": {

      "OrderItems": {

        "List": [

         

        ],

        "EmptyListItem": {

          "ProductId": "5ef4c0d67c9403459b2bbc1a",

          "Quantity": {

            "Action": "ADD",

            "Quantity": "1"

          },

          "Notes": "",

          "ProductFeatureIds": {

            "List": [

             

            ],

            "EmptyListItem": ""

          }

        }

      }

    }

  }

}

I copied this from Network in devtools on browser. I saw a post about list append but didn't understand. Please help!!! 

Regards,

Vaishnavi

Hi Vaishnavi ,

Are you trying to compose api where you give and take request and response?


Regards

Rahul Sahu

Rahul Sahu wrote:

Hi Vaishnavi ,

Are you trying to compose api where you give and take request and response?


Regards

Rahul Sahu

 Hi Rahul,

    Yes I've consumed a POST REST API which takes the request as I mentioned. And I'm assigning the list to that request but it is giving 400 error code.


Regards

Vaishnavi

 

Hi Vaishnavi,

you are getting error because you data is not format as your request pattern.

Create a Structue with your request pattern and use this structure for request when you consume API provide inputs from this structure.


Regards

Rahul Sahu

Hi,


Please follow the below steps,

1. Create a structure from JSON request using "Add Structure from JSON"

2. Create a variable type of structure.

3. Assign required data into that variable using Assign widget

4. Call API and pass the variable in the request.


Thanks.