Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send simple object in cURL post request

I need to attach a simple object {foo:"bar"} to a x-www-form-urlencoded cURL post request. Notice the metadata tag in the example below: How do you encode an object like that? I realize it's not literal JSON, like I have in the request example below.

curl https://api.stripe.com/v1/transfers \ -u **********************: \ -d currency=usd \ -d description='This is a test' \ -d destination=************* \ -d metadata='{foo:"bar"}' \ -d amount=200

I've also tried %7B'foo'%3A'bar'%7D and foo=bar

The Stripe API response is always: { "error": { "type": "invalid_request_error", "message": "Invalid metadata: metadata must be a set of key-value pairs", "param": "metadata" } }

like image 582
user1791914 Avatar asked Mar 05 '26 07:03

user1791914


1 Answers

For anyone that has trouble with the nesting metadata, the answer is the following...

curl https://api.stripe.com/v1/transfers \ -u ************: \ -d currency=usd \ -d description='This is a test' \ -d destination=********* \ -d metadata[foo]=bar \ -d amount=200

like image 75
user1791914 Avatar answered Mar 08 '26 01:03

user1791914



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!