How to add subscribers to your Revue newsletter programmatically?
Tags: automation, python
Published: 2022-02-09 13:44:52

---
title: How to add subscribers to your Revue newsletter programmatically?
published: true
date: 2022-02-09 06:55:52 UTC
tags: Automation, Python
canonical_url: https://ireadblog.com/posts/89/how-to-add-subscribers-to-your-revue-newsletter-programmatically
---

# **Introduction**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7g5w67ouvyf2ylr40sl.png)

[Revue](https://getrevue.co/) makes it easy for writers and publishers to send editorial newsletters — and get paid. If you are looking to manage newsletters for your website, Revue is one of the best options out there, that too for free.


<p><u><strong>Fact</strong></u><strong>:</strong> iRead manages its newsletter using Revue. You can subscribe to&nbsp;<strong><a href="http://digests.ireadblog.com/" target="_blank">iRead Weekly Digests</a></strong> for free.</p>

Get started with Revue [here](https://getrevue.co) and register for free now.  
 

# **Why add subscribers programmatically?**

You might be thinking why should you add subscribers programmatically when users can themselves visit your newsletter page and subscribe themselves. Well, do you remember signing up for the newsletters on the shopping website you use? I don't think so. Still, when you sign up for an account on the site, you start receiving mails daily, weekly, or monthly. That's the use-case.

Consider a situation where you have a multi-user blogging platform like iRead. You have added an option for users to signup for newsletters at the bottom of the page. But users generally don't scroll till the end. How about adding the same functionality like the shopping website? When a new user registers on your website, you programmatically add the user to your Revue newsletter subscriber list. Isn't that amazing? Let's do it in the next step.  
 

# **How to add subscribers programmatically?**

Revue has made this process quite easy for us. Revue provides us with an API to manage it. Read their official API documentation [here](https://www.getrevue.co/api#overview). With this, you also get an API Key when you register for a free account on Revue. To find your API Key, log in to your Revue account. Then go to **Account Settings** and select the [**Integrations**](https://www.getrevue.co/app/integrations) tab. You'll find your API Key at the bottom of this page.

**<u>Note</u>:** If you don't know how to interact with APIs in Python, read this [tutorial](https://ireadblog.com/posts/77/python-api-tutorial-how-to-interact-with-web-services).

To continue with the coding part, you must have **requests** library installed. If not, you can install using the command:

```bash
pip install requests
```

 Additionally, you can also install **Rich** to beautify your terminal output. This is an optional step. To install Rich, use the command:

```bash
pip install rich
```

To learn more about Rich, read this [tutorial](https://ireadblog.com/posts/87/getting-rich-with-python).

Let's jump into the coding part now.

```py
import requests
from rich import print as rprint # Optional 

BASE_URL = 'https://www.getrevue.co/api'

API_KEY = 'add-your-api-key-here'

headers = {
    'Authorization': f'Token {API_KEY}'
}

data = {
    'email': 'user@domain.com',
    'first_name': 'Ashutosh',
    'last_name': 'Krishna', #Optional
    'double_opt_in': False # True if you wish to notify the user
}

response = requests.post(f'{BASE_URL}/v2/subscribers/',
                         headers=headers, json=data).json()

rprint(response)
# If you don't want to use Rich, comment the above line and uncomment the below line
# print(response)

```

As per the official API documentation of Revue, the base URL is  **`https://www.getrevue.co/api`**. To authenticate ourselves with the server, we need to add the API Key in the _header_ of the request as **`Token <API-KEY>`**. Further, we need to pass our data in JSON format. We can use [Python dictionaries](https://ireadblog.com/posts/84/everything-you-need-to-know-about-python-dictionaries) for the same. The **`email`** and `first_name` are mandatory fields. The `last_name` field is optional. The `double_opt_in` field means whether we wish to notify the users after they are added to our subscribers' list or not. If we don't wish to notify, we set it to _False_, else it is set to _True_, which is the default value too. Then we make a POST request on the `/v2/subscribers/` route as per the documentation with the headers and JSON data. We then print the JSON response we receive from the server either using [the print function provided by Rich](https://ireadblog.com/posts/87/getting-rich-with-python#how-to-rich-print) or the built-in print function. 

<u><strong>Output:</strong></u>

![](https://res.cloudinary.com/dlomjljb6/image/upload/v1/media/blog/uploads/2022/02/09/screenshot-2022-02-09-120953_ozgo3v)

# **Conclusion**

In this blog, we saw how we can programmatically add subscribers to our Revue newsletter. If you liked this post, you can consider [subscribing to my newsletter](https://www.getrevue.co/profile/ashutoshkrris).