Are you looking to export your list of unsubscribers using the API? Here's a detailed guide to help you accomplish this. In this article, we outline 4 steps to export a file of unsubscribers from the past seven days, for example, from a specific DB.
Pre-Requisites
To perform an export via API, you’ll need an API account.
- If you requested an API account during the creation of your database, the credentials have already been provided to you.
- If not, or if you’ve forgotten your credentials, please contact your administrator to create access or reset the API password.
Note: Each database can have up to two API accounts (one with full access and one with restricted access).
👉 Learn more about managing your company's API accounts here.
❗Each step below includes links to our API documentation, where you’ll find parameter details, operator definitions, and additional customizations to meet your specific needs.❗
1. Authenticate Yourself
Start by retrieving your authentication token, also called a "Token."
👉 Learn how to authenticate here.
❗The next two steps are for initialisation only. There is no need to recreate the target for each export, you can reuse the one created the first time. ❗
2. Create a Target in the API
Use the following endpoint to create a target: POST api/{idsite}/Targets
👉 Detailed instructions are available here.
You have created a target but no filter has been defined.
So at this stage, the target is not yet usable and cannot appear in the target manager in the interface.
For the target to be valid, it must have at least one filter.
To create one, you can use the call corresponding to the type of filter you want.At this stage, the target is created but not yet usable. To make it functional, you must define at least one filter. For example, filters can be added based on specific fields.
3. Add Filters to the Target
👉 Learn how to add filters here.
To define your target’s population, use the following endpoint: POST api/{idsite}/targetfilters/{idTarget}/field
The 2 criteria to be inserted for our example are :
- Subscriber Status: Unsubscribed or manually unsubscribed (use
;
to indicate "OR"). - Unsubscription Date: it is less than 7 days old, to export unsubscribers from the last 7 days, for example
Here’s an example of the required parameters for these filters (replace XXXX
with your target ID):
{
"idTarget": XXXX,
"isEnabled": true,
"filters": [
{
"idField": 7,
"operator": 3,
"value": "1;2"
},
{
"idField": 4,
"operator": 11,
"value": "7"
}
]
}
4. Export the Target
Once the target is ready, use the following endpoint to export it:
POST api/{idsite}/exports/subscribers
This module allows you to export a list of email addresses along with their associated fields. Use the created target ID and specify additional parameters like the export file name, desired fields, SFTP location, encoding, and more.
👉 Find the list of required parameters here.
Once the API call has been set up, all you have to do is trigger it at the frequency chosen in the target.
In this example, we want to export unsubscribers from the last 7 days. You will therefore need to launch this call every 7 days.