# Create API key POST /api-keys Add a new API key to authenticate communications with Resend. ## Body Parameters The API key name. The API key can have full access to Resend's API or be only restricted to send emails. \* `full_access`: Can create, delete, get, and update any resource. \* `sending_access`: Can only send emails. Restrict an API key to send emails only from a specific domain. This is only used when the `permission` is set to `sending_access`. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.apiKeys.create({ name: 'Production' }); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->apiKeys->create([ 'name' => 'Production' ]); ``` ```python Python import resend resend.api_key = "re_123456789" params: resend.ApiKeys.CreateParams = { "name": "Production", } resend.ApiKeys.create(params) ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" params = { name: "Production" } Resend::ApiKeys.create(params) ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") params := &resend.CreateApiKeyRequest{ Name: "Production", } apiKey, _ := client.ApiKeys.Create(params) ``` ```rust Rust use resend_rs::{types::CreateApiKeyOptions, Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _api_key = resend .api_keys .create(CreateApiKeyOptions::new("Production")) .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); CreateApiKeyOptions params = CreateApiKeyOptions .builder() .name("Production").build(); CreateApiKeyResponse apiKey = resend.apiKeys().create(params); } } ``` ```bash cURL curl -X POST 'https://api.resend.com/api-keys' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' \ -d $'{ "name": "Production" }' ``` ```json Response { "id": "dacf4072-4119-4d88-932f-6202748ac7c8", "token": "re_c1tpEyD8_NKFusih9vKVQknRAQfmFcWCv" } ``` # Delete API key DELETE /api-keys/:api_key_id Remove an existing API key. ## Path Parameters The API key ID. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.apiKeys.remove('b6d24b8e-af0b-4c3c-be0c-359bbd97381e'); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->apiKeys->remove('b6d24b8e-af0b-4c3c-be0c-359bbd97381e'); ``` ```python Python import resend resend.api_key = "re_123456789" resend.ApiKeys.remove(api_key_id="b6d24b8e-af0b-4c3c-be0c-359bbd97381e") ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" Resend::ApiKeys.remove "b6d24b8e-af0b-4c3c-be0c-359bbd97381e" ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") client.ApiKeys.Remove("b6d24b8e-af0b-4c3c-be0c-359bbd97381e") ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); resend .api_keys .delete("b6d24b8e-af0b-4c3c-be0c-359bbd97381e") .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); resend.apiKeys().remove("b6d24b8e-af0b-4c3c-be0c-359bbd97381e"); } } ``` ```bash cURL curl -X DELETE 'https://api.resend.com/api-keys/b6d24b8e-af0b-4c3c-be0c-359bbd97381e' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```text Response HTTP 200 OK ``` # List API keys GET /api-keys Retrieve a list of API keys for the authenticated user. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.apiKeys.list(); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->apiKeys->list(); ``` ```python Python import resend resend.api_key = "re_123456789" resend.ApiKeys.list() ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" Resend::ApiKeys.list ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") keys, err := client.ApiKeys.List() ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _api_keys = resend.api_keys.list().await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); resend.apiKeys().list(); } } ``` ```bash cURL curl -X GET 'https://api.resend.com/api-keys' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "data": [ { "id": "91f3200a-df72-4654-b0cd-f202395f5354", "name": "Production", "created_at": "2023-04-08T00:11:13.110779+00:00" } ] } ``` # Create Audience POST /audiences Create a list of contacts. ## Body Parameters The name of the audience you want to create. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.audiences.create({ name: 'Registered Users' }); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->audiences->create([ 'name' => 'Registered Users' ]); ``` ```python Python import resend resend.api_key = "re_123456789" params: resend.Audiences.CreateParams = { "name": "Registered Users" } resend.Audiences.create(params) ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" Resend::Audiences.create({ name: "Registered Users" }) ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") params := &resend.CreateAudienceRequest{ Name: "Registered Users", } audience, err := client.Audiences.Create(params) ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _audience = resend.audiences.create("Registered Users").await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); CreateAudienceOptions params = CreateAudienceOptions .builder() .name("Registered Users").build(); CreateAudienceResponseSuccess data = resend.audiences().create(params); } } ``` ```bash cURL curl -X POST 'https://api.resend.com/audiences' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' \ -d $'{ "name": "Registered Users" }' ``` ```json Response { "object": "audience", "id": "78261eea-8f8b-4381-83c6-79fa7120f1cf", "name": "Registered Users" } ``` # Delete Audience DELETE /audiences/:audience_id Remove an existing audience. ## Path Parameters The Audience ID. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.audiences.remove('78261eea-8f8b-4381-83c6-79fa7120f1cf'); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->audiences->remove('78261eea-8f8b-4381-83c6-79fa7120f1cf'); ``` ```python Python import resend resend.api_key = "re_123456789" resend.Audiences.remove("78261eea-8f8b-4381-83c6-79fa7120f1cf") ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" Resend::Audiences.remove("78261eea-8f8b-4381-83c6-79fa7120f1cf") ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") removed, err := client.Audiences.Remove("78261eea-8f8b-4381-83c6-79fa7120f1cf") ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _deleted = resend .audiences .delete("78261eea-8f8b-4381-83c6-79fa7120f1cf") .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); RemoveAudienceResponseSuccess data = resend.audiences().remove("78261eea-8f8b-4381-83c6-79fa7120f1cf"); } } ``` ```bash cURL curl -X DELETE 'https://api.resend.com/audiences/78261eea-8f8b-4381-83c6-79fa7120f1cf' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "object": "audience", "id": "78261eea-8f8b-4381-83c6-79fa7120f1cf", "deleted": true } ``` # Retrieve Audience GET /audiences/:audience_id Retrieve a single audience. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.audiences.get('78261eea-8f8b-4381-83c6-79fa7120f1cf'); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->audiences->get('78261eea-8f8b-4381-83c6-79fa7120f1cf'); ``` ```python Python import resend resend.api_key = "re_123456789" resend.Audiences.get("78261eea-8f8b-4381-83c6-79fa7120f1cf") ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" Resend::Audiences.get("78261eea-8f8b-4381-83c6-79fa7120f1cf") ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") audience, err := client.Audiences.Get("78261eea-8f8b-4381-83c6-79fa7120f1cf") ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _audience = resend .audiences .get("78261eea-8f8b-4381-83c6-79fa7120f1cf") .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); GetAudienceResponseSuccess data = resend.audiences().get("78261eea-8f8b-4381-83c6-79fa7120f1cf"); } } ``` ```bash cURL curl -X GET 'https://api.resend.com/audiences/78261eea-8f8b-4381-83c6-79fa7120f1cf' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "object": "audience", "id": "78261eea-8f8b-4381-83c6-79fa7120f1cf", "name": "Registered Users", "created_at": "2023-10-06T22:59:55.977Z" } ``` # List Audiences GET /audiences Retrieve a list of audiences. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.audiences.list(); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->audiences->list(); ``` ```python Python import resend resend.api_key = "re_123456789" resend.Audiences.list() ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" Resend::Audiences.list ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") audiences, err := client.Audiences.List() ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _audiences = resend .audiences .list() .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); ListAudiencesResponseSuccess data = resend.audiences().list(); } } ``` ```bash cURL curl -X GET 'https://api.resend.com/audiences' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "object": "list", "data": [ { "id": "78261eea-8f8b-4381-83c6-79fa7120f1cf", "name": "Registered Users", "created_at": "2023-10-06T22:59:55.977Z" } ] } ``` # Create Contact POST /audiences/:audience_id/contacts Create a contact inside an audience. ## Body Parameters The email address of the contact. The Audience ID. The first name of the contact. The last name of the contact. The subscription status. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.contacts.create({ email: 'steve.wozniak@gmail.com', firstName: 'Steve', lastName: 'Wozniak', unsubscribed: false, audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf', }); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->contacts->create( audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf', [ 'email' => 'steve.wozniak@gmail.com', 'first_name' => 'Steve', 'last_name' => 'Wozniak', 'unsubscribed' => false ] ); ``` ```python Python import resend resend.api_key = "re_123456789" params: resend.Contacts.CreateParams = { "email": "steve.wozniak@gmail.com", "first_name": "Steve", "last_name": "Wozniak", "unsubscribed": False, "audience_id": "78261eea-8f8b-4381-83c6-79fa7120f1cf", } resend.Contacts.create(params) ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" params = { "email": "steve.wozniak@gmail.com", "first_name": "Steve", "last_name": "Wozniak", "unsubscribed": false, "audience_id": "78261eea-8f8b-4381-83c6-79fa7120f1cf", } Resend::Contacts.create(params) ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") params := &resend.CreateContactRequest{ Email: "steve.wozniak@gmail.com", FirstName: "Steve", LastName: "Wozniak", Unsubscribed: false, AudienceId: "78261eea-8f8b-4381-83c6-79fa7120f1cf", } contact, err := client.Contacts.Create(params) ``` ```rust Rust use resend_rs::{types::ContactData, Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let contact = ContactData::new("steve.wozniak@gmail.com") .with_first_name("Steve") .with_last_name("Wozniak") .with_unsubscribed(false); let _contact = resend .contacts .create("78261eea-8f8b-4381-83c6-79fa7120f1cf", contact) .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); CreateContactOptions params = CreateContactOptions.builder() .email("steve.wozniak@gmail.com") .firstName("Steve") .lastName("Wozniak") .unsubscribed(false) .audienceId("78261eea-8f8b-4381-83c6-79fa7120f1cf") .build(); CreateContactResponseSuccess data = resend.contacts().create(params); } } ``` ```bash cURL curl -X POST 'https://api.resend.com/audiences/78261eea-8f8b-4381-83c6-79fa7120f1cf/contacts' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' \ -d $'{ "email": "steve.wozniak@gmail.com", "first_name": "Steve", "last_name": "Wozniak", "unsubscribed": false }' ``` ```json Response { "object": "contact", "id": "479e3145-dd38-476b-932c-529ceb705947" } ``` # Delete Contact DELETE /audiences/:audience_id/contacts/:id Remove an existing contact from an audience. ## Path Parameters The Audience ID. The Contact ID. The Contact email. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); // Delete by contact id resend.contacts.remove({ id: '520784e2-887d-4c25-b53c-4ad46ad38100', audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf', }); // Delete by contact email resend.contacts.remove({ email: 'acme@example.com', audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf', }); ``` ```php PHP $resend = Resend::client('re_123456789'); // Delete by contact id $resend->contacts->remove( audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf', id: '520784e2-887d-4c25-b53c-4ad46ad38100' ); // Delete by contact email $resend->contacts->remove( '78261eea-8f8b-4381-83c6-79fa7120f1cf', 'acme@example.com' ); ``` ```python Python import resend resend.api_key = "re_123456789" # Delete by contact id resend.Contacts.remove( id="520784e2-887d-4c25-b53c-4ad46ad38100", audience_id="78261eea-8f8b-4381-83c6-79fa7120f1cf" ) # Delete by contact email resend.Contacts.remove( email="acme@example.com", audience_id="78261eea-8f8b-4381-83c6-79fa7120f1cf" ) ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" # Delete by contact id Resend::Contacts.remove( "78261eea-8f8b-4381-83c6-79fa7120f1cf", "520784e2-887d-4c25-b53c-4ad46ad38100" ) # Delete by contact email Resend::Contacts.remove( "78261eea-8f8b-4381-83c6-79fa7120f1cf", "acme@example.com" ) ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") // Delete by contact id removed, err := client.Contacts.Remove( "78261eea-8f8b-4381-83c6-79fa7120f1cf", "520784e2-887d-4c25-b53c-4ad46ad38100" ) // Delete by contact email removed, err := client.Contacts.Remove( "78261eea-8f8b-4381-83c6-79fa7120f1cf", "acme@example.com" ) ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); // Delete by contact id let _deleted = resend .contacts .delete_by_contact_id( "78261eea-8f8b-4381-83c6-79fa7120f1cf", "520784e2-887d-4c25-b53c-4ad46ad38100", ) .await?; // Delete by contact email let _deleted = resend .contacts .delete_by_email("78261eea-8f8b-4381-83c6-79fa7120f1cf", "acme@example.com") .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); // Delete by contact id resend.contacts().remove(ContactRequestOptions.builder() .id("520784e2-887d-4c25-b53c-4ad46ad38100") .audienceId("78261eea-8f8b-4381-83c6-79fa7120f1cf") .build()); // Delete by contact email resend.contacts().remove(ContactRequestOptions.builder() .email("acme@example.com") .audienceId("78261eea-8f8b-4381-83c6-79fa7120f1cf") .build()); } } ``` ```bash cURL # Delete by contact id curl -X DELETE 'https://api.resend.com/audiences/78261eea-8f8b-4381-83c6-79fa7120f1cf/contacts/520784e2-887d-4c25-b53c-4ad46ad38100' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' # Deleted by contact email curl -X DELETE 'https://api.resend.com/audiences/78261eea-8f8b-4381-83c6-79fa7120f1cf/contacts/acme@example.com' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "object": "contact", "contact": "520784e2-887d-4c25-b53c-4ad46ad38100", "deleted": true } ``` # Retrieve Contact GET /audiences/:audience_id/contacts/:id Retrieve a single contact from an audience. ## Path Parameters The Audience ID. The Contact ID. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.contacts.get({ id: 'e169aa45-1ecf-4183-9955-b1499d5701d3', audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf', }); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->contacts->get( audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf', id: 'e169aa45-1ecf-4183-9955-b1499d5701d3' ); ``` ```python Python import resend resend.api_key = "re_123456789" resend.Contacts.get( id="e169aa45-1ecf-4183-9955-b1499d5701d3", audience_id="78261eea-8f8b-4381-83c6-79fa7120f1cf" ) ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" Resend::Contacts.get( "e169aa45-1ecf-4183-9955-b1499d5701d3", "78261eea-8f8b-4381-83c6-79fa7120f1cf" ) ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") contact, err := client.Contacts.Get( "e169aa45-1ecf-4183-9955-b1499d5701d3", "78261eea-8f8b-4381-83c6-79fa7120f1cf" ) ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _contact = resend .contacts .get( "e169aa45-1ecf-4183-9955-b1499d5701d3", "78261eea-8f8b-4381-83c6-79fa7120f1cf", ) .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); GetContactOptions params = GetContactOptions.builder() .id("e169aa45-1ecf-4183-9955-b1499d5701d3") .audienceId("78261eea-8f8b-4381-83c6-79fa7120f1cf").build(); GetContactResponseSuccess data = resend.contacts().get(params); } } ``` ```bash cURL curl -X GET 'https://api.resend.com/audiences/78261eea-8f8b-4381-83c6-79fa7120f1cf/contacts/e169aa45-1ecf-4183-9955-b1499d5701d3' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "object": "contact", "id": "e169aa45-1ecf-4183-9955-b1499d5701d3", "email": "steve.wozniak@gmail.com", "first_name": "Steve", "last_name": "Wozniak", "created_at": "2023-10-06T23:47:56.678Z", "unsubscribed": false } ``` # List Contacts GET /audiences/:audience_id/contacts Show all contacts from an audience. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.contacts.list({ audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf', }); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->contacts->get( audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf' ); ``` ```python Python import resend resend.api_key = "re_123456789" resend.Contacts.list( audience_id="78261eea-8f8b-4381-83c6-79fa7120f1cf" ) ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" Resend::Contacts.list("78261eea-8f8b-4381-83c6-79fa7120f1cf") ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") contacts, err := client.Contacts.List("78261eea-8f8b-4381-83c6-79fa7120f1cf") ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _contacts = resend .contacts .list("78261eea-8f8b-4381-83c6-79fa7120f1cf") .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); ListContactsResponseSuccess data = resend.contacts().list("78261eea-8f8b-4381-83c6-79fa7120f1cf"); } } ``` ```bash cURL curl -X GET 'https://api.resend.com/audiences/78261eea-8f8b-4381-83c6-79fa7120f1cf/contacts' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "object": "list", "data": [ { "id": "e169aa45-1ecf-4183-9955-b1499d5701d3", "email": "steve.wozniak@gmail.com", "first_name": "Steve", "last_name": "Wozniak", "created_at": "2023-10-06T23:47:56.678Z", "unsubscribed": false } ] } ``` # Update Contact PATCH /audiences/:audience_id/contacts/:id Update an existing contact. ## Path Parameters The Audience ID. The Contact ID. ## Body Parameters The first name of the contact. The last name of the contact. The subscription status. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.contacts.update({ id: 'e169aa45-1ecf-4183-9955-b1499d5701d3', audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf', unsubscribed: true, }); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->contacts->update( audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf', id: 'e169aa45-1ecf-4183-9955-b1499d5701d3', [ 'unsubscribed' => true ] ); ``` ```python Python import resend resend.api_key = "re_123456789" params: resend.Contacts.UpdateParams = { "id": "e169aa45-1ecf-4183-9955-b1499d5701d3", "audience_id": "78261eea-8f8b-4381-83c6-79fa7120f1cf", "unsubscribed": True, } resend.Contacts.update(params) ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" params = { "id": "e169aa45-1ecf-4183-9955-b1499d5701d3", "audience_id": "78261eea-8f8b-4381-83c6-79fa7120f1cf", "unsubscribed": true, } Resend::Contacts.update(params) ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") params := &resend.UpdateContactRequest{ Id: "e169aa45-1ecf-4183-9955-b1499d5701d3", AudienceId: "78261eea-8f8b-4381-83c6-79fa7120f1cf", Unsubscribed: true, } contact, err := client.Contacts.Update(params) ``` ```rust Rust use resend_rs::{types::ContactChanges, Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let changes = ContactChanges::new().with_unsubscribed(true); let _contact = resend .contacts .update( "e169aa45-1ecf-4183-9955-b1499d5701d3", "78261eea-8f8b-4381-83c6-79fa7120f1cf", changes, ) .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); UpdateContactOptions params = UpdateContactOptions.builder() .audienceId("78261eea-8f8b-4381-83c6-79fa7120f1cf") .id("e169aa45-1ecf-4183-9955-b1499d5701d3") .unsubscribed(true) .build(); UpdateContactResponseSuccess data = resend.contacts().update(params); } } ``` ```bash cURL curl -X PATCH 'https://api.resend.com/audiences/78261eea-8f8b-4381-83c6-79fa7120f1cf/contacts/520784e2-887d-4c25-b53c-4ad46ad38100' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' \ -d $'{ "unsubscribed": true }' ``` ```json Response { "object": "contact", "id": "479e3145-dd38-476b-932c-529ceb705947" } ``` # Create Domain POST /domains Create a domain through the Resend Email API. ## Body Parameters The name of the domain you want to create. The region where emails will be sent from. Possible values: `us-east-1' | 'eu-west-1' | 'sa-east-1' | 'ap-northeast-1'` ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.domains.create({ name: 'example.com' }); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->domains->create([ 'name' => 'example.com' ]); ``` ```python Python import resend resend.api_key = "re_123456789" params: resend.Domains.CreateParams = { "name": "example.com", } resend.Domains.create(params) ``` ```ruby Ruby Resend.api_key = ENV["RESEND_API_KEY"] params = { name: "example.com", } domain = Resend::Domains.create(params) puts domain ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") params := &resend.CreateDomainRequest{ Name: "example.com", } domain, err := client.Domains.Create(params) ``` ```rust Rust use resend_rs::{types::CreateDomainOptions, Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _domain = resend .domains .add(CreateDomainOptions::new("example.com")) .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); CreateDomainOptions params = CreateDomainOptions .builder() .name("example.com").build(); CreateDomainResponse domain = resend.domains().create(params); } } ``` ```bash cURL curl -X POST 'https://api.resend.com/domains' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' \ -d $'{ "name": "example.com" }' ``` ```json Response { "id": "4dd369bc-aa82-4ff3-97de-514ae3000ee0", "name": "example.com", "created_at": "2023-03-28T17:12:02.059593+00:00", "status": "not_started", "records": [ { "record": "SPF", "name": "send", "type": "MX", "ttl": "Auto", "status": "not_started", "value": "feedback-smtp.us-east-1.amazonses.com", "priority": 10 }, { "record": "SPF", "name": "send", "value": "\"v=spf1 include:amazonses.com ~all\"", "type": "TXT", "ttl": "Auto", "status": "not_started" }, { "record": "DKIM", "name": "nhapbbryle57yxg3fbjytyodgbt2kyyg._domainkey", "value": "nhapbbryle57yxg3fbjytyodgbt2kyyg.dkim.amazonses.com.", "type": "CNAME", "status": "not_started", "ttl": "Auto" }, { "record": "DKIM", "name": "xbakwbe5fcscrhzshpap6kbxesf6pfgn._domainkey", "value": "xbakwbe5fcscrhzshpap6kbxesf6pfgn.dkim.amazonses.com.", "type": "CNAME", "status": "not_started", "ttl": "Auto" }, { "record": "DKIM", "name": "txrcreso3dqbvcve45tqyosxwaegvhgn._domainkey", "value": "txrcreso3dqbvcve45tqyosxwaegvhgn.dkim.amazonses.com.", "type": "CNAME", "status": "not_started", "ttl": "Auto" } ], "region": "us-east-1" } ``` # Delete Domain DELETE /domains/:domain_id Remove an existing domain. ## Path Parameters The Domain ID. ```js Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.domains.remove('d91cd9bd-1176-453e-8fc1-35364d380206'); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->domains->remove('d91cd9bd-1176-453e-8fc1-35364d380206'); ``` ```python Python import resend resend.api_key = "re_123456789" resend.Domains.remove(domain_id="d91cd9bd-1176-453e-8fc1-35364d380206") ``` ```ruby Ruby Resend.api_key = ENV["RESEND_API_KEY"] Resend::Domains.remove("d91cd9bd-1176-453e-8fc1-35364d380206") ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") removed, err := client.Domains.Remove("d91cd9bd-1176-453e-8fc1-35364d380206") ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _deleted = resend .domains .delete("d91cd9bd-1176-453e-8fc1-35364d380206") .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); RemoveDomainResponse removed = resend.domains().remove("d91cd9bd-1176-453e-8fc1-35364d380206"); } } ``` ```bash cURL curl -X DELETE 'https://api.resend.com/domains/d91cd9bd-1176-453e-8fc1-35364d380206' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "object": "domain", "id": "d91cd9bd-1176-453e-8fc1-35364d380206", "deleted": true } ``` # Retrieve Domain GET /domains/:domain_id Retrieve a single domain for the authenticated user. ## Path Parameters The Domain ID. Possible domain `status` return types include `"not_started"`, `"pending"`, `"verified"`, `"failure"`, and `"temporary_failure"`. You can read more about the statuses [here](https://resend.com/docs/dashboard/domains/introduction#understand-a-domain-status). ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.domains.get('d91cd9bd-1176-453e-8fc1-35364d380206'); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->domains->get('d91cd9bd-1176-453e-8fc1-35364d380206'); ``` ```python Python import resend resend.api_key = "re_123456789" resend.Domains.get(domain_id="d91cd9bd-1176-453e-8fc1-35364d380206") ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" Resend::Domains.get "d91cd9bd-1176-453e-8fc1-35364d380206" ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") retrievedDomain, err := client.Domains.Get("d91cd9bd-1176-453e-8fc1-35364d380206") ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _domain = resend .domains .get("d91cd9bd-1176-453e-8fc1-35364d380206") .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); Domain domain = resend.domains().get("d91cd9bd-1176-453e-8fc1-35364d380206"); } } ``` ```bash cURL curl -X GET 'https://api.resend.com/domains/d91cd9bd-1176-453e-8fc1-35364d380206' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "object": "domain", "id": "d91cd9bd-1176-453e-8fc1-35364d380206", "name": "example.com", "status": "not_started", "created_at": "2023-04-26T20:21:26.347412+00:00", "region": "us-east-1", "records": [ { "record": "SPF", "name": "send", "type": "MX", "ttl": "Auto", "status": "not_started", "value": "feedback-smtp.us-east-1.amazonses.com", "priority": 10 }, { "record": "SPF", "name": "send", "value": "\"v=spf1 include:amazonses.com ~all\"", "type": "TXT", "ttl": "Auto", "status": "not_started" }, { "record": "DKIM", "name": "resend._domainkey", "value": "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDsc4Lh8xilsngyKEgN2S84+21gn+x6SEXtjWvPiAAmnmggr5FWG42WnqczpzQ/mNblqHz4CDwUum6LtY6SdoOlDmrhvp5khA3cd661W9FlK3yp7+jVACQElS7d9O6jv8VsBbVg4COess3gyLE5RyxqF1vYsrEXqyM8TBz1n5AGkQIDAQA2", "type": "TXT", "status": "not_started", "ttl": "Auto" } ] } ``` # List Domains GET /domains Retrieve a list of domains for the authenticated user. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.domains.list(); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->domains->list(); ``` ```python Python import resend resend.api_key = "re_123456789" resend.Domains.list() ``` ```ruby Ruby Resend.api_key = ENV["RESEND_API_KEY"] Resend::Domains.list ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") domains, err := client.Domains.List() ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _domains = resend .domains .list() .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); ListDomainsResponse response = resend.domains().list(); } } ``` ```bash cURL curl -X GET 'https://api.resend.com/domains' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "data": [ { "id": "d91cd9bd-1176-453e-8fc1-35364d380206", "name": "example.com", "status": "not_started", "created_at": "2023-04-26T20:21:26.347412+00:00", "region": "us-east-1" } ] } ``` # Update Domain PATCH /domains/:domain_id Update an existing domain. ## Path Parameters The Domain ID. ## Body Parameters Track clicks within the body of each HTML email. Track the open rate of each email. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.domains.update({ id: 'b8617ad3-b712-41d9-81a0-f7c3d879314e', openTracking: false, clickTracking: true, tls: 'enforced', }); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->domains->update( 'b8617ad3-b712-41d9-81a0-f7c3d879314e', [ 'open_tracking' => false, 'click_tracking' => true, 'tls' => 'enforced', ] ); ``` ```python Python import resend resend.api_key = "re_123456789" params: resend.Domains.UpdateParams = { "id": "b8617ad3-b712-41d9-81a0-f7c3d879314e", "open_tracking": False, "click_tracking": True, "tls": "enforced", } resend.Domains.update(params) ``` ```ruby Ruby Resend.api_key = "re_123456789" Resend::Domains.update({ id: "b8617ad3-b712-41d9-81a0-f7c3d879314e", open_tracking: false, click_tracking: true, tls: "enforced", }) ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") updateDomainParams := &resend.UpdateDomainRequest{ OpenTracking: false, ClickTracking: true, Tls: resend.Enforced, } updated, err := client.Domains.Update("b8617ad3-b712-41d9-81a0-f7c3d879314e", updateDomainParams) ``` ```rust Rust use resend_rs::{types::{DomainChanges, Tls}, Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let changes = DomainChanges::new() .with_open_tracking(false) .with_click_tracking(true) .with_tls(Tls::Enforced); let _domain = resend .domains .update("b8617ad3-b712-41d9-81a0-f7c3d879314e", changes) .await?; Ok(()) } ``` ```java Java Resend resend = new Resend("re_123456789"); UpdateDomainOptions params = UpdateDomainOptions.builder() .id("b8617ad3-b712-41d9-81a0-f7c3d879314e") .openTracking(false) .clickTracking(true) .tls(Tls.ENFORCED) .build(); resend.domains().update(params); ``` ```bash cURL curl -X PATCH 'https://api.resend.com/domains/b8617ad3-b712-41d9-81a0-f7c3d879314e' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' \ -d $'{ "open_tracking": false, "click_tracking": true, "tls": "enforced" }' ``` ```json Response { "object": "domain", "id": "b8617ad3-b712-41d9-81a0-f7c3d879314e" } ``` # Verify Domain POST /domains/:domain_id/verify Verify an existing domain. ## Path Parameters The Domain ID. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.domains.verify('d91cd9bd-1176-453e-8fc1-35364d380206'); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->domains->verify('d91cd9bd-1176-453e-8fc1-35364d380206'); ``` ```python Python import resend resend.api_key = "re_123456789" resend.Domains.verify(domain_id="d91cd9bd-1176-453e-8fc1-35364d380206") ``` ```ruby Ruby Resend.api_key = ENV["RESEND_API_KEY"] Resend::Domains.verify("d91cd9bd-1176-453e-8fc1-35364d380206") ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") verified, err := client.Domains.Verify("d91cd9bd-1176-453e-8fc1-35364d380206") ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); resend .domains .verify("d91cd9bd-1176-453e-8fc1-35364d380206") .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); VerifyDomainResponse verified = resend.domains().verify("d91cd9bd-1176-453e-8fc1-35364d380206"); } } ``` ```bash cURL curl -X POST 'https://api.resend.com/domains/d91cd9bd-1176-453e-8fc1-35364d380206/verify' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "object": "domain", "id": "d91cd9bd-1176-453e-8fc1-35364d380206" } ``` # Cancel Email POST /emails/:id/cancel Cancel a scheduled email. ## Path Parameters The Email ID. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.emails.cancel('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794'); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->emails->cancel('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794'); ``` ```python Python import resend resend.api_key = "re_123456789" resend.Emails.cancel(email_id="49a3999c-0ce1-4ea6-ab68-afcd6dc2e794") ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" Resend::Emails.cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794") ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") canceled, err := client.Emails.Cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794") if err != nil { panic(err) } fmt.Println(canceled.Id) ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _canceled = resend .emails .cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794") .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); CancelEmailResponse canceled = resend .emails() .cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"); } } ``` ```bash cURL curl -X POST 'https://api.resend.com/emails/49a3999c-0ce1-4ea6-ab68-afcd6dc2e794/cancel' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "object": "email", "id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794" } ``` # Retrieve Email GET /emails/:id Retrieve a single email. ## Path Parameters The Email ID. ```js Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.emails.get('37e4414c-5e25-4dbc-a071-43552a4bd53b'); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->emails->get('37e4414c-5e25-4dbc-a071-43552a4bd53b'); ``` ```python Python import resend resend.api_key = "re_123456789" resend.Emails.get(email_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c") ``` ```ruby Ruby Resend.api_key = "re_123456789" email = Resend::Emails.get("4ef9a417-02e9-4d39-ad75-9611e0fcc33c") puts email ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") email, err := client.Emails.Get("4ef9a417-02e9-4d39-ad75-9611e0fcc33c") ``` ```rust Rust use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let _email = resend .emails .get("4ef9a417-02e9-4d39-ad75-9611e0fcc33c") .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); Email email = resend.emails().get("4ef9a417-02e9-4d39-ad75-9611e0fcc33c"); } } ``` ```bash cURL curl -X GET 'https://api.resend.com/emails/4ef9a417-02e9-4d39-ad75-9611e0fcc33c' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' ``` ```json Response { "object": "email", "id": "4ef9a417-02e9-4d39-ad75-9611e0fcc33c", "to": ["delivered@resend.dev"], "from": "Acme ", "created_at": "2023-04-03T22:13:42.674981+00:00", "subject": "Hello World", "html": "Congrats on sending your first email!", "text": null, "bcc": [null], "cc": [null], "reply_to": [null], "last_event": "delivered" } ``` # Send Batch Emails POST /emails/batch Trigger up to 100 batch emails at once. Instead of sending one email per HTTP request, we provide a batching endpoint that permits you to send up to 100 emails in a single API call. ## Body Parameters Sender email address. To include a friendly name, use the format `"Your Name "`. Recipient email address. For multiple addresses, send as an array of strings. Max 50. Email subject. Bcc recipient email address. For multiple addresses, send as an array of strings. Cc recipient email address. For multiple addresses, send as an array of strings. Reply-to email address. For multiple addresses, send as an array of strings. The HTML version of the message. The plain text version of the message. The React component used to write the message. *Only available in the Node.js SDK.* Custom headers to add to the email. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); await resend.batch.send([ { from: 'Acme ', to: ['foo@gmail.com'], subject: 'hello world', html: '

it works!

', }, { from: 'Acme ', to: ['bar@outlook.com'], subject: 'world hello', html: '

it works!

', }, ]); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->batch->send([ [ 'from' => 'Acme ', 'to' => ['foo@gmail.com'], 'subject' => 'hello world', 'html' => '

it works!

', ], [ 'from' => 'Acme ', 'to' => ['bar@outlook.com'], 'subject' => 'world hello', 'html' => '

it works!

', ] ]); ``` ```py Python import resend from typing import List resend.api_key = "re_123456789" params: List[resend.Emails.SendParams] = [ { "from": "Acme ", "to": ["foo@gmail.com"], "subject": "hello world", "html": "

it works!

", }, { "from": "Acme ", "to": ["bar@outlook.com"], "subject": "world hello", "html": "

it works!

", } ] resend.Batch.send(params) ``` ```rb Ruby require "resend" Resend.api_key = 're_123456789' params = [ { "from": "Acme ", "to": ["foo@gmail.com"], "subject": "hello world", "html": "

it works!

", }, { "from": "Acme ", "to": ["bar@outlook.com"], "subject": "world hello", "html": "

it works!

", } ] Resend::Batch.send(params) ``` ```go Go package examples import ( "fmt" "os" "github.com/resend/resend-go/v2" ) func main() { ctx := context.TODO() client := resend.NewClient("re_123456789") var batchEmails = []*resend.SendEmailRequest{ { From: "Acme ", To: []string{"foo@gmail.com"}, Subject: "hello world", Html: "

it works!

", }, { From: "Acme ", To: []string{"bar@outlook.com"}, Subject: "world hello", Html: "

it works!

", }, } sent, err := client.Batch.SendWithContext(ctx, batchEmails) if err != nil { panic(err) } fmt.Println(sent.Data) } ``` ```rust Rust use resend_rs::types::CreateEmailBaseOptions; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let emails = vec![ CreateEmailBaseOptions::new( "Acme ", vec!["foo@gmail.com"], "hello world", ) .with_html("

it works!

"), CreateEmailBaseOptions::new( "Acme ", vec!["bar@outlook.com"], "world hello", ) .with_html("

it works!

"), ]; let _emails = resend.batch.send(emails).await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); CreateEmailOptions firstEmail = CreateEmailOptions.builder() .from("Acme ") .to("foo@gmail.com") .subject("hello world") .html("

it works!

") .build(); CreateEmailOptions secondEmail = CreateEmailOptions.builder() .from("Acme ") .to("bar@outlook.com") .subject("world hello") .html("

it works!

") .build(); CreateBatchEmailsResponse data = resend.batch().send( Arrays.asList(firstEmail, secondEmail) ); } } ``` ```bash cURL curl -X POST 'https://api.resend.com/emails/batch' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' \ -d $'[ { "from": "Acme ", "to": ["foo@gmail.com"], "subject": "hello world", "html": "

it works!

" }, { "from": "Acme ", "to": ["bar@outlook.com"], "subject": "world hello", "html": "

it works!

" } ]' ```
```json Response { "data": [ { "id": "ae2014de-c168-4c61-8267-70d2662a1ce1" }, { "id": "faccb7a5-8a28-4e9a-ac64-8da1cc3bc1cb" } ] } ``` ## Limitations The `attachments`, `tags`, and `scheduled_at` fields are not supported yet. # Send Email POST /email Start sending emails through the Resend Email API. ## Body Parameters Sender email address. To include a friendly name, use the format `"Your Name "`. Recipient email address. For multiple addresses, send as an array of strings. Max 50. Email subject. Bcc recipient email address. For multiple addresses, send as an array of strings. Cc recipient email address. For multiple addresses, send as an array of strings. Schedule email to be sent later. The date should be in language natural (e.g.: `in 1 min`) or ISO 8601 format (e.g: `2024-08-05T11:52:01.858Z`). [See examples](/dashboard/emails/schedule-email) Reply-to email address. For multiple addresses, send as an array of strings. The HTML version of the message. The plain text version of the message. The React component used to write the message. *Only available in the Node.js SDK.* Custom headers to add to the email. Filename and content of attachments (max 40mb per email). [See examples](/dashboard/emails/attachments) Content of an attached file, passed as a buffer or base64 string. Name of attached file. Path where the attachment file is hosted Content type for the attachment, if not set will be derived from the filename property Custom data passed in key/value pairs. [See examples](/dashboard/emails/tags). The name of the email tag. It can only contain ASCII letters (a–z, A–Z), numbers (0–9), underscores (\_), or dashes (-). It can contain no more than 256 characters. The value of the email tag. It can only contain ASCII letters (a–z, A–Z), numbers (0–9), underscores (\_), or dashes (-). It can contain no more than 256 characters. ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); await resend.emails.send({ from: 'Acme ', to: ['delivered@resend.dev'], subject: 'hello world', html: '

it works!

', }); ``` ```php PHP $resend = Resend::client('re_123456789'); $resend->emails->send([ 'from' => 'Acme ', 'to' => ['delivered@resend.dev'], 'subject' => 'hello world', 'html' => '

it works!

' ]); ``` ```python Python import resend resend.api_key = "re_123456789" params: resend.Emails.SendParams = { "from": "Acme ", "to": ["delivered@resend.dev"], "subject": "hello world", "html": "

it works!

" } email = resend.Emails.send(params) print(email) ``` ```rb Ruby require "resend" Resend.api_key = "re_123456789" params = { "from": "Acme ", "to": ["delivered@resend.dev"], "subject": "hello world", "html": "

it works!

" } sent = Resend::Emails.send(params) puts sent ``` ```go Go import ( "fmt" "github.com/resend/resend-go/v2" ) func main() { ctx := context.TODO() client := resend.NewClient("re_123456789") params := &resend.SendEmailRequest{ From: "Acme ", To: []string{"delivered@resend.dev"}, Subject: "hello world", Html: "

it works!

" } sent, err := client.Emails.SendWithContext(ctx, params) if err != nil { panic(err) } fmt.Println(sent.Id) } ``` ```rust Rust use resend_rs::types::{CreateEmailBaseOptions}; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let from = "Acme "; let to = ["delivered@resend.dev"]; let subject = "hello world"; let html = "

it works!

"; let email = CreateEmailBaseOptions::new(from, to, subject) .with_html(html); let _email = resend.emails.send(email).await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); CreateEmailOptions params = CreateEmailOptions.builder() .from("Acme ") .to("delivered@resend.dev") .subject("hello world") .html("

it works!

") .build(); CreateEmailResponse data = resend.emails().send(params); } } ``` ```bash cURL curl -X POST 'https://api.resend.com/emails' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' \ -d $'{ "from": "Acme ", "to": ["delivered@resend.dev"], "subject": "hello world", "html": "

it works!

" }' ```
```json Response { "id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794" } ``` # Update Email PATCH /emails/:id Update a scheduled email. ## Path Parameters The Email ID. ## Body Parameters Schedule email to be sent later. The date should be in ISO 8601 format (e.g: 2024-08-05T11:52:01.858Z). ```ts Node.js import { Resend } from 'resend'; const resend = new Resend('re_123456789'); const oneMinuteFromNow = new Date(Date.now() + 1000 * 60).toISOString(); resend.emails.update({ id: '49a3999c-0ce1-4ea6-ab68-afcd6dc2e794', scheduledAt: oneMinuteFromNow, }); ``` ```php PHP $resend = Resend::client('re_123456789'); $oneMinuteFromNow = (new DateTime())->modify('+1 minute')->format(DateTime::ISO8601); $resend->emails->update('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794', [ 'scheduled_at' => $oneMinuteFromNow ]); ``` ```python Python import resend from datetime import datetime, timedelta resend.api_key = "re_123456789" one_minute_from_now = (datetime.now() + timedelta(minutes=1)).isoformat() update_params: resend.Emails.UpdateParams = { "id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", "scheduled_at": one_minute_from_now } resend.Emails.update(params=update_params) ``` ```ruby Ruby require "resend" Resend.api_key = "re_123456789" one_minute_from_now = (Time.now + 1 * 60).strftime("%Y-%m-%dT%H:%M:%S.%L%z") update_params = { "email_id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", "scheduled_at": one_minute_from_now } Resend::Emails.update(update_params) ``` ```go Go import "github.com/resend/resend-go/v2" client := resend.NewClient("re_123456789") oneMinuteFromNow := time.Now().Add(time.Minute * time.Duration(1)) oneMinuteFromNowISO := oneMinuteFromNow.Format("2006-01-02T15:04:05-0700") updateParams := &resend.UpdateEmailRequest{ Id: "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", ScheduledAt: oneMinuteFromNowISO } updatedEmail, err := client.Emails.Update(updateParams) if err != nil { panic(err) } fmt.Printf("%v\n", updatedEmail) ``` ```rust Rust use chrono::{Local, TimeDelta}; use resend_rs::types::UpdateEmailOptions; use resend_rs::{Resend, Result}; #[tokio::main] async fn main() -> Result<()> { let resend = Resend::new("re_123456789"); let one_minute_from_now = Local::now() .checked_add_signed(TimeDelta::minutes(1)) .unwrap() .to_rfc3339(); let update = UpdateEmailOptions::new() .with_scheduled_at(&one_minute_from_now); let _email = resend .emails .update("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", update) .await?; Ok(()) } ``` ```java Java import com.resend.*; public class Main { public static void main(String[] args) { Resend resend = new Resend("re_123456789"); String oneMinuteFromNow = Instant .now() .plus(1, ChronoUnit.MINUTES) .toString(); UpdateEmailOptions updateParams = UpdateEmailOptions.builder() .scheduledAt(oneMinuteFromNow) .build(); UpdateEmailResponse data = resend.emails().update("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", updateParams); } } ``` ```bash cURL curl -X PATCH 'https://api.resend.com/emails/49a3999c-0ce1-4ea6-ab68-afcd6dc2e794' \ -H 'Authorization: Bearer re_123456789' \ -H 'Content-Type: application/json' \ -d $'{ "scheduled_at": "2024-08-05T11:52:01.858Z" }' ``` ```json Response { "object": "email", "id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794" } ``` # Errors Troubleshoot problems with this comprehensive breakdown of all error codes. ## Error schema We use standard HTTP response codes for success and failure notifications, and our errors are further classified by type. ### `validation_error` * **Status:** 400 * **Message:** We found an error with one or more fields in the request. * **Suggested action:** The message will contain more details about what field and error we found. ### `missing_api_key` * **Status:** 401 * **Message:** Missing API key in the authorization header. * **Suggested action:** Include the following header in the request: `Authorization: Bearer YOUR_API_KEY`. ### `restricted_api_key` * **Status:** 401 * **Message:** This API key is restricted to only send emails. * **Suggested action:** Make sure the API key has `Full access` to perform actions other than sending emails. ### `validation_error` * **Status:** 403 * **Message:** You can only send testing emails to your own email address (`youremail@domain.com`). * **Suggested action:** In [Resend's Domain page](https://resend.com/domains), add and verify a domain for which you have DNS access. This allows you to send emails to addresses beyond your own. ### `not_found` * **Status:** 404 * **Message:** The requested endpoint does not exist. * **Suggested action:** Change your request URL to match a valid API endpoint. ### `invalid_attachment` * **Status:** 422 * **Message:** Attachment must have either a `content` or `path`. * **Suggested action:** Attachments must either have a `content` (strings, Buffer, or Stream contents) or `path` to a remote resource (better for larger attachments). ### `missing_required_field` * **Status:** 422 * **Message:** The request body is missing one or more required fields. * **Suggested action:** Check the error message to see the list of missing fields. ### `daily_quota_exceeded` * **Status:** 429 * **Message:** You have reached your daily email sending quota. * **Suggested action:** [Upgrade your plan](https://resend.com/settings/billing) to remove the daily quota limit or wait until 24 hours have passed to continue sending. ### `rate_limit_exceeded` * **Status:** 429 * **Message:** Too many requests. Please limit the number of requests per second. Or [contact support](https://resend.com/contact) to increase rate limit. * **Suggested action:** You should read the [response headers](./introduction#rate-limit) and reduce the rate at which you request the API. This can be done by introducing a queue mechanism or reducing the number of concurrent requests per second. If you have specific requirements, [contact support](https://resend.com/contact) to request a rate increase. ### `security_error` * **Status:** 451 * **Message:** We may have found a security issue with the request. * **Suggested action:** The message will contain more details. [Contact support](https://resend.com/contact) for more information. ### `application_error` * **Status:** 500 * **Message:** An unexpected error occurred. * **Suggested action:** Try the request again later. If the error does not resolve, check our status page for service updates. # Introduction Understand general concepts, response codes, and authentication strategies. ## Base URL The Resend API is built on **REST** principles. We enforce **HTTPS** in every request to improve data security, integrity, and privacy. The API does not support **HTTP**. All requests contain the following base URL: ``` https://api.resend.com ``` ## Authentication To authenticate you need to add an *Authorization* header with the contents of the header being `Bearer re_123456789` where `re_123456789` is your [API Key](https://resend.com/api-keys). ``` Authorization: Bearer re_123456789 ``` ## Response codes Resend uses standard HTTP codes to indicate the success or failure of your requests. In general, `2xx` HTTP codes correspond to success, `4xx` codes are for user-related failures, and `5xx` codes are for infrastructure issues. | Status | Description | | ------ | --------------------------------------- | | `200` | Successful request. | | `400` | Check that the parameters were correct. | | `401` | The API key used was missing. | | `403` | The API key used was invalid. | | `404` | The resource was not found. | | `429` | The rate limit was exceeded. | | `5xx` | Indicates an error with Resend servers. | Check [Error Codes](/api-reference/errors) for a comprehensive breakdown of all possible API errors. ## Rate limit The response headers describe your current rate limit following every request in conformance with the [IETF standard](https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-ratelimit-headers): | Header name | Description | | --------------------- | ------------------------------------------------------------------- | | `ratelimit-limit` | Maximum number of requests allowed within a window. | | `ratelimit-remaining` | How many requests you have left within the current window. | | `ratelimit-reset` | How many seconds until the limits are reset. | | `retry-after` | How many seconds you should wait before making a follow-up request. | The default maximum rate limit is **2 requests per second**. This number can be increased for trusted senders by request. After that, you'll hit the rate limit and receive a `429` response error code. To prevent this, we recommend reducing the rate at which you request the API. This can be done by introducing a queue mechanism or reducing the number of concurrent requests per second. If you have specific requirements, [contact support](https://resend.com/contact) to request a rate increase. ## FAQ At this moment, there are no pagination parameters since we don't provide a way to fetch data via API yet. We plan to add pagination capabilities in the future. Currently, there's no versioning system in place. We plan to add versioning via calendar-based headers in the future. # Introduction Visualize all the API Keys on the Resend Dashboard. ## What is an API Key API Keys are secret tokens used to authenticate your requests. They are unique to your account and should be kept confidential. ## Add API Key 1. Navigate to **API Keys** on the sidebar. 2. Click **Create API Key**. 3. Give your API Key a name. 4. Select **Full access** or **Sending access** as the permission. 5. If you select **Sending access**, you can choose the specific domain you want restrict access. Add API Key ## Understand API Key permissions There are two different permissions of API Keys: * **Full access**: allows the API Key to create, delete, get, and update any resource. * **Sending access**: allows the API Key to only send emails. With API Key permissions, Resend users can give each API Key different permissions, which can limit the damage that may be done both accidentally or maliciously. ## Seeing all API Keys You can see the **last time you used** an API Key. By having different color indicators, you can quickly scan and detect which API Keys are being used and which ones are not. View All API Keys ## Interacting with an inactive API Key In the event that an API Key **hasn't been used in the last 30 days**, we now advise users to consider deleting them to keep their accounts secure. View Inactive API Key ## Viewing an active API Key When visualizing an active API Key, you can see the **total number of requests** made and go to a separate Logs page to view them. View Active API Key # Introduction Learn how to add, update, retrieve, and remove contacts that you send Broadcasts to. Managing subscribers and unsubscribers is a critical part of any email implementation. It's important to respect your users' preferences and ensure that they're receiving the right emails at the right time. Resend Audiences allow you to group and manage your contacts in a simple and intuitive way. Audience ## Import Contacts You can add your Contacts to an Audience in 3 different ways: manually, CSV upload, or via API. To add contacts manually, first go to the [Audiences](https://resend.com/audiences) page, and click on **Add Contacts**. From there, click on **Add Manually**. ![Adding Contacts](https://mintlify.s3-us-west-1.amazonaws.com/resend/images/audiences-intro-6.png) You can then add either one, or multiple email addresses into the text field, separating multiple email addresses with commas. ![Adding Contacts Manually](https://mintlify.s3-us-west-1.amazonaws.com/resend/images/audiences-intro-7.png) To add contacts manually, head to the [Audiences](https://resend.com/audiences) page, and click on **Add Contacts**. From there, click on **Import CSV** and upload your CSV file from your file directory. ![Adding Contacts](https://mintlify.s3-us-west-1.amazonaws.com/resend/images/audiences-intro-6.png) After uploading your CSV file, you're able to map the fields you want to use. Currently, the supported mapping fields are `email`, `first_name`, `last_name`, and `unsubscribed`. Import Contacts via CSV Finally, click continue, review the contacts, and finish the upload. Instead of manually importing contacts, you can also add them programmatically. You can leverage one of the Resend SDKs (PHP, Python, Ruby, Go, Java, and cURL) to add contacts to your audience. Here are the links to the [Audience](/api-reference/audiences/create-audience) and [Contacts](/api-reference/contacts/create-contact) API References. Example using the Node.js SDK: ```ts import { Resend } from 'resend'; const resend = new Resend('re_123456789'); resend.contacts.create({ email: 'steve.wozniak@gmail.com', firstName: 'Steve', lastName: 'Wozniak', unsubscribed: false, audienceId: '78261eea-8f8b-4381-83c6-79fa7120f1cf', }); ``` ## Send emails to your Audience Audiences were designed to be used in conjunction with [Broadcasts](https://resend.com/broadcasts). You can send emails to your Audience by creating a new Broadcast and selecting the Audience you want to send it to. ![Send emails to your Audience](https://mintlify.s3-us-west-1.amazonaws.com/resend/images/audiences-intro-2.png) You can include the Unsubscribe Footer in your Broadcasts, which will be automatically replaced with the correct link for each contact. ![Unsubscribe Link](https://mintlify.s3-us-west-1.amazonaws.com/resend/images/audiences-intro-3.png) ## Automatic Unsubscribes When you send emails to your Audience, Resend will automatically handle the unsubscribe flow for you. If a contact unsubscribes from your emails, they will be skipped when sending a future Broadcast to this same audience. ![Automatic Unsubscribes](https://mintlify.s3-us-west-1.amazonaws.com/resend/images/audiences-intro-4.png) Learn more about managing your unsubscribe list [here](https://resend.com/docs/dashboard/audiences/managing-unsubscribe-list). # Managing Unsubscribed Contacts Learn how to check and remove recipients who have unsubscribed to your marketing emails. It's essential to update your contact list when someone unsubscribes to maintain a good sender reputation. This reduces the likelihood of your emails being marked as spam, and can also improve deliverability for any other marketing or transactional emails you send. When a contact unsubscribes from your emails, Resend will automatically handle the unsubscribe flow for you, and they will be skipped when sending the next Broadcast to that same audience. ## Checking Unsubcribed Contacts To see which contacts have unsubscribed, first navigate to the [Audiences page](https://resend.com/audiences). Then, select the Audience that you want to check. Click on the **All Statuses** filter next to the search bar, then select **Unsubscribed**. Managing Unsubscribe List # Introduction Send marketing emails efficiently without code. Broadcasts allow you to send email blasts to your customers using a WYSIWYG editor. You can use this to send email blasts such as: * Newsletters * Product Launches * Investor Updates * Promotions * Changelogs Our Broadcasts feature was made to enable your entire team to send email campaigns without having to ask for help from developers. ## No-Code Editor