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

# Node.js SDK

> Node.js library documentation for the Amisend API.

## Installation

<CodeGroup>
  ```bash npm theme={null}
  npm install --save amisend
  ```

  ```bash yarn theme={null}
  yarn add amisend
  ```
</CodeGroup>

### Authentication

Create an account at [amisend](https://amisend.com) and get your **API Key**.

```js theme={null}
// CommonJS
const Amisend = require("amisend");

// ES6 / Typescript
import Amisend from "amisend";

const amisend = new Amisend({
  apiKey: "YOUR_API_KEY",
});
```

## Emails

### Send an email

```js theme={null}
amisend.emails
  .send({
    from: "Example <example@domain.com>",
    to: ["example@hotmail.com"],
    subject: "hello world",
    html: "<p>It works!</p>",
  })
  .then((response) => {
    // Handle response
  })
  .catch((error) => console.log(error));
```

## Contacts

### Create a contact

```js theme={null}
amisend.contacts
  .create({
    audienceId: "audience-id",
    name: "Sebastián",
    email: "example@hotmail.com",
  })
  .then((response) => {
    // Handle response
  })
  .catch((error) => console.log(error));
```

### List contacts in an audience

```js theme={null}
amisend.contacts
  .list({ audienceId: "audience-id", page: 1, limit: 10 })
  .then((contacts) => {
    // Handle contacts
  })
  .catch((error) => console.log(error));
```

### Update a contact

```js theme={null}
amisend.contacts
  .update({
    audienceId: "audience-id",
    contactId: "contact-id",
    name: "Sebastián Updated",
  })
  .then((response) => {
    // Handle response
  })
  .catch((error) => console.log(error));
```

### Delete a contact

```js theme={null}
amisend.contacts
  .delete({ audienceId: "audience-id", contactId: "contact-id" })
  .then((response) => {
    // Handle response
  })
  .catch((error) => console.log(error));
```

## Domains

### List domains

```js theme={null}
amisend.domains
  .list({})
  .then((domains) => {
    // Handle domains
  })
  .catch((error) => console.log(error));
```

### Create a domain

```js theme={null}
amisend.domains
  .create({ name: "example.com" })
  .then((domain) => {
    // Handle domain
  })
  .catch((error) => console.log(error));
```

### Retrieve a domain

```js theme={null}
amisend.domains
  .retrieve({ domainId: "domain-id" })
  .then((domain) => {
    // Handle domain
  })
  .catch((error) => console.log(error));
```

### Delete a domain

```js theme={null}
amisend.domains
  .delete({ domainId: "domain-id" })
  .then((response) => {
    // Handle response
  })
  .catch((error) => console.log(error));
```

### Check a domain

```js theme={null}
amisend.domains
  .check({ domainId: "domain-id" })
  .then((result) => {
    // Handle result
  })
  .catch((error) => console.log(error));
```

## Audiences

### List audiences

```js theme={null}
amisend.audiences
  .list({ page: 1, limit: 10 })
  .then((audiences) => {
    // Handle audiences
  })
  .catch((error) => console.log(error));
```

### Create an audience

```js theme={null}
amisend.audiences
  .create({ name: "Newsletter" })
  .then((audience) => {
    // Handle audience
  })
  .catch((error) => console.log(error));
```

### Retrieve an audience

```js theme={null}
amisend.audiences
  .retrieve({ audienceId: "audience-id" })
  .then((audience) => {
    // Handle audience
  })
  .catch((error) => console.log(error));
```

### Delete an audience

```js theme={null}
amisend.audiences
  .delete({ audienceId: "audience-id" })
  .then((response) => {
    // Handle response
  })
  .catch((error) => console.log(error));
```

## API Keys

### List API keys

```js theme={null}
amisend.apiKeys
  .list({})
  .then((apiKeys) => {
    // Handle API keys
  })
  .catch((error) => console.log(error));
```

### Create an API key

```js theme={null}
amisend.apiKeys
  .create({ name: "My Key" })
  .then((apiKey) => {
    // Handle API key
  })
  .catch((error) => console.log(error));
```

### Delete an API key

```js theme={null}
amisend.apiKeys
  .delete({ apiKeyId: "api-key-id" })
  .then((response) => {
    // Handle response
  })
  .catch((error) => console.log(error));
```

## Broadcasts

### List broadcasts

```js theme={null}
amisend.broadcasts
  .list({ page: 1, limit: 10 })
  .then((broadcasts) => {
    // Handle broadcasts
  })
  .catch((error) => console.log(error));
```

### Create a broadcast

```js theme={null}
amisend.broadcasts
  .create({
    name: "Promo",
    from: "Example <example@domain.com>",
    audience: "audience-id",
    subject: "Promo subject",
    html: "<p>Promo content</p>",
  })
  .then((broadcast) => {
    // Handle broadcast
  })
  .catch((error) => console.log(error));
```

### Retrieve a broadcast

```js theme={null}
amisend.broadcasts
  .retrieve({ broadcastId: "broadcast-id" })
  .then((broadcast) => {
    // Handle broadcast
  })
  .catch((error) => console.log(error));
```

### Update a broadcast

```js theme={null}
amisend.broadcasts
  .update({ broadcastId: "broadcast-id", subject: "New subject" })
  .then((broadcast) => {
    // Handle broadcast
  })
  .catch((error) => console.log(error));
```

### Delete a broadcast

```js theme={null}
amisend.broadcasts
  .delete({ broadcastId: "broadcast-id" })
  .then((response) => {
    // Handle response
  })
  .catch((error) => console.log(error));
```

### Send a broadcast

```js theme={null}
amisend.broadcasts
  .send({ broadcastId: "broadcast-id" })
  .then((result) => {
    // Handle result
  })
  .catch((error) => console.log(error));
```

### Unsubscribe a contact from a broadcast

```js theme={null}
amisend.broadcasts
  .unsubscribe({ broadcastId: "broadcast-id", contactId: "contact-id" })
  .then((result) => {
    // Handle result
  })
  .catch((error) => console.log(error));
```
