SDK
Node.js
This section introduces how to use the SDK (Node.js) for integration.
Requirements
Node.js Version >= 14.0.0
Installation
npm install sendflare-sdk-tsCode Examples
Basic Usage
import { createSendflare } from 'sendflare-sdk-ts';
const client = createSendflare('this-is-my-token');
const req = {
from: 'test@example.com',
to: 'to@example.com',
subject: 'test',
body: 'test email',
};
client.sendEmail(req)
.then(response => {
console.log('Email sent successfully:', response);
})
.catch(error => {
console.error('Failed to send email:', error);
});Using async/await
import { Sendflare } from 'sendflare-sdk-ts';
async function main() {
const client = new Sendflare('this-is-my-token');
try {
// Send an email
const emailResponse = await client.sendEmail({
from: 'test@example.com',
to: 'to@example.com',
subject: 'test',
body: 'test email',
});
console.log('Email sent:', emailResponse);
// Get contact list
const contacts = await client.getContactList({
appId: 'your-app-id',
page: 1,
pageSize: 10,
});
console.log('Contacts:', contacts);
// Save a contact
const saveResponse = await client.saveContact({
appId: 'your-app-id',
emailAddress: 'contact@example.com',
data: {
firstName: 'John',
lastName: 'Doe',
},
});
console.log('Contact saved:', saveResponse);
// Delete a contact
const deleteResponse = await client.deleteContact({
appId: 'your-app-id',
emailAddress: 'contact@example.com',
});
console.log('Contact deleted:', deleteResponse);
} catch (error) {
console.error('Error:', error);
}
}
main();API Reference
createSendflare
Create a new Sendflare client instance.
Parameters:
token- Your Sendflare API token
Returns: A Sendflare client instance
sendEmail
Send an email.
Parameters:
req.from- Sender email addressreq.to- Recipient email addressreq.subject- Email subjectreq.body- Email body content
getContactList
Get contact list with pagination.
Parameters:
req.appId- Application IDreq.page- Page numberreq.pageSize- Number of items per page
saveContact
Create or update a contact.
Parameters:
req.appId- Application IDreq.emailAddress- Contact email addressreq.data- Optional contact data fields
deleteContact
Delete a contact.
Parameters:
req.appId- Application IDreq.emailAddress- Contact email address to delete
TypeScript Support
This SDK is written in TypeScript and includes complete type definitions out of the box. No need to install separate @types packages.
import { Sendflare, SendEmailReq, SendEmailResp } from 'sendflare-sdk-ts';
const client = new Sendflare('your-token');
const req: SendEmailReq = {
from: 'test@example.com',
to: 'to@example.com',
subject: 'test',
body: 'test email',
};
const response: SendEmailResp = await client.sendEmail(req);