cf-worker-mautic
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

cf-woker-mautic

A Cloudflare Worker Friendly Mautic API implemented with ES6 + async/await.

Based on

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

  1. Import the class

    import MauticConnector from "node-mautic";
  2. 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 and password are just a normal Mautic user's username and password. There are no separate API users in Mautic.
    • timeoutInSeconds is optional.
  3. Make calls

    Example:

    const campaigns = (await mauticConnector.campaigns.listCampaigns()).campaigns;
    await mautic.contacts.createContact({
    mobile: phone,
    	tags: ["tag1","tag2"]
    })
    mautic.contacts.queryContacts(
        {
          // "email": "email@domain.com",
          // "mobile": encodeURIComponent(phone),
        },
    ).then((response) => {
    console.log(JSON.stringify(response, null, 2))
    });
  4. 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

Tests

To run the tests, fill the apiUrl, username, and password fields in MauticConnector.i.test.js.

Thanks

Package Sidebar

Install

npm i cf-worker-mautic

Weekly Downloads

0

Version

1.0.1

License

Apache-2.0

Unpacked Size

73.5 kB

Total Files

8

Last publish

Collaborators

  • dave_xt