Dharmanshu Kamra
Dharmanshu Kamra

Reputation: 613

How to use curl multipart form data to post array field from command line ?

Using curl request

curl -v -X PATCH -H "Content-Type:multipart/form-data" -H "Accept:application/json" -H "Auth-token:abcde" -F "first_name=snme" -F 'tags[]=chec' -F 'tags[]=chec2' http://example.com/api/users/1

I want to post tags as an array. So parsing the request i should get tags = ['check' , 'check2'] etc.

What I get now is {"tags[]" = "chec"}

Upvotes: 15

Views: 20352

Answers (3)

chris
chris

Reputation: 2863

For some server, you can use

curl -X POST -F 'tags=check1' -F 'tags=check2' 'http://example.com/api/users/1' -v

Upvotes: 2

Olexandr Minzak
Olexandr Minzak

Reputation: 176

For me on BASH is work like this:

curl -X POST -H 'Content-Type: multipart/form-data' -F "email="$EMAIL"" https://slack.com/api/users.admin.invite?token=$TOKEN&t=$DATE&first_name=$F1&last_name=$F2

Upvotes: -1

Swathi K
Swathi K

Reputation: 276

Try this:

   curl -X POST -d 'tags[]=check&tags[]=check2' 'http://example.com/api/users/1' -v

For multipart it should work with what you have tried:

   curl -X POST -F 'tags[]=check1' -F 'tags[]=check2' 'http://example.com/api/users/1' -v

Returns:

    {"tags":["chec","chec2"], ... }

Upvotes: 19

Related Questions