How to send data in a post request with RestClient How to send data in a post request with RestClient curl curl

How to send data in a post request with RestClient


Change:

payload: {"param_1" => "1"})

To:

payload: '{"param_1": "1"})'

Also, specify the headers.

So, it becomes:

RestClient::Request.execute(method: :post,                            url: 'your_url',                            user: 'API_KEY',                            payload: '{"param_1": "1"}',                            headers: {"Content-Type" => "application/json"}                           )


Just Change:

payload: {"param_1" => "1"}

To:

payload: {"param_1" => "1"}.to_json

So, then it becomes:

RestClient::Request.execute(method: :post,                            url: 'your_url',                            user: 'API_KEY',                            payload: {"param_1" => "1"}.to_json,                            headers: {"Content-Type" => "application/json"}                           )


Turns out I had to add an argument to specify that my data was in a JSON format. The correct answer was something like this:RestClient::Request.execute(method: :post, url: URL, user: API_KEY, payload: '{"param_1": "1"}', headers: {"Content-Type" => "application/json"})