Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contactdata trouble #36

Closed
AlexandreK38 opened this issue Feb 23, 2015 · 2 comments
Closed

Contactdata trouble #36

AlexandreK38 opened this issue Feb 23, 2015 · 2 comments

Comments

@AlexandreK38
Copy link

Hi,
I'am experiencing some trouble with the Contactdata.
Basically for a property 'language' with value 'en', I wrote :

Mailjet::Contactdata.create(:contact_id => contact.id, :data => [{"Name" => "language", "Value" => "en"}])

but an error is raised:

Mailjet::ApiError: error 400 while sending #<RestClient::Resource:0x00000101f373a0 @url="https://api.mailjet.com/v3/REST/contactdata", @block=nil, @options={:public_operations=>[:get, :put, :post, :delete], :read_only=>nil, :user=>"xxxxxx", :password=>"xxxxxxx"}> to https://api.mailjet.com/v3/REST/contactdata with {"ContactId"=>1, "Data"=>[{"Name"=>"language", "Value"=>"en"}]}

"{ \"ErrorInfo\" : \"\", \"ErrorMessage\" : \"Invalid json input: property \\\"Data[Name]\\\" not found at stream position 34\", \"StatusCode\" : 400 }"

Perhaps there is a problem with the way data are sent to the API : I have seen that the gem is sending using "application/x-www-form-urlencoded" content type, whereas in the mailjet api example they use json. Obvioulsy, when I tried with curl using the request made with the lib (url encoded), I got the same error, but if I tried with curl with json doing

curl -s -X POST --user "xxxxx:xxxxx" https://api.mailjet.com/v3/REST/contactdata -H 'Content-Type: application/json' -d '{"ContactID": 1, "Data" : [{"Name" : "language", "Value" : "en"}]}'

and it worked perfectly, as well as if I directly use RestClient as below

r = RestClient::Resource.new(Mailjet.config.end_point+'/'+Mailjet::Contactdata.resource_path,Mailjet.config.api_key, Mailjet.config.secret_key)
r.post({"ContactId" => contact.id, "Data" => [{"Name" => "language", "Value" => "en"}]}.to_json, :content_type => :json)

Is there a known problem, and why the gem isn't using json?
Thanks

@tylerjnap
Copy link
Contributor

Hi AlexandreK,

Sorry for the late response. We're currently in the process of looking into this. Will get back to you shortly once we recreate and fix this bug.

Best,

@tylerjnap
Copy link
Contributor

Hi AlexandreK,

The issue is fixed with the latest update to master branch. Seems the issue was what you were saying - not using JSON. Thank you for bringing this to our attention.

Best,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants