0

I am trying to call comment-check with httparty and I am getting "Empty \"blog\" value" error even though i am passing blog params in the request. Below is the code

url = "https://my_akistmet_key.rest.akismet.com/1.1/comment-check"

payload = {
           :blog => "http://mysitename.com", 
           :comment_author => "Some Random User Name", 
           :comment_author_email => 'example_1@gmail.com',
           :comment_content=> "Any comment",
           :user_ip=> "A Valid user ip",
           :user_agent=> "A Valid User agent",
           :peramlink=> "A valid peramlink",
           :comment_type=> 'comment'
          }
response = HTTParty.post(url,
                        :body => payload.to_json, 
                        :headers => { 'Content-Type' => 'application/x-www-form-urlencoded'} 
                        )

Response

#<HTTParty::Response:0x55db6da493d8 parsed_response="Missing required field: blog.", @response=#<Net::HTTPOK 200 OK readbody=true>, @headers={"server"=>["nginx"], "date"=>["Wed, 16 Dec 2020 06:20:37 GMT"], "content-type"=>["text/plain; charset=utf-8"], "content-length"=>["29"], "connection"=>["close"], "x-akismet-debug-help"=>["Empty \"blog\" value"]}>


response.body
=> "Missing required field: blog."
Vishal
  • 7,113
  • 6
  • 31
  • 61
  • Explicit encoding of the payload to JSON along with `'Content-Type' => 'application/x-www-form-urlencoded'` looks quite weird - please check the documentation, I'd say you're just sending a bad request. – Konstantin Strukov Dec 16 '20 at 08:49
  • Yea. it was the mistake.. I was trying to take content type as json but it seems that API is not working with JSON. We must need to use `'Content-Type' => 'application/x-www-form-urlencoded'` – Vishal Dec 17 '20 at 04:52

0 Answers0