Installation
You can install the package from npm:Cocoonmail_API_KEY in an .env file).
Usage
from "cocoonmail";
Default contact properties
Each contact in Cocoonmail has a set of default properties. These will always be returned in API results.idemailfirstNamelastNamesourcesubscribeduserGroupuserId
Custom contact properties
You can use custom contact properties in API calls. Please make sure to add custom properties in your Cocoonmail account before using them with the SDK.Methods
- testApiKey()
- createContact()
- updateContact()
- findContact()
- deleteContact()
- getMailingLists()
- sendEvent()
- sendTransactionalEmail()
- getCustomFields()
testApiKey()
Test that an API key is valid. API ReferenceParameters
NoneExample
Response
This method will return a success or error message:createContact()
Create a new contact. API ReferenceParameters
Examples
Response
This method will return a success or error message:updateContact()
Update a contact. Note: To update a contact’s email address, the contact requires auserId value. Then you can make a request with their userId and an updated email address.
API Reference
Parameters
Example
Response
This method will return a success or error message:findContact()
Find a contact. API ReferenceParameters
You must use one parameter in the request.Examples
resp = await cocoonmail.findContact({ email: });
Response
This method will return a list containing a single contact object, which will include all default properties and any custom properties. If no contact is found, an empty list will be returned.deleteContact()
Delete a contact, either by email address oruserId.
API Reference
Parameters
You must use one parameter in the request.Example
Response
This method will return a success or error message:getMailingLists()
Get a list of your account’s mailing lists. Read more about mailing lists API ReferenceParameters
NoneExample
Response
This method will return a list of mailing list objects containingid, name and isPublic attributes.
If your account has no mailing lists, an empty list will be returned.
sendEvent()
Send an event to trigger an email in Cocoonmail. Read more about events API ReferenceParameters
Examples
Response
This method will return a success or error:sendTransactionalEmail()
Send a transactional email to a contact. Learn about sending transactional email API ReferenceParameters
Examples
Response
This method will return a success or error message.Version history
v3.3.0(Sep 9, 2024) - AddedtestApiKey()method.3.2.0(Aug 23, 2024) - Added support for a newmailingListsattribute infindContact().v3.1.0(Aug 12, 2024) - The SDK now acceptsnullas a value for contact properties increateContact(),updateContact()andsendEvent(), which allows you to reset/empty properties.v3.0.0(Jul 2, 2024) -[sendTransactionalEmail()]()now accepts an object instead of separate parameters (breaking change).v2.2.0(Jul 2, 2024) - Deprecated. Added newaddToAudienceoption tosendTransactionalEmail().v2.1.1(Jun 20, 2024) - Added support for mailing lists increateContact(),updateContact()andsendEvent().v2.1.0(Jun 19, 2024) - Added support for new List mailing lists endpoint.v2.0.0(Apr 19, 2024)- Added
userIdas a parameter tofindContact(). This includes a breaking change for thefindContact()parameters. userIdvalues must now be strings (could have also been numbers previously).
- Added
v1.0.1(Apr 1, 2024) - Fixed types forsendEvent().v1.0.0(Mar 28, 2024) - Fix for ESM types. Switched to named export- .v0.4.0(Mar 22, 2024) - Support for neweventPropertiesinsendEvent(). This includes a breaking change for thesendEvent()parameters.v0.3.0(Feb 22, 2024) - Updated minimum Node version to 18.0.0.v0.2.1(Feb 6, 2024) - Fix for ESM imports.v0.2.0(Feb 1, 2024) - CommonJS support.v0.1.5(Jan 25, 2024) -getCustomFields()now returnstypevalues for each contact property.v0.1.4(Jan 25, 2024) - Added support foruserIdinsendEvent()request. Added missing error response type forsendEvent()requests.v0.1.3(Dec 8, 2023) - Added support for transactional attachments.v0.1.2(Dec 6, 2023) - Improved transactional error types.v0.1.1(Nov 1, 2023) - Initial release.