Prem
Prem

Reputation: 65

Ruby -> getting RestClient::UnprocessableEntity: 422 Unprocessable Entity

I have something as simple as this, and I get a error 422

irb(main):024:0> RestClient.post 'http://dev.myServer.es/api/register', '{"first_name": "John"}', :content_type=>'application/json'

RestClient::UnprocessableEntity: 422 Unprocessable Entity

However, when I run the same with Curl works OK:

curl --location "http://dev.myServer.es/api/register" -H 'Content-Type: application/json' -d '{"first_name": "John"}'


{"status": "OK"}

I am quite new to Ruby... but I don't know what I am missing?

Upvotes: 0

Views: 3107

Answers (1)

Keith Broughton
Keith Broughton

Reputation: 487

There's an example in the docs - https://github.com/rest-client/rest-client#usage-raw-url - which shows:

RestClient.post "http://example.com/resource", {'x' => 1}.to_json, {content_type: :json, accept: :json}

Try replacing:

:content_type=>'application/json'

in your call, with:

content_type: :json

Upvotes: 1

Related Questions