# Resend Integration via LowCodeAPI

## Overview

Resend is a modern email API platform for developers, providing transactional email services with powerful features for:

- **Email Sending** - Send transactional emails with HTML and text versions
- **Batches** - Send multiple emails in a single API request
- **Emails** - Retrieve and manage sent emails
- **Domains** - Manage domains and DNS configuration
- **API Keys** - Create and manage API credentials
- **Analytics** - Track email engagement and delivery

## Base Endpoint

```
https://api.lowcodeapi.com/resend/
```

## Authentication

LowCodeAPI handles authentication automatically using API Key authentication. You only need to:

1. **Sign up** at [Resend](https://resend.com) to get your API Key
2. **Connect your account** in the LowCodeAPI dashboard
3. **Use your `api_token`** in all requests

The `api_token` is your LowCodeAPI authentication token. LowCodeAPI will automatically:
- Fetch your Resend API key
- Apply it to each request as a Bearer token

**Auth Type**: Bearer Token

## API Categories

- **Transactional Email** - Email delivery and management

## Common Endpoints

### Category: Email

#### Send Email

**Method**: `POST` | **LowCodeAPI Path**: `/emails`

**Full URL**:
```
https://api.lowcodeapi.com/resend/emails?api_token={api_token}
```

**Description**: Send an email to one or multiple recipients.

**Request Body**:
```json
{
  "from": "[email protected]",
  "to": ["[email protected]"],
  "subject": "Order Confirmation",
  "html": "<html><body><h1>Order Confirmed</h1><p>Your order has been received.</p></body></html>",
  "text": "Order Confirmed. Your order has been received.",
  "cc": ["[email protected]"],
  "bcc": ["[email protected]"],
  "reply_to": ["[email protected]"],
  "attachments": [
    {
      "content": "base64_encoded_content",
      "filename": "invoice.pdf"
    }
  ],
  "tags": [
    {
      "name": "category",
      "value": "order_confirmation"
    }
  ]
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `from` | string | Yes | Sender email address |
| `to` | array | Yes | Recipient email addresses |
| `subject` | string | Yes | Email subject line |
| `html` | string | No | HTML email body |
| `text` | string | No | Plain text email body |
| `cc` | array | No | CC recipients |
| `bcc` | array | No | BCC recipients |
| `reply_to` | array | No | Reply-to addresses |
| `attachments` | array | No | Email attachments |
| `tags` | array | No | Email tags for tracking |
| `headers` | object | No | Custom headers |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/resend/emails?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "[email protected]",
    "to": ["[email protected]"],
    "subject": "Welcome to Our Service",
    "html": "<html><body><h1>Welcome!</h1><p>Thanks for signing up.</p></body></html>",
    "tags": [{"name": "category", "value": "welcome"}]
  }'
```

**Official Documentation**: [Send Email](https://resend.com/docs/api-reference/emails/send-email)

---

#### Retrieve Email

**Method**: `GET` | **LowCodeAPI Path**: `/emails/email_id`

**Full URL**:
```
https://api.lowcodeapi.com/resend/emails/email_id?email_id={email_id}&api_token={api_token}
```

**Description**: Retrieve a single email by ID.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `email_id` | string | Yes | Email ID to retrieve |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/resend/emails/email_id?email_id=abc123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Retrieve Email](https://resend.com/docs/api-reference/emails/retrieve-email)

---

### Category: Batch

#### Send Batch Emails

**Method**: `POST` | **LowCodeAPI Path**: `/emails/batch`

**Full URL**:
```
https://api.lowcodeapi.com/resend/emails/batch?api_token={api_token}
```

**Description**: Send multiple emails in a single batch request.

**Request Body**:
```json
{
  "payload": [
    {
      "from": "[email protected]",
      "to": ["[email protected]"],
      "subject": "Newsletter Week 1",
      "html": "<html><body>Newsletter content</body></html>"
    },
    {
      "from": "[email protected]",
      "to": ["[email protected]"],
      "subject": "Newsletter Week 1",
      "html": "<html><body>Newsletter content</body></html>"
    }
  ]
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `payload` | array | Yes | Array of email objects (max 100) |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/resend/emails/batch?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "payload": [
      {
        "from": "[email protected]",
        "to": ["[email protected]"],
        "subject": "Special Offer",
        "html": "<html><body>Exclusive offer just for you!</body></html>"
      },
      {
        "from": "[email protected]",
        "to": ["[email protected]"],
        "subject": "Special Offer",
        "html": "<html><body>Exclusive offer just for you!</body></html>"
      }
    ]
  }'
```

**Official Documentation**: [Send Batch](https://resend.com/docs/api-reference/emails/send-batch)

---

### Category: Domains

#### List Domains

**Method**: `GET` | **LowCodeAPI Path**: `/domains`

**Full URL**:
```
https://api.lowcodeapi.com/resend/domains?api_token={api_token}
```

**Description**: Get a list of all domains in your account.

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/resend/domains?api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [List Domains](https://resend.com/docs/api-reference/domains/list-domains)

---

#### Get Domain

**Method**: `GET` | **LowCodeAPI Path**: `/domains/domain_id`

**Full URL**:
```
https://api.lowcodeapi.com/resend/domains/domain_id?domain_id={domain_id}&api_token={api_token}
```

**Description**: Retrieve a single domain by ID.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `domain_id` | string | Yes | Domain ID to retrieve |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/resend/domains/domain_id?domain_id=domain_123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Domain](https://resend.com/docs/api-reference/domains/get-domain)

---

#### Add Domain

**Method**: `POST` | **LowCodeAPI Path**: `/domains`

**Full URL**:
```
https://api.lowcodeapi.com/resend/domains?api_token={api_token}
```

**Description**: Add a new domain to your account.

**Request Body**:
```json
{
  "name": "example.com",
  "region": "us-east-1"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `name` | string | Yes | Domain name |
| `region` | string | No | AWS region for the domain |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/resend/domains?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "mydomain.com",
    "region": "us-east-1"
  }'
```

**Official Documentation**: [Add Domain](https://resend.com/docs/api-reference/domains/add-domain)

---

#### Verify Domain

**Method**: `POST` | **LowCodeAPI Path**: `/domains/domain_id/verify`

**Full URL**:
```
https://api.lowcodeapi.com/resend/domains/domain_id/verify?domain_id={domain_id}&api_token={api_token}
```

**Description**: Verify domain DNS records.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `domain_id` | string | Yes | Domain ID to verify |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/resend/domains/domain_id/verify?domain_id=domain_123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Verify Domain](https://resend.com/docs/api-reference/domains/verify-domain)

---

#### Delete Domain

**Method**: `DELETE` | **LowCodeAPI Path**: `/domains/domain_id`

**Full URL**:
```
https://api.lowcodeapi.com/resend/domains/domain_id?domain_id={domain_id}&api_token={api_token}
```

**Description**: Delete a domain from your account.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `domain_id` | string | Yes | Domain ID to delete |

**Example Request**:
```bash
curl -X DELETE "https://api.lowcodeapi.com/resend/domains/domain_id?domain_id=domain_123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Delete Domain](https://resend.com/docs/api-reference/domains/delete-domain)

---

### Category: API Keys

#### List API Keys

**Method**: `GET` | **LowCodeAPI Path**: `/api-keys`

**Full URL**:
```
https://api.lowcodeapi.com/resend/api-keys?api_token={api_token}
```

**Description**: Get a list of all API keys.

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/resend/api-keys?api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [List API Keys](https://resend.com/docs/api-reference/api-keys/list-api-keys)

---

#### Create API Key

**Method**: `POST` | **LowCodeAPI Path**: `/api-keys`

**Full URL**:
```
https://api.lowcodeapi.com/resend/api-keys?api_token={api_token}
```

**Description**: Create a new API key.

**Request Body**:
```json
{
  "name": "Production API Key",
  "permission": "full_access"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `name` | string | Yes | API key name |
| `permission` | enum | Yes | Access level: full_access, basic_access |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/resend/api-keys?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production Key",
    "permission": "full_access"
  }'
```

**Official Documentation**: [Create API Key](https://resend.com/docs/api-reference/api-keys/create-api-key)

---

#### Delete API Key

**Method**: `DELETE` | **LowCodeAPI Path**: `/api-keys/api_key_id`

**Full URL**:
```
https://api.lowcodeapi.com/resend/api-keys/api_key_id?api_key_id={api_key_id}&api_token={api_token}
```

**Description**: Delete an API key.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `api_key_id` | string | Yes | API key ID to delete |

**Example Request**:
```bash
curl -X DELETE "https://api.lowcodeapi.com/resend/api-keys/api_key_id?api_key_id=key_123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Delete API Key](https://resend.com/docs/api-reference/api-keys/delete-api-key)

---

### Category: Analytics

#### Get Email Stats

**Method**: `GET` | **LowCodeAPI Path**: `/emails/stats`

**Full URL**:
```
https://api.lowcodeapi.com/resend/emails/stats?api_token={api_token}
```

**Description**: Get email engagement statistics.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | date | No | Start date for stats (YYYY-MM-DD) |
| `end_date` | date | No | End date for stats (YYYY-MM-DD) |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/resend/emails/stats?api_token=YOUR_API_TOKEN&start_date=2024-01-01&end_date=2024-01-31"
```

**Official Documentation**: [Email Stats](https://resend.com/docs/api-reference/emails/get-stats)

---

## Usage Examples

### Example 1: Send a Welcome Email

Send a new user welcome email:

```bash
# No ID needed - sends new email
curl -X POST "https://api.lowcodeapi.com/resend/emails?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "[email protected]",
    "to": ["[email protected]"],
    "subject": "Welcome to Our Platform!",
    "html": "<html><body><h1>Welcome aboard!</h1><p>Thanks for joining our platform.</p></body></html>",
    "text": "Welcome aboard! Thanks for joining our platform.",
    "tags": [{"name": "type", "value": "welcome"}]
  }'
```

### Example 2: Send Batch Newsletter

Send newsletter to multiple recipients:

```bash
# No ID needed - sends batch emails
curl -X POST "https://api.lowcodeapi.com/resend/emails/batch?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "payload": [
      {
        "from": "[email protected]",
        "to": ["[email protected]"],
        "subject": "Weekly Newsletter - Week 1",
        "html": "<html><body><h1>Weekly Update</h1><p>Here is what happened this week.</p></body></html>"
      },
      {
        "from": "[email protected]",
        "to": ["[email protected]"],
        "subject": "Weekly Newsletter - Week 1",
        "html": "<html><body><h1>Weekly Update</h1><p>Here is what happened this week.</p></body></html>"
      }
    ]
  }'
```

### Example 3: Manage Custom Domain

Set up and verify a custom sending domain:

```bash
# Step 1: Add a custom domain
# No ID needed - adds new domain
curl -X POST "https://api.lowcodeapi.com/resend/domains?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "mydomain.com",
    "region": "us-east-1"
  }'

# Step 2: Verify domain DNS records
# Replace DOMAIN_ID with actual domain ID from Step 1
curl -X POST "https://api.lowcodeapi.com/resend/domains/domain_id/verify?domain_id=DOMAIN_ID&api_token=YOUR_API_TOKEN"

# Step 3: Get domain details
# Replace DOMAIN_ID with actual domain ID
curl -X GET "https://api.lowcodeapi.com/resend/domains/domain_id?domain_id=DOMAIN_ID&api_token=YOUR_API_TOKEN"
```

## Complete Endpoint Reference

For a complete list of all 15 endpoints and their parameters, refer to:

- **OpenAPI Definition**: https://backend.lowcodeapi.com/resend/definition
- **Official Resend Documentation**: https://resend.com/docs/api-reference

## Rate Limits & Best Practices

- **Rate Limit**: Refer to your Resend plan
- **Best Practices**:
  - Always provide both HTML and text versions of email content
  - Use tags to categorize and track email types
  - Verify domain DNS records before sending from custom domains
  - Use batch API for sending multiple emails (max 100 per batch)
  - Keep attachments under 40MB
  - Implement proper error handling for rate limits
  - Use appropriate subject lines to avoid spam filters

## Error Handling

All responses are wrapped in a `data` key:
```json
{
  "data": {
    // Actual response from Resend
  }
}
```

Common error responses:
- **400**: Invalid request parameters
- **401**: Invalid API key
- **403**: Insufficient permissions
- **404**: Resource not found
- **422**: Validation error
- **429**: Rate limit exceeded
- **500**: Resend server error