This article takes you through extracting data from Mandrill and loads it into Snowflake. If these instructions look cumbersome you can simplify the process of syncing data from Mandrill to Snowflake by using RudderStack, where the whole process will be handled by RudderStack and you can focus on what matters, the analysis of your data.
There’s a continually growing usage of services like Mandrill. Mandrill is a transactional email API for Mailchimp Users, and it is ideal for sending data-driven emails, including targeted and personalized one-to-one messages to your customers. But that traffic creates more data. How can you analyze the data you generate with Mandrill as part of your transactional email campaigns, on Snowflake?
In this article, we will use Mandrill’s API to access and extract e-mail related data and load it into Snowflake for further analysis. You will need to write the code to get the data and make sure that this process will run every time new data are generated.
How to Extract my data from Mandrill
There are two main methods to get our data from Mandrill, the first one is to pull data out from it and the second one is to ask Mandrill to push data to us whenever something of importance happens. We will see the difference between these two solutions and how we can access data from both.
In order to pull data from Mandrill, we need to access its HTTP API. As a Web API following the RESTful architecture principles, it can be accessed through HTTP. As a RESTful API, interacting with it can be achieved by using tools like CURL or Postman or by using HTTP clients for your favorite language or framework.
Mandrill maintains a number of officially supported clients or SDKs that you can use with your favorite language to access it without having to mess with the raw underlying HTTP calls. These are the following:
There are also a number of unofficial clients that you can use if you prefer. The complete list can be found here.
In this post, we will consider the more generic case of accessing the HTTP endpoints directly for our examples, but of course, you are free to use the client of your choice for your project.
Mandrill API Authentication
In order to use the Mandrill API, you first have to generate an API key through your MandrillApp account. When you have created the key you can use it to access the API.
You can actually have multiple keys per account something that adds versatility to the platform. In most cases with the Mandrill API, you make a POST call to access an endpoint with a JSON body containing the access key.
Mandrill rate limiting
API rate limiting with Mandrill is a bit of a more complicated matter than in most cases of APIs out there. The reason is that Mandrill is mainly an SMTP as a service platform, in most cases when we make a call to its API we do it in order to send an e-mail to someone, so rate limiting in the typical sense that we find it in web APIs does not apply in Mandrill.
What is actually happening, is that every Mandrill account has a reputation and an hourly quota, the main reason that rate limiting is a bit more complicated in Mandrill is that they need to take special care of pointing out and handling potential spammers.
So the hourly quota is affected by your reputation, if for example, you have a poor reputation then Mandrill will reduce the number of e-mails and consequently the API calls that you can do on a per hour basis, on the contrary, if you have an excellent reputation you will be able to make more calls. Free accounts can send up to 25 emails per hour.
If you want to find your hourly quota and reputation you will have to check your Dashboard in MandrillApp.
Users: Information about your account, for example here you can validate that your API key is valid.
This endpoint is used to send messages through the Mandrill API.
Information and operation about user-defined tags.
Rejects. Manage your email rejection list.
Whitelists. Manage your rejection whitelists.
Senders. Manage senders associated with your Mandrill account.
Get information about the URLs that are included in your e-mails.
Manage e-mail templates.
Webhooks. Manage webhooks for your account.
Subaccounts. Manage subaccounts.
Information about domains that have been configured for inbound delivery.
Run export jobs to retrieve data from your Mandrill account.
IPs. Information and operations about your dedicated IPs.
Information and operations about your custom metadata fields indexed for the account.
The above endpoints define the complete set of operations that we perform with Mandrill, in our case we care mainly about what data we can export so we will work with the export endpoint. Export jobs can be executed for the following data:
Export your rejection blacklist.
Export your rejection whitelist.
Export your activity history.
We assume that you would like to export your activity data. In order to do that you need to perform a POST request to the following endpoint:
Keep in mind that the base URL might change depending on the warehouse where your application is hosted. For this reason, we will mention only the endpoints and you will have to prepend the base URL for your case.
The body that we should post to the above end-point should look like this.