cf-worker-mautic
v1.0.1
Published
A Cloudflare Worker Friendly Mautic API implemented with ES6 + async/await
Downloads
3
Maintainers
Readme
cf-woker-mautic
A Cloudflare Worker Friendly Mautic API implemented with ES6 + async/await.
Based on
- NPM: https://www.npmjs.com/package/node-mautic
- GitHub: https://github.com/vdavid/node-mautic/
Tested with wrangler2 and Mautic 4.4.5.
~~This package has only 1 dependency (node-fetch), which has 0 dependencies.~~ This package now has 0 dependancies.
Installation
$ npm install cf-worker-mautic
Usage
Import the class
import MauticConnector from "node-mautic";
Instantiate the object
const mauticConnector = new MauticConnector({ apiUrl: 'https://your-url.com', username: '...', password: '...' , timeoutInSeconds: 5 });
apiURL
needs to be just the base URL. The/url/
part of the API URL is to be omitted here.username
andpassword
are just a normal Mautic user's username and password. There are no separate API users in Mautic.timeoutInSeconds
is optional.
Make calls
Example:
const campaigns = (await mauticConnector.campaigns.listCampaigns()).campaigns;
await mautic.contacts.createContact({ mobile: phone, tags: ["tag1","tag2"] })
mautic.contacts.queryContacts( { // "email": "[email protected]", // "mobile": encodeURIComponent(phone), }, ).then((response) => { console.log(JSON.stringify(response, null, 2)) });
Run or deploy
To try it out:
$ wrangler2 dev
To deploy it:
$ wrangler2 publish --name name-of-the-worker
Features
- uses basic authentication
- has methods for all ~200 documented API endpoints
- has less than 400 lines of code
- uses async/await (no callback hell)
- some documentation
- 6 Jest tests
Based On
- NPM: https://www.npmjs.com/package/node-mautic
- GitHub: https://github.com/vdavid/node-mautic/
Tests
To run the tests, fill the apiUrl
, username
, and password
fields in MauticConnector.i.test.js
.
Thanks
- To https://github.com/vdavid/node-mautic/ for the original code!