evendis / mandrill-rails

Webhook processing and event decoration to make using Mandrill with Rails just that much easier
MIT License
288 stars 36 forks source link

Can't use webhook with content-type application/json #44

Closed farhansalam closed 6 years ago

farhansalam commented 7 years ago

I can use it with x-www-form-urlencoded but not with json

tardate commented 7 years ago

@farhansalam need more information than that to help much. what are you trying to do? can you provide an example?

farhansalam commented 7 years ago

Sorry for not being clear, I am using this request via Postman which works fine

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "HTTP_X_MANDRILL_SIGNATURE: 7rUa4lNJitlb178MgGOcHO6T4Bg=" -H "Accept: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: 4898365b-dbc4-907a-621c-afd310eacc97" -d 'private_key=ntynTMaFpM_octE5R1DKAw&original_url=http://requestb.in/q9a918q9&mandrill_events=[{"event":"send"%2C"msg":{"ts":1365109999%2C"subject":"This an example webhook message"%2C"email":"example.webhook@mandrillapp.com"%2C"sender":"example.sender@mandrillapp.com"%2C"tags":["webhook-example"]%2C"opens":[{"ts":1365111111}]%2C"clicks":[{"ts":1365111111%2C"url":"http:\/\/mandrill.com"}]%2C"state":"sent"%2C"metadata":{"ename":"welcome email"%2C"etype":"First"%2C"uuuid":"random_uuid"%2C"nid":"noe-valley"%2C"recType":"geo"%2C"inNhd":1%2C"reminder":"reminder-1"%2C"src":"onboarding"}%2C"_id":"exampleaaaaaaaaaaaaaaaaaaaaaaaaa"%2C"_version":"exampleaaaaaaaaaaaaaaa"}%2C"ip":"127.0.0.1"%2C"location":{"country_short":"US"%2C"country":"United States"%2C"region":"Oklahoma"%2C"city":"Oklahoma City"%2C"latitude":35.4675598145%2C"longitude":-97.5164337158%2C"postal_code":"73101"%2C"timezone":"-05:00"}%2C"user_agent":"Mozilla\/5.0 (Macintosh%3B U%3B Intel Mac OS X 10.6%3B en-US%3B rv:1.9.1.8) Gecko\/20100317 Postbox\/1.1.3"%2C"user_agent_parsed":{"type":"Email Client"%2C"ua_family":"Postbox"%2C"ua_name":"Postbox 1.1.3"%2C"ua_version":"1.1.3"%2C"ua_url":"http:\/\/www.postbox-inc.com\/"%2C"ua_company":"Postbox%2C Inc."%2C"ua_company_url":"http:\/\/www.postbox-inc.com\/"%2C"ua_icon":"http:\/\/cdn.mandrill.com\/img\/email-client-icons\/postbox.png"%2C"os_family":"OS X"%2C"os_name":"OS X 10.6 Snow Leopard"%2C"os_url":"http:\/\/www.apple.com\/osx\/"%2C"os_company":"Apple Computer%2C Inc."%2C"os_company_url":"http:\/\/www.apple.com\/"%2C"os_icon":"http:\/\/cdn.mandrill.com\/img\/email-client-icons\/macosx.png"%2C"mobile":false}%2C"url":"http:\/\/mandrill.com"%2C"ts":1379233940}%2C{"event":"click"%2C"msg":{"ts":1365109999%2C"subject":"This an example webhook message"%2C"email":"example.webhook@mandrillapp.com"%2C"sender":"example.sender@mandrillapp.com"%2C"tags":["webhook-example"]%2C"opens":[{"ts":1365111111}]%2C"clicks":[{"ts":1365111111%2C"url":"http:\/\/mandrill.com"}]%2C"state":"sent"%2C"metadata":{"user_id":111}%2C"_id":"exampleaaaaaaaaaaaaaaaaaaaaaaaaa"%2C"_version":"exampleaaaaaaaaaaaaaaa"}%2C"ip":"127.0.0.1"%2C"location":{"country_short":"US"%2C"country":"United States"%2C"region":"Oklahoma"%2C"city":"Oklahoma City"%2C"latitude":35.4675598145%2C"longitude":-97.5164337158%2C"postal_code":"73101"%2C"timezone":"-05:00"}%2C"user_agent":"Mozilla\/5.0 (Macintosh%3B U%3B Intel Mac OS X 10.6%3B en-US%3B rv:1.9.1.8) Gecko\/20100317 Postbox\/1.1.3"%2C"user_agent_parsed":{"type":"Email Client"%2C"ua_family":"Postbox"%2C"ua_name":"Postbox 1.1.3"%2C"ua_version":"1.1.3"%2C"ua_url":"http:\/\/www.postbox-inc.com\/"%2C"ua_company":"Postbox%2C Inc."%2C"ua_company_url":"http:\/\/www.postbox-inc.com\/"%2C"ua_icon":"http:\/\/cdn.mandrill.com\/img\/email-client-icons\/postbox.png"%2C"os_family":"OS X"%2C"os_name":"OS X 10.6 Snow Leopard"%2C"os_url":"http:\/\/www.apple.com\/osx\/"%2C"os_company":"Apple Computer%2C Inc."%2C"os_company_url":"http:\/\/www.apple.com\/"%2C"os_icon":"http:\/\/cdn.mandrill.com\/img\/email-client-icons\/macosx.png"%2C"mobile":false}%2C"url":"http:\/\/mandrill.com"%2C"ts":1379233940}]' "http://localhost:3000/mandrill"

And the code reaches my event handler functions, but if I use header Content-Type: application/json the code never reaches my handler functions and i get 200OK response every time.

I am also not able to make simple post calls via rspec, the code never reaches the handler functions.

ducnguyenhuy-agilityio commented 6 years ago

It's because Mandrill sends a POST request with application/x-www-form-urlencoded as the content type.