Product
Introducing: New newsletter action endpoints API
Mailjet is releasing a new newsletter API with ‘action’ endpoints. Management of your newsletter contents can now all be performed with ‘actions’.
PUBLISHED ON
‘Action’ Syntax
We are very excited to announce today that Mailjet is releasing ‘action’ endpoints for our newsletter resource. With this API update, the management of the newsletter contents -- scheduling, and testing of a newsletter -- can all be done with ‘actions’ on the newsletter object.
To begin, we are releasing four ‘actions’ to the newsletter endpoint:
Each of these ‘actions’ coupled with the newsletter API endpoint and the newsletter ID execute their respective functions. These new endpoints are as follows:
https://api.mailjet.com/v3/REST/newsletter/:id/detailcontent
https://api.mailjet.com/v3/REST/newsletter/:id/schedule
https://api.mailjet.com/v3/REST/newsletter/:id/send
https://api.mailjet.com/v3/REST/newsletter/:id/test All you do is substitute the ‘:id’ with the actual numerical ‘:id’ of the newsletter (i.e. http://api.mailjet.com/v3/REST/newsletter/3/detailcontent) and you ’re ready to start creating, testing, and sending newsletters!
/detailcontent
Allows you to manage the content of a newsletter -- i.e. creating, editing, or attaching the HTML or text part of it. You can create, update, view, and delete any content you make for a particular newsletter before sending it out. To do so, simply attach the content in a JSON packet in the body.
Sample code
Methods allowed
POST, GET, PUT, DELETE
Create Newsletter Content
To manage the newsletter content, perform a POST request with the ‘Text-part’ and ‘Html-part’ in a JSON structure. Keep in mind, if a POST request is done and one of the two aforementioned parameters is missing, it will delete the respective missing parameter for the particular newsletter you are manipulating. Use a PUT (see below) to avoid this -- there is no need to first POST content before updating, since only HTML or text are required.
Get Newsletter Content
To see the newsletter content, perform a GET request
This will return the following:
Update Newsletter Content
To update the the ‘Html-part’ or ‘Text-part’ of a newsletter, perform a PUT request with either the ‘Html-part’ or the ‘Text-part’. Unlike performing a POST request to this endpoint, if one of these is not included in the JSON structure, it will not be deleted. This allows for partial updates of newsletter content.
Delete Newsletter Content
/schedule
Allows you to schedule when the newsletter will be sent out. To schedule, simply attach the ISO 8601 date you wish the newsletter to be sent out at in a JSON packet in the body. You can also use “NOW” instead of a timestamp to send immediately. In that case, you can also use the send method, described below.
Before allowing the ‘/schedule’ method to go through, the API will check that all the pertinent newsletter information has already been created -- sender email, sender name, subject, contactlist, newsletter status, and HTML/text. If one of these is missing, the API will throw an error your way for you to correct and try again.
Sample code
Methods allowed
POST, DELETE
Schedule a Newsletter
To schedule a newsletter, perform a POST request with the ISO 8601 date you wish to send it out at:
Cancel a Newsletter
To cancel the sending of a newsletter, perform a DELETE:
/send
Allows you to send the newsletter. This API call is equivalent to using, as mentioned earlier, “NOW” as the timestamp in the ‘/schedule’ action endpoint.
Similar to ‘/schedule’, before allowing the ‘/send’ method to go through, the API will check that all pertinent newsletter information has already been created -- sender email, sender name, subject, contactlist, newsletter status, and HTML/text. If one of these is missing, the API will throw an error your way for you to correct and try again.
Sample code
Methods allowed
POST
Send a Newsletter Now
To send a newsletter immediately, perform a POST request:
/test
Allows you to test send the newsletter to an email address. This is to make sure you’ve “dotted all of the ‘i’s and crossed all of the ‘t’s” before sending your newsletter to the masses. To do so, simply add the name and email of the intended test email recipient in a JSON packet in the body.
Similar to ‘/schedule’ and ‘/send’, before allowing the ‘/test method to go through, the API will check that all the pertinent newsletter information has already been created for the newsletter -- sender email, sender name, subject, newsletter status, and HTML/text. If one of these is missing, the API will throw an error your way for you to correct and try again.
Sample code
Methods allowed
POST
Send a Test
To send a test newsletter, issue a POST request:
Documentation
You can check out all of the new additions to our ‘/newsletter’ documentation here.
FAQ
I already have "creating" and "sending" implemented via the API. What does this mean for me? Do I have to recode some software?
No, but you’re more than welcome to check out and implement our new ‘action’ endpoints. Most importantly, you don’t have to change any of your currently working software if you don’t wish to.
I still can’t find my API key and secret key. Where can I find them? You can find them here: https://app.mailjet.com/account/setup
By Tyler Nappy