mailjet / mailjet-gem

[API v3] Mailjet official Ruby GEM

Home Page:https://dev.mailjet.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mailjet::Contact_managemanycontacts not working

MathieuDerelle opened this issue · comments

Mailjet::Contact_managemanycontacts.create(Contacts: [{Email: 'plop@plop.com'}])
Mailjet::ApiError: error 400 while sending #<RestClient::Resource:0x007ff9db02b110 @url="https://api.mailjet.com/v3/REST/contact/", @block=nil, @options={:public_operations=>[:post, :get], :read_only=>nil, :perform_api_call=>true, :user=>"X", :password=>"X", :content_type=>"application/json"}> to https://api.mailjet.com/v3/REST/contact/ with {"Contacts"=>[{"Email"=>"plop@plop.com"}]}

"{ \"ErrorInfo\" : \"\", \"ErrorMessage\" : \"Invalid json input: object \\\"\\\"->\\\"TContact\\\" has no property \\\"Contacts\\\"\", \"StatusCode\" : 400 }"

Please see https://dev.mailjet.com/guides/#status-codes for more informations on error numbers.


from /Users/mathieu/.rvm/gems/ruby-2.3.4/gems/mailjet-1.5.4/lib/mailjet/connection.rb:88:in `handle_exception'

(same error when using contacts)

the curl equivalent is working properly ...

curl -s -X POST \
--user "X:X" \
https://api.mailjet.com/v3/REST/contact/managemanycontacts \
-H 'Content-Type: application/json' \
-d '{"Contacts":[{"Email":"plop@plop.com"}]}'
{ "Count" : 1, "Data" : [{ "JobID" : 113869785 }], "Total" : 1 }

this gem is posting on /REST/contact/ instead of /REST/contact/managemanycontacts

Getting same error. What is the workaround, and will this be addressed?

Actually I encountered 2 issues:

  • there should be an and attributes[:id] at the end of this line otherwise indeed, the endpoint is stripped to /REST/contact/
  • my mailjet initializer was configured with config.api_version = 'v3.1' but calling the /REST/contact/managemanycontacts endpoint requires v3. As shown in the OP, the cURL request which works is with v3 in the URL, not v3.1. (i.e, calling api.mailjet.com/v3.1/REST/contact/managemanycontacts gives 404). This is really confusing. One would expect to always use the latest release available.