mailjet / mailjet-gem

[API v3] Mailjet official Ruby GEM
https://dev.mailjet.com
Other
130 stars 72 forks source link

Unable to update Newsletter_detailcontent #52

Closed judemoutiez closed 8 years ago

judemoutiez commented 8 years ago

Hi everyone,

I'm trying to send a marketing campaign and am following the documentation.

First of all, my newsletter is not creating with a contact list, even though the ID I am inputing is valid.

Then, when I try to update Newsletter_detailcontent to add Html content, this issue is sent : NameError: undefined local variable or method `id' for #Mailjet::Newsletter_detailcontent:0x007ffb70a5a910

Here is my code :

    variable = Mailjet::Newsletter.create(locale: "en_US",sender: "Me",sender_email: "hello@lessuricates.fr",subject: "TEST",contacts_list_id: "$ID",title: "TEST CAMPAIGN")
    target = Mailjet::Newsletter_detailcontent.find(variable.id)
    target.update_attributes(html_part: "Hello <strong>world</strong>!",text_part: "Hello world!")
    test = Mailjet::Newsletter_send.create(id: variable.id)

Where am I mistaken ?

Also, what is the easiest way to add more "complex" html code as content instead of "one liners" like the hello world ?

Thanks !

WeshGuillaume commented 8 years ago

Hey @judemoutiez !

I added the id field that was missing in the appropriate resource. Thanks :) Can you ensure this works for you before I merge it into the master branch ?https://github.com/mailjet/mailjet-gem/blob/nlsend/lib/mailjet/resources/newsletter_send.rb#L10

Thanks, Guillaume :airplane:

judemoutiez commented 8 years ago

Hello @GuillaumeBadi , thanks for your answer !

I just tested on branch 'nlsend' and it seems that the issue remains, here is the full error

NameError: undefined local variable or method id' for #<Mailjet::Newsletter_detailcontent:0x007fb59720c9d0> /Library/Ruby/Gems/2.0.0/bundler/gems/mailjet-gem-94de887d6fde/lib/mailjet/resource.rb:286:inmethod_missing' /Library/Ruby/Gems/2.0.0/bundler/gems/mailjet-gem-94de887d6fde/lib/mailjet/resource.rb:203:in save' /Library/Ruby/Gems/2.0.0/bundler/gems/mailjet-gem-94de887d6fde/lib/mailjet/resource.rb:230:inupdate_attributes'

Thanks !

WeshGuillaume commented 8 years ago

Hey @judemoutiez !

I am just letting you know that I am currently working on that. :) Thank you for your patience.

Regards, Guillaume

WeshGuillaume commented 8 years ago

It should finally be working, can you confirm that on your side so I can merge to master ? :airplane: It works for me.

Best, Guillaume

judemoutiez commented 8 years ago

Hello @GuillaumeBadi , here is the error I get now :

"{ \"ErrorInfo\" : \"\", \"ErrorMessage\" : \"Invalid json input: object \"\"->\"TNewsLetterSend\" property \"Id\" is not a class property, but tkInt64\", \"StatusCode\" : 400 }"

Do you have an idea ? Is it on my side ?

WeshGuillaume commented 8 years ago

Ok I managed to spot the issue here.

inside the code, the id was sent during the post as a payload, and contacts_list_id was instead 'ContactsListId'. But anyway your code snippet should work now :)

Still on the NLSEND branch :)

Let me know if anything else blocks you

Best, Guillaume :airplane:

judemoutiez commented 8 years ago

I'll test this as soon as possible thanks !

WeshGuillaume commented 8 years ago

What about this one ? :) Did it work for you ?

Maroo-b commented 8 years ago

@GuillaumeBadi I faced the same issue described above when trying to add body to newletter ( http://dev.mailjet.com/guides/?ruby#prepare-a-newsletter)

For information I'm using the Github master version.

WeshGuillaume commented 8 years ago

Hey @Maroo-b ! Can you paste your code here so I can try to reproduce your error ?

Maroo-b commented 8 years ago

@GuillaumeBadi thanks for the fast reply :) , it's the same code from official documentation:

newsletter = Mailjet::Newsletter.create(locale: "en_US",sender: "MisterMailjet",sender_email: "test@test.com",subject: "Greetings from Mailjet",contacts_list_id: 1614627,title: "api test")

target = Mailjet::Newsletter_detailcontent.find(newsletter.id) target.update_attributes(html_part: "Hello <strong>world</strong>!",text_part: "Hello world!")

Error msg: undefined local variable or method `id' for #Mailjet::Newsletter_detailcontent:0x007ff794a640a8

WeshGuillaume commented 8 years ago

Can you try now ? I pushed it on master. I will do the release after a few tests

Maroo-b commented 8 years ago

@GuillaumeBadi the update is working now, thx :) I suggest to add a regression test for this case to avoid facing this bug again, is it possible ?

WeshGuillaume commented 8 years ago

You are 100% right, This was broken because of the last release, so I guess its time to add more tests :)