Pass array as query parameter in Postman
Asked Answered
C

5

14

I am trying to pass an array as query parameter in Postman.

I am calling DELETE method to delete a user from list of databases. It is expecting list of database names as array in the query parameter. When I pass as given below, I am getting error.

{"code":2,"message":"data_services must be an array and not empty"}

Trying to Pass databasenames as array

Please let me know, how can I pass an array as query parameter in Postman.

Chaconne answered 3/3, 2020 at 7:4 Comment(2)
Can you post the DELETE method signature/ code?Waldenses
Sorry. I was wrong. I misread the DELETE method. It was expecting array in the content section. I have provided answer for clarityChaconne
C
3

I mis-read the DELETE method. It was expecting array of databases in the body of the Http body section, instead of on query parameter section. I provided the array as given below and it got succeeded.

The below is the way, I passed array to Http request in the body section.

Passing Array in the Http request content body

Chaconne answered 5/3, 2020 at 12:20 Comment(0)
O
29

You need to create 2 keys with the same name and add postfix [] enter image description here

enter image description here

enter image description here

Olander answered 11/2, 2022 at 11:7 Comment(0)
W
12

You can specify the parameter key multiple times with different values.
Don't use square brackets or numbers like an array in code.

This will result in a query string like so:

?data_services=somename&data_services=anothername
Waldenses answered 3/3, 2020 at 13:17 Comment(2)
no. it is not working out. Even if a specify a single value data_services=DBName, it is throwing same errorChaconne
Sorry for confusion caused. I have upvoted your answer. But, as my problem is different, I have added the answer for clarityChaconne
C
3

I mis-read the DELETE method. It was expecting array of databases in the body of the Http body section, instead of on query parameter section. I provided the array as given below and it got succeeded.

The below is the way, I passed array to Http request in the body section.

Passing Array in the Http request content body

Chaconne answered 5/3, 2020 at 12:20 Comment(0)
D
2

enter image description here

can you check below link it is useful for you

https://medium.com/@darilldrems/how-to-send-arrays-with-get-or-post-request-in-postman-f87ca70b154e

Diderot answered 4/3, 2020 at 6:0 Comment(1)
I have already tried it. Not working. mine is just list of databasename and not associative array.Chaconne
T
0

I learned today that you can also pass in a GET param as

some_end_point?param1=123456&data_services[0].param2:123456&data_services[0].param3:123456
Tiffanytiffi answered 20/6 at 22:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.