yournotify-node-sdk
Version:
NPM SDK for Yournotify API. Send email and sms marketing campaigns with ease.
264 lines (210 loc) • 5.84 kB
Markdown
# Yournotify Node SDK
## Installation
Install the Yournotify Node.js SDK using npm:
```bash
npm install yournotify-node-sdk
```
## Usage
First, import the `Yournotify` class and initialize it with your API key.
```js
import Yournotify from "yournotify-node-sdk";
const apiKey = "your_api_key_here";
const yournotify = new Yournotify(apiKey);
```
---
### Sending an Email
```js
yournotify
.sendEmail(
"Awesome Campaign", // name
"sender@example.com", // from
"Subject", // subject
"<h1>Hello</h1>", // html
"Hello", // text
"running", // status
["recipient@example.com"] // to
)
.then((response) => {
console.log(response.status); // success or failed
console.log(response.data.id); // Campaign ID
});
```
### Sending an SMS
```js
yournotify
.sendSMS(
"Awesome Campaign", // name
"sender_id", // from
"Hello world!", // text
"running", // status
["+2348100000000"] // to
)
.then((response) => {
console.log(response.status); // success or failed
console.log(response.data.id); // Campaign ID
});
```
### Adding a Contact
```js
yournotify
.addContact(
"email@example.com",
"+2348100000000",
"list_id",
"Contact Name",
{ key: "value" }
)
.then((response) => {
console.log(response.status);
console.log(response.data.id); // Contact ID
});
```
### Getting All Contacts
```js
yournotify.getContacts().then((response) => {
console.log(response.status);
console.log(response.data); // List of contacts
});
```
### Deleting a Contact
```js
yournotify.deleteContact(123).then((response) => {
console.log(response.status); // success or failed
});
```
### Adding a List
```js
yournotify.addList("List Title", "type", "optin").then((response) => {
console.log(response.status);
console.log(response.data.id); // List ID
});
```
### Getting All Lists
```js
yournotify.getLists().then((response) => {
console.log(response.status);
console.log(response.data); // List of lists
});
```
### Deleting a List
```js
yournotify.deleteList(456).then((response) => {
console.log(response.status); // success or failed
});
```
### Deleting a Campaign
```js
yournotify.deleteCampaign(789).then((response) => {
console.log(response.status); // success or failed
});
```
### Getting Campaign Stats
```js
yournotify.getCampaignStats(123, "email").then((response) => {
console.log(response.status);
console.log(response.data); // Campaign stats
});
```
### Getting Campaign Reports
```js
yournotify.getCampaignReports(123, "sms").then((response) => {
console.log(response.status);
console.log(response.data); // Campaign reports
});
```
### Getting Your Profile
```js
yournotify.getProfile().then((response) => {
console.log(response.status);
console.log(response.data); // Profile information
});
```
---
## API Methods Reference
### API Methods
#### Email
- **`sendEmail(name, from, subject, html, text, status, to)`**
Sends an email campaign.
- `to`: Accepts either:
- An array of email strings
Example:
```js
["recipient1@example.com", "recipient2@example.com"];
```
- An array of objects
Example:
```js
[
{
email: "recipient1@example.com",
name: "Recipient One",
attribs: { key: "value" }, // optional
},
{
email: "recipient2@example.com",
name: "Recipient Two",
attribs: { key: "value2" }, // optional
},
];
```
#### SMS
- **`sendSMS(name, from, text, status, to)`**
Sends an SMS campaign.
- `to`: Accepts either:
- An array of phone number strings
Example:
```js
["+2348100000000", "+2348100000001"];
```
- An array of objects
Example:
```js
[
{
telephone: "+2348100000000",
name: "Recipient One",
attribs: { key: "value" }, // optional
},
{
telephone: "+2348100000001",
name: "Recipient Two",
attribs: { key: "value2" }, // optional
},
];
```
#### Contacts
- **`addContact(email, telephone, list, name, attribs)`**
Adds a contact to a list.
- **`getContact(id)`**
Retrieves a contact by ID.
- **`getContacts()`**
Retrieves all contacts.
- **`deleteContact(id)`**
Deletes a contact by ID.
#### Lists
- **`addList(title, type, optin)`**
Creates a new list.
- **`getList(id)`**
Retrieves a list by ID.
- **`getLists()`**
Retrieves all lists.
- **`deleteList(id)`**
Deletes a list by ID.
#### Campaigns
- **`deleteCampaign(id)`**
Deletes a campaign by ID.
- **`getCampaignStats(ids, channel)`**
Retrieves campaign statistics for one or more campaign IDs.
- `channel`: `"email"` or `"sms"`
- **`getCampaignReports(ids, channel)`**
Retrieves campaign reports for one or more campaign IDs.
- `channel`: `"email"` or `"sms"`
#### Profile
- **`getProfile()`**
Retrieves your profile information, including account credits and related data.
---
## More Information
For full API reference, visit the [Yournotify API Documentation](https://api.yournotify.com/doc).
---
## License
This SDK is open-source and available under the MIT License.