I'm trying to create a user on my rails app with a curl command from os x terminal. No matter how I format the data, the app returns a responses that non of my validations have passed.
curl http://localhost:3000/api/1/users.json -i -X POST -d {"user":{"first_name":"firstname","last_name":"lastname","email":"[email protected]","password":"app123","password_confirmation":"app123"}}"
I've tried every variation. I've tried using [] brackets, I've tried user={data..} and nothing seems to work. Any ideas?
To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option.
To post JSON data using Curl, you need to set the Content-Type of your request to application/json and pass the JSON data with the -d command line parameter. The JSON content type is set using the -H "Content-Type: application/json" command line parameter. JSON data is passed as a string.
Users can send data with the POST request using the -d flag. The following POST request sends a user and a pass field along with their corresponding values. POSTing with curl's -d option will include a default header that looks like: Content-Type: application/x-www-form-urlencoded .
First off, there is an extraneous " at the end of your command.
Try this
curl -v \ -H "Accept: application/json" \ -H "Content-type: application/json" \ -X POST \ -d ' {"user":{"first_name":"firstname","last_name":"lastname","email":"[email protected]","password":"app123","password_confirmation":"app123"}}' \ http://localhost:3000/api/1/users
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With