JavaScript/TypeScript
JavaScript and TypeScript SDK for Poodle’s email sending API.
Table of Contents
Section titled “Table of Contents”- Installation
- Quick Start
- Features
- API Reference
- Error Handling
- Examples
- Development
- Contributing
- License
Installation
Section titled “Installation”npm install @usepoodle/poodle-js
Quick Start
Section titled “Quick Start”import { PoodleClient, PoodleError } from '@usepoodle/poodle-js';
// Initialize the client with your API keyconst client = new PoodleClient({ apiKey: 'YOUR_POODLE_API_KEY_HERE',});
// Send an emailasync function sendEmail() { try { const response = await client.sendEmail({ subject: 'Hello from Poodle!', html: '<h1>Hello!</h1><p>This is a test email.</p>', });
console.log('Email API call successful:', response.message); } catch (error: any) { console.error('Failed to send email:', error.message);
if (error instanceof PoodleError) { console.error('Status Code:', error.statusCode); console.error('Specific Details:', error.details); } }}
sendEmail();
For more usage patterns, including sending text-only emails, see the examples directory.
Features
Section titled “Features”- Intuitive API: Get started in minutes.
- TypeScript First: Robust type safety out-of-the-box.
- Modern Async: Clean async/await for non-blocking operations.
- Detailed Errors: Understand and debug issues quickly with PoodleError objects.
- Flexible Content: Send rich HTML or plain text emails easily.
API Reference
Section titled “API Reference”PoodleClient
Section titled “PoodleClient”The main class for interacting with the Poodle API.
Constructor
Section titled “Constructor”new PoodleClient(options: PoodleClientOptions)
Options:
apiKey
(required): Your Poodle API keybaseUrl
(optional): Custom API base URL (defaults to production API)
Methods
Section titled “Methods”sendEmail
Section titled “sendEmail”sendEmail(options: SendEmailOptions): Promise<SendEmailResponse>
Options:
from
(required): Sender email addressto
(required): Recipient email addresssubject
(required): Email subject linehtml
(optional): HTML content of the emailtext
(optional): Plain text content of the email
At least one of html
or text
must be provided.
Response:
success
:boolean
- Indicates if the email was successfully queued (typicallytrue
for a successful call).message
:string
- A confirmation message from the API (e.g., “Email queued for sending”).
Error Handling
Section titled “Error Handling”The SDK throws PoodleError
instances for API-related errors. Each error includes:
message
: Human-readable error message (from the API’smessage
field).statusCode
: HTTP status code (if applicable).details
: Detailed error information or specific error code from the API (from the API’serror
field in the JSON response, if available).
Common error scenarios:
- Invalid API key (401)
- Rate limiting (429)
- Invalid email addresses (400)
- Account issues (402)
Examples
Section titled “Examples”Check the examples directory for more usage examples.
Development
Section titled “Development”# Install dependenciesnpm install
# Run testsnpm test
# Build the packagenpm run build
# Run linternpm run lint
# Format codenpm run format
Contributing
Section titled “Contributing”Contributions are welcome! Please read our Contributing Guide for details on the process for submitting pull requests and our Code of Conduct.
License
Section titled “License”This project is licensed under the MIT License - see the LICENSE file for details.