> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usesendly.app/llms.txt
> Use this file to discover all available pages before exploring further.

# cURL Integration

> Use Sendly API with cURL

## Authentication

All requests require the `Authorization` header with your API key:

```bash theme={null}
curl -H "Authorization: Bearer se_your_api_key" \
  https://api.usesendly.app/v1/emails
```

## Base URL

```
https://api.usesendly.app/v1
```

## Send an Email

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.usesendly.app/v1/emails \
    -H "Authorization: Bearer se_your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "from": "noreply@yourdomain.com",
      "to": "user@example.com",
      "subject": "Welcome!",
      "html": "<h1>Hello!</h1><p>Thanks for signing up.</p>"
    }'
  ```

  ```javascript SDK theme={null}
  import { Sendly } from '@sendlyapp/sdk'

  const client = new Sendly('se_your_api_key')

  await client.emails.send({
    from: 'noreply@yourdomain.com',
    to: 'user@example.com',
    subject: 'Welcome!',
    html: '<h1>Hello!</h1><p>Thanks for signing up.</p>'
  })
  ```
</CodeGroup>

## List Emails

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.usesendly.app/v1/emails?limit=20&sortOrder=desc \
    -H "Authorization: Bearer se_your_api_key"
  ```

  ```javascript SDK theme={null}
  const response = await client.emails.list({
    limit: 20,
    sortOrder: 'desc'
  })

  response.data.forEach(email => {
    console.log(`${email.to} - ${email.status}`)
  })
  ```
</CodeGroup>

## Get Email Status

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.usesendly.app/v1/emails/email_123 \
    -H "Authorization: Bearer se_your_api_key"
  ```

  ```javascript SDK theme={null}
  const email = await client.emails.get('email_123')
  console.log(`Status: ${email.status}`)
  ```
</CodeGroup>

## Create a Domain

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.usesendly.app/v1/domains \
    -H "Authorization: Bearer se_your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "domain": "mail.yourdomain.com"
    }'
  ```

  ```javascript SDK theme={null}
  const domain = await client.domains.create({
    domain: 'mail.yourdomain.com'
  })
  ```
</CodeGroup>

## Verify Domain

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.usesendly.app/v1/domains/mail.yourdomain.com/verify \
    -H "Authorization: Bearer se_your_api_key"
  ```

  ```javascript SDK theme={null}
  await client.domains.verify('mail.yourdomain.com')
  ```
</CodeGroup>

## List Domains

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.usesendly.app/v1/domains \
    -H "Authorization: Bearer se_your_api_key"
  ```

  ```javascript SDK theme={null}
  const response = await client.domains.list()
  ```
</CodeGroup>

## Create Webhook

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.usesendly.app/v1/webhooks \
    -H "Authorization: Bearer se_your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "url": "https://yourdomain.com/webhooks/sendly",
      "events": [
        "email.delivered",
        "email.bounced",
        "email.opened",
        "email.clicked"
      ]
    }'
  ```

  ```javascript SDK theme={null}
  const webhook = await client.webhooks.create({
    url: 'https://yourdomain.com/webhooks/sendly',
    events: [
      'email.delivered',
      'email.bounced',
      'email.opened',
      'email.clicked'
    ]
  })
  ```
</CodeGroup>

## Error Handling

Errors are returned with appropriate HTTP status codes:

```bash theme={null}
# 400 Bad Request
curl -X POST https://api.usesendly.app/v1/emails \
  -H "Authorization: Bearer se_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"from": "invalid"}'

# Response:
# {
#   "code": "INVALID_EMAIL",
#   "message": "The email address is invalid",
# }
```

## Save Response to File

```bash theme={null}
curl https://api.usesendly.app/v1/emails \
  -H "Authorization: Bearer se_your_api_key" \
  -o response.json
```

## Pretty Print JSON

```bash theme={null}
curl https://api.usesendly.app/v1/emails \
  -H "Authorization: Bearer se_your_api_key" | jq
```

## Common HTTP Methods

| Method | Purpose             |
| ------ | ------------------- |
| GET    | Retrieve data       |
| POST   | Create new resource |
| PATCH  | Update resource     |
| DELETE | Delete resource     |

## Resources

* [Full API Reference](/api-reference/introduction)
* [Best Practices](/best-practices)

***

Need help? Contact [support@usesendly.app](mailto:support@usesendly.app)
