# Postmark Integration via LowCodeAPI

## Overview

Postmark is a fast and reliable email delivery service for transactional emails. The Postmark API provides comprehensive functionality for:

- **Email Sending** - Send transactional emails with templates or raw content
- **Batches** - Send multiple emails in a single API request
- **Templates** - Manage and use email templates with dynamic content
- **Statistics** - Retrieve email delivery statistics and information
- **Bounces** - Handle bounced email addresses
- **Server Management** - Manage email servers and configurations

## Base Endpoint

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

## Authentication

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

1. **Sign up** at [Postmark](https://postmarkapp.com) to get your Server API Token
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 Postmark API key
- Apply it to each request

**Auth Type**: API Key (X-Postmark-Server-Token header)

## API Categories

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

## Common Endpoints

### Category: Email

#### Send Email

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

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

**Description**: Send a single transactional email.

**Request Body**:
```json
{
  "From": "[email protected]",
  "To": "[email protected]",
  "Subject": "Welcome to our service",
  "HtmlBody": "<html><body><h1>Welcome!</h1><p>Thank you for signing up.</p></body></html>",
  "TextBody": "Welcome! Thank you for signing up.",
  "ReplyTo": "[email protected]",
  "Cc": "[email protected]",
  "Bcc": "[email protected]",
  "Tag": "welcome-email",
  "TrackOpens": true,
  "TrackLinks": "HtmlAndText"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `From` | string | Yes | The sender email address |
| `To` | string | Yes | Recipient email address |
| `Subject` | string | Yes | Email subject line |
| `HtmlBody` | string | No | HTML email body |
| `TextBody` | string | No | Plain text email body |
| `ReplyTo` | string | No | Reply-to address |
| `Cc` | string | No | CC recipient(s) |
| `Bcc` | string | No | BCC recipient(s) |
| `Tag` | string | No | Email tag for tracking |
| `TrackOpens` | boolean | No | Track email opens |
| `TrackLinks` | enum | No | Link tracking: None, HtmlOnly, TextOnly, HtmlAndText |
| `Headers` | array | No | Additional headers |
| "Attachments" | array | No | Email attachments |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/postmark/email?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "From": "[email protected]",
    "To": "[email protected]",
    "Subject": "Order Confirmation",
    "HtmlBody": "<html><body><h1>Order Confirmed</h1><p>Your order has been received.</p></body></html>",
    "TextBody": "Order Confirmed. Your order has been received."
  }'
```

**Official Documentation**: [Send Email](https://postmarkapp.com/developer/api/email-api)

---

#### Send Batch of Emails

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

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

**Description**: Send multiple emails in a single batch request (up to 500 emails).

**Request Body**:
```json
{
  "Messages": [
    {
      "From": "[email protected]",
      "To": "[email protected]",
      "Subject": "Email 1",
      "HtmlBody": "<html><body>Content 1</body></html>"
    },
    {
      "From": "[email protected]",
      "To": "[email protected]",
      "Subject": "Email 2",
      "HtmlBody": "<html><body>Content 2</body></html>"
    }
  ]
}
```

**Request Body Fields**:

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

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/postmark/email/batch?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "Messages": [
      {
        "From": "[email protected]",
        "To": "[email protected]",
        "Subject": "Welcome",
        "TextBody": "Welcome to our service!"
      },
      {
        "From": "[email protected]",
        "To": "[email protected]",
        "Subject": "Welcome",
        "TextBody": "Welcome to our service!"
      }
    ]
  }'
```

**Official Documentation**: [Send Batch](https://postmarkapp.com/developer/api/email-api#send-batch)

---

#### Send Email with Template

**Method**: `POST` | **LowCodeAPI Path**: `/email/withTemplate`

**Full URL**:
```
https://api.lowcodeapi.com/postmark/email/withTemplate?api_token={api_token}
```

**Description**: Send an email using a predefined template.

**Request Body**:
```json
{
  "From": "[email protected]",
  "To": "[email protected]",
  "TemplateId": 123456,
  "TemplateModel": {
    "name": "John Doe",
    "product": "Premium Plan",
    "date": "2024-01-15"
  },
  "Tag": "template-welcome"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `From` | string | Yes | Sender email address |
| `To` | string | Yes | Recipient email address |
| `TemplateId` | integer | Yes | Template ID or TemplateAlias |
| `TemplateModel` | object | Yes | Key-value pairs for template variables |
| `Tag` | string | No | Tag for tracking |
| `ReplyTo` | string | No | Reply-to address |
| `Cc` | string | No | CC recipients |
| `Bcc` | string | No | BCC recipients |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/postmark/email/withTemplate?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "From": "[email protected]",
    "To": "[email protected]",
    "TemplateId": 123456,
    "TemplateModel": {
      "name": "Jane Smith",
      "order_id": "ORD-12345"
    }
  }'
```

**Official Documentation**: [Send with Template](https://postmarkapp.com/developer/api/templates-api#send-with-template)

---

### Category: Statistics

#### Get Statistics

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

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

**Description**: Get email statistics for your server.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `tag` | string | No | Filter by tag |
| `fromdate` | string | No | Start date filter |
| `todate` | string | No | End date filter |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/postmark/stats?api_token=YOUR_API_TOKEN&tag=welcome-email"
```

**Official Documentation**: [Get Stats](https://postmarkapp.com/developer/api/stats-api)

---

#### Get Sent Counts

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

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

**Description**: Get counts of sent emails by type.

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

**Official Documentation**: [Get Sent Counts](https://postmarkapp.com/developer/api/stats-api)

---

### Category: Bounces

#### Get Bounces

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

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

**Description**: Get a list of bounces.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `type` | string | No | Filter by bounce type |
| `inactive` | boolean | No | Filter by inactive status |
| `emailFilter` | string | No | Filter by email address |
| `tag` | string | No | Filter by tag |
| `count` | integer | No | Number of results to return |
| `offset` | integer | No | Number of results to skip |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/postmark/bounces?api_token=YOUR_API_TOKEN&count=50&offset=0"
```

**Official Documentation**: [Get Bounces](https://postmarkapp.com/developer/api/bounces-api)

---

#### Get Bounce Details

**Method**: `GET` | **LowCodeAPI Path**: `/bounces/id`

**Full URL**:
```
https://api.lowcodeapi.com/postmark/bounces/id?id={id}&api_token={api_token}
```

**Description**: Get details about a specific bounce.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `id` | integer | Yes | Bounce ID |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/postmark/bounces/id?id=12345&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Bounce](https://postmarkapp.com/developer/api/bounces-api)

---

#### Activate Bounce

**Method**: `PUT` | **LowCodeAPI Path**: `/bounces/id/activate`

**Full URL**:
```
https://api.lowcodeapi.com/postmark/bounces/id/activate?id={id}&api_token={api_token}
```

**Description**: Reactivate a bounced email address.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `id` | integer | Yes | Bounce ID |

**Example Request**:
```bash
curl -X PUT "https://api.lowcodeapi.com/postmark/bounces/id/activate?id=12345&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Activate Bounce](https://postmarkapp.com/developer/api/bounces-api)

---

### Category: Templates

#### Get All Templates

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

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

**Description**: Get a list of all templates on the server.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `count` | integer | No | Number of results to return |
| `offset` | integer | No | Number of results to skip |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/postmark/templates?api_token=YOUR_API_TOKEN&count=50"
```

**Official Documentation**: [Get Templates](https://postmarkapp.com/developer/api/templates-api)

---

#### Create Template

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

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

**Description**: Create a new email template.

**Request Body**:
```json
{
  "Name": "Welcome Email",
  "Subject": "Welcome, {{name}}!",
  "HtmlBody": "<html><body><h1>Welcome {{name}}!</h1></body></html>",
  "TextBody": "Welcome {{name}}!",
  "Alias": "welcome-template"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `Name` | string | Yes | Template name |
| `Subject` | string | Yes | Email subject with template variables |
| `HtmlBody` | string | No | HTML body with template variables |
| `TextBody` | string | No | Plain text body with template variables |
| `Alias` | string | No | Friendly alias for the template |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/postmark/templates?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "Name": "Order Confirmation",
    "Subject": "Order {{order_id}} Confirmed",
    "HtmlBody": "<html><body><h1>Order {{order_id}}</h1></body></html>",
    "Alias": "order-confirmation"
  }'
```

**Official Documentation**: [Create Template](https://postmarkapp.com/developer/api/templates-api)

---

#### Delete Template

**Method**: `DELETE` | **LowCodeAPI Path**: `/templates/templateid`

**Full URL**:
```
https://api.lowcodeapi.com/postmark/templates/templateid?templateid={templateid}&api_token={api_token}
```

**Description**: Delete a specific template.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `templateid` | integer | Yes | Template ID |

**Example Request**:
```bash
curl -X DELETE "https://api.lowcodeapi.com/postmark/templates/templateid?templateid=123456&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Delete Template](https://postmarkapp.com/developer/api/templates-api)

---

### Category: Server

#### Get Server Information

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

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

**Description**: Get information about your server.

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

**Official Documentation**: [Get Server](https://postmarkapp.com/developer/api/server-api)

---

#### Edit Server Sending Configuration

**Method**: `PUT` | **LowCodeAPI Path**: `/server`

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

**Description**: Update server sending configuration.

**Request Body**:
```json
{
  "Name": "Production Server",
  "Color": "red",
  "RawEmailEnabled": true,
  "SmtpApiActivated": true,
  "InboundHookUrl": "https://example.com/inbound",
  "BounceHookUrl": "https://example.com/bounce",
  "OpenHookUrl": "https://example.com/open",
  "PostFirstOpenOnly": false,
  "TrackOpens": true,
  "TrackLinks": "HtmlAndText"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `Name` | string | No | Server name |
| `Color` | string | No | Server color code |
| `RawEmailEnabled` | boolean | No | Include raw email in webhook |
| `SmtpApiActivated` | boolean | No | Enable SMTP API |
| `InboundHookUrl` | string | No | Inbound webhook URL |
| `BounceHookUrl` | string | No | Bounce webhook URL |
| `OpenHookUrl` | string | No | Open webhook URL |
| `TrackOpens` | boolean | No | Track email opens |
| `TrackLinks` | enum | No | Link tracking option |

**Example Request**:
```bash
curl -X PUT "https://api.lowcodeapi.com/postmark/server?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "Name": "Production Email Server",
    "TrackOpens": true,
    "TrackLinks": "HtmlAndText"
  }'
```

**Official Documentation**: [Edit Server](https://postmarkapp.com/developer/api/server-api)

---

## Usage Examples

### Example 1: Send a Transactional Email

Send a single email with HTML and text versions:

```bash
# No ID needed - sends new email
curl -X POST "https://api.lowcodeapi.com/postmark/email?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "From": "[email protected]",
    "To": "[email protected]",
    "Subject": "Welcome to Our Service",
    "HtmlBody": "<html><body><h1>Welcome!</h1><p>Thank you for joining us.</p></body></html>",
    "TextBody": "Welcome! Thank you for joining us.",
    "Tag": "welcome-email",
    "TrackOpens": true
  }'
```

### Example 2: Send Batch Emails

Send multiple emails efficiently:

```bash
# No ID needed - sends batch of emails
curl -X POST "https://api.lowcodeapi.com/postmark/email/batch?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "Messages": [
      {
        "From": "[email protected]",
        "To": "[email protected]",
        "Subject": "Newsletter - Week 1",
        "HtmlBody": "<html><body>Weekly newsletter content</body></html>"
      },
      {
        "From": "[email protected]",
        "To": "[email protected]",
        "Subject": "Newsletter - Week 1",
        "HtmlBody": "<html><body>Weekly newsletter content</body></html>"
      }
    ]
  }'
```

### Example 3: Use Templates for Dynamic Content

Send emails using templates:

```bash
# Step 1: Create a template
# No ID needed - creates new template
curl -X POST "https://api.lowcodeapi.com/postmark/templates?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "Name": "Password Reset",
    "Subject": "Reset Your Password",
    "HtmlBody": "<html><body><a href=\"{{reset_url}}\">Reset Password</a></body></html>",
    "Alias": "password-reset"
  }'

# Step 2: Send email using the template
# No ID needed - sends with template
curl -X POST "https://api.lowcodeapi.com/postmark/email/withTemplate?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "From": "[email protected]",
    "To": "[email protected]",
    "TemplateAlias": "password-reset",
    "TemplateModel": {
      "reset_url": "https://example.com/reset?token=abc123"
    }
  }'
```

## Complete Endpoint Reference

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

- **OpenAPI Definition**: https://backend.lowcodeapi.com/postmark/definition
- **Official Postmark Documentation**: https://postmarkapp.com/developer/api

## Rate Limits & Best Practices

- **Rate Limit**: Refer to your Postmark plan
- **Best Practices**:
  - Always provide both HtmlBody and TextBody for better deliverability
  - Use templates for recurring email types (welcome, password reset, etc.)
  - Implement proper bounce handling to maintain sender reputation
  - Use tags to categorize and track email types
  - Set up webhooks for real-time delivery status updates
  - Keep individual emails under 10MB for attachments
  - Use batch API for sending multiple emails (max 500 per batch)

## Error Handling

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

Common error codes:
- **400**: Invalid request parameters
- **401**: Invalid API key
- **422**: Unprocessable entity
- **500**: Postmark server error