Sync Users to Marketing Audience
This endpoint fetches users from the database based on activity filters, creates a new audience in Resend, and adds the filtered users as contacts to that audience. There is also a GET method on this endpoint to preview the number of users that would be synced based on the filters, without actually creating an audience or syncing.Authentication
Both POST and GET methods require a secret API key (
MARKETING_API_SECRET
environment variable) passed as a Bearer token in the Authorization
header. This is not the standard user JWT token.POST Request (Sync Users)
Creates a Resend audience and adds users.Bearer token containing the secret marketing API key. Format:
Bearer YOUR_MARKETING_API_SECRET
The name for the new Resend audience. Defaults to “Audience [YYYY-MM-DD]”.
An optional description for the new Resend audience.
If
true
, only includes users considered active within the activeDays
period.If
filterActive
is true
, specifies the number of days to consider for recent activity (default: 30).POST Response
Indicates if the audience creation and contact addition were successful.
Details of the newly created Resend audience (e.g.,
id
, name
).The number of contacts successfully added to the audience.
A summary message of the operation.
GET Request (Preview Sync)
Checks how many users match the filters without performing the sync.Bearer token containing the secret marketing API key. Format:
Bearer YOUR_MARKETING_API_SECRET
If
true
, only counts users considered active within the activeDays
period.If
filterActive
is true
, specifies the number of days to consider for recent activity (default: 30).GET Response
Indicates if the count was successful.
The total number of users matching the specified filters.
An array containing a sample of the first 5 users matching the filters (includes
email
, full_name
, first_name
, last_name
).Error Codes
Status Code | Description |
---|---|
401 | Invalid or missing marketing API key. |
500 | Internal server error (e.g., fetching users failed, Resend API error). |
Code Examples
Notes
- Authorization: Uses a dedicated marketing API key, NOT user JWTs.
- POST: Creates a new audience each time it’s called and adds users.
- GET: Useful for checking the scope of a potential sync before executing it.
- Data Format: User data is formatted to match Resend’s contact requirements.
Body
application/json
The marketing platform to sync with
Example:
"mailchimp"
Optional list or audience ID for platforms that support multiple lists
Example:
"abc123def456"
The type of sync to perform
Available options:
all
, new
, specific
Example:
"all"
Array of user IDs to sync (required if sync_type is "specific")
Example:
["user1", "user2", "user3"]
Array of tags to apply to the synced users
Example:
["onlyautomator-user", "active"]