hschmaiske:email-octopus

v0.0.3Published 8 months ago

EmailOctopusClient

A simple JavaScript class for interacting with the EmailOctopus API.

Installation

Install the package using:

meteor add hschmaiske:email-octopus

Usage

1import { EmailOctopusClient } from "hschmaiske:email-octopus";
2
3// Replace 'your-api-key' with your EmailOctopus API key
4const apiKey = "your-api-key";
5const emailOctopusClient = new EmailOctopusClient(apiKey);
6
7// Replace 'your-list-id' with the ID of your EmailOctopus list
8const listId = "your-list-id";
9
10// Replace the example data with the actual data for the new contact
11const userData = {
12  email: "john.doe@example.com",
13  firstName: "John",
14  lastName: "Doe",
15  username: "john_doe",
16  tags: ["tag1", "tag2", "tag3"],
17};
18
19try {
20  await emailOctopusClient.createContact(listId, userData);
21  console.log("Contact created successfully!");
22} catch (error) {
23  console.error("Error creating contact:", error.message);
24}

API

EmailOctopusClient(apiKey: string)

Creates a new instance of the EmailOctopusClient.

  • apiKey: The API key for EmailOctopus.

callApi(endpoint: string, data: Object, method: string = "POST"): Promise<Object>

Makes an API call to EmailOctopus.

  • endpoint: The API endpoint to call.
  • data: The data to be sent in the API call.
  • method: The HTTP method for the API call (default is "POST").

createContact(listId: string, contactData: Object): Promise<void>

Creates a new contact in an EmailOctopus list.

  • listId: The ID of the EmailOctopus list.
  • contactData: Data for the new contact.