Comments (10)
Hi @judemoutiez and thank you for using Mailjet !
A simple way to create a contact through the API is to use contactslist/:id/managecontact
Once you created a list, and you know its ID, you can create a contact within that list by using the Mailjet::Contactslist_managecontact
class
Mailjet::Contactslist_managecontact.create(id: <your list id>, action: "addnoforce", email: "[email protected]", name: "Guillaume")
then you can check if it works via curl for example:
curl -X GET --user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" https://api.mailjet.com/v3/REST/contact/?contactslist=<you list id> | python -m json.tool
I hope it helped !
Regards,
Guillaume from Mailjet
from mailjet-gem.
Hi @judemoutiez !
Please let me know if you didn't manage to make it work on your side, I'd take some more time to help you on the implementation. Otherwise, could you please close the issue ?
Regards,
Guillaume;
from mailjet-gem.
Hi Guillaume !
Thanks for your answer
I used the solution you gave me and it appears to be working, but not every single time.
When I test the line in the console, I manage to create a user, and if I try to create another one right after with another mail & name, I get this error:
"{ "ErrorMessage" : "Object properties invalid", "StatusCode" : 400, "ErrorInfo" : { "Email" : "MJ08 Property email is invalid: MJ03 A non-empty value is required", "Action" : "Invalid action: " } }"
The same seems to be happening on the website
Do you have an idea on what is happening ?
Thanks !
from mailjet-gem.
Hi !
I can't reproduce your error ! Can you paste a code snippet so I can try it on my side ? Here's what I've done so far:
from mailjet-gem.
Hi !
Here is what I get in the console
Loading development environment (Rails 4.1.4)
irb(main):001:0> Mailjet::Contactslist_managecontact.create(id: 16, action: "addnoforce", email: "[email protected]", name: "Julien")
=> #<Mailjet::Contactslist_managecontact:0x00000007e02520 @attributes={"persisted"=>false, "id"=>16, "action"=>"addnoforce", "email"=>"[email protected]", "name"=>"Julien", "contact_id"=>1489758118}, @persisted=true>
irb(main):002:0> Mailjet::Contactslist_managecontact.create(id: 16, action: "addnoforce", email: "[email protected]", name: "Julienbis")
Mailjet::ApiError: error 400 while sending #<RestClient::Resource:0x00000007e51800 @url="https://api.mailjet.com/v3/REST/contactslist/16/managecontact", @block=nil, @options={:public_operations=>[:post], :read_only=>nil, :user=>"api key", :password=>"api secret", :content_type=>"application/json"}> to https://api.mailjet.com/v3/REST/contactslist/16/managecontact with {}
"{ \"ErrorMessage\" : \"Object properties invalid\", \"StatusCode\" : 400, \"ErrorInfo\" : { \"Email\" : \"MJ08 Property email is invalid: MJ03 A non-empty value is required\", \"Action\" : \"Invalid action: \" } }"
Please see http://api.mailjet.com/0.1/HelpStatus for more informations on error numbers.
Thanks !
from mailjet-gem.
Hey Julien !
It is indeed really confusing. I don't know if it comes from you account or the rails/mailjet compatibility.. I still can't get the same error on my side. What output do you get if you issue this line in the terminal:
(do it twice with a different email and a different name)
curl -s -X POST --user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" https://api.mailjet.com/v3/REST/contactslist/16/managecontact -H "Content-Type: application/json" -d '{"Action": "addnoforce", "Email": "[email protected]", "Name": "test github"}'
Thanks .
Guillaume ! :)
PS: remember not to publicly post your credentials (apikey/apisecret) ;)
from mailjet-gem.
Hey @judemoutiez !
I finally managed to reproduce your error. Thank you so much for the issue ! You might want to take a look at the rails_fix: branch. It looks like it fixes it. I just need to implement some more testing, but it should do the job !
Best,
Guillaume
from mailjet-gem.
Hello Guillaume !
Thank you very much, I'll have a loot at it :)
from mailjet-gem.
Hi @judemoutiez !
Please keep me up to date ! :)
Best,
Guillaume.
from mailjet-gem.
Works perfectly, thanks a lot !
from mailjet-gem.
Related Issues (20)
- "in-v3.mailjet.com" does not match the server certificate HOT 3
- How to get total count ? HOT 3
- Release new gem version HOT 1
- FATAL -- : [12421295-5b4a-4afa-828e-166f88779600] Net::OpenTimeout (execution expired): HOT 2
- Random 404 Errors HOT 1
- undefined method `merge' for nil:NilClass HOT 1
- Autoloading and Reloading Constants HOT 1
- error 400 while sending HOT 1
- Send a mail with template: error in template language HOT 1
- Rails integration causes an "Initialization autoloaded the constants ActionText::ContentHelper" warning HOT 1
- ActionMailer + Campaigns? HOT 1
- formatted_payload in resource.rb returns incomplete hash HOT 1
- Cannot change delivery method options after initialization of APIMailer HOT 2
- Setting `from` and `reply_to` to `nil` or `''` causes 400 Bad Request HOT 1
- Support for API v4 - SMS API HOT 2
- Possible bug in the `Mailjet::Send.create` method HOT 1
- Read only attribute causing NoMethodError (undefined method `map' for nil:NilClass) HOT 2
- I'm facing the same issue with just a basic hello world email template. HOT 1
- How to use Send API v3.1 and REST API v3 at the same time? HOT 1
- Remove password and API key from exception
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mailjet-gem.