Socket
Socket
Sign inDemoInstall

drip-nodejs

Package Overview
Dependencies
52
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

drip-nodejs

A complete NodeJS wrapper for connecting to the Drip v2 REST API


Version published
Maintainers
1
Weekly downloads
5,261
decreased by-5.02%

Weekly downloads

Readme

Source

Build Status

Drip Rest API Wrapper for Node.js

A complete Nodejs wrapper for the Drip REST API.

How to install

npm install drip-nodejs --save

NOTE: Potential Breaking Changes for Version 3.0.0

Drip's documentation doesn't explicitly describe the required schema for each endpoint. In versions prior to 3 you would need to explicitly pass payloads with the required schema, which aren't obvious. In version 3 and later, I've attempted to make this a bit simpler. For example, batch endpoints will now only need you to pass an array of objects as:

payload = [
  {
    email: 'user@example.com',
    action: 'Purchased'
  },
  {
    email: 'user@example.com',
    action: 'Purchased'
  }
]
// client.recordBatchEvents(payload, ...)

Prior to v3 changes you would need to do something like the following where the entire payload structure is defined:

payload = {
  batches: [
    {
      events: [
        {
          email: 'user@example.com',
          action: 'Purchased'
        },
        {
          email: 'user@example.com',
          action: 'Purchased'
        }
      ]
    }
  ]
}
// client.recordBatchEvents(payload, ...)

This should help to get up and running simpler without much knowledge of the required schema. However, existing users will need to take special note of these changes.

Authentication

For private use and integrations, use your API Token found here. Create a new instance of the client library with:

const client = require('drip-nodejs')({ token: YOUR_API_KEY, accountId: YOUR_ACCOUNT_ID });

For public integrations with an OAuth2 application registered with Drip, you'll need to specify the type of token you're passing (e.g. "Bearer"):

const client = require('drip-nodejs')({ token: YOUR_ACCESS_TOKEN, tokenType: TOKEN_TYPE, accountId: YOUR_ACCOUNT_ID });

You'll need your Drip Account ID when requiring the client which can be found here in your Drip account.

Usage

The following methods are currently available on the client instance. You can find a detailed explanation of all methods and their effect on resources in your Drip account here.

Note: All methods except updateBatchSubscribers return promises and support an optional asynchronous callback. The batch subscribers method only supports callbacks for now.

Accounts

ActionMethod
List all accountsclient.listAccounts(callback)
Fetch an accountclient.fetchAccount(accountId, callback)

Broadcasts

ActionMethod
List broadcastsclient.listBroadcasts(options = {}, callback)
Fetch a broadcastclient.fetchBroadcast(broadcastId, callback)

Campaigns

ActionMethod
List all campaignsclient.listCampaigns(options = {}, callback)
Fetch a campaignclient.fetchCampaign(campaignId, callback)
Activate a campaignclient.activateCampaign(campaignId, callback)
Pause a campaignclient.pauseCampaign(campaignId, callback)
List specific campaign's subscribersclient.listAllSubscribesToCampaign(campaignId, options = {}, callback)
Subscribe to a campaignclient.subscribeToCampaign(campaignId, payload, callback)

Campaign subscriptions

ActionMethod
List campaign subscriptionsclient.subscriberCampaignSubscriptions(subscriberId, callback)

Conversions

ActionMethod
List all conversionsclient.listConversions(options = {}, callback)
Fetch a conversionclient.fetchConversion(conversionId, callback)

Custom fields

ActionMethod
List all custom fieldsclient.listAllCustomFields(callback)

Events

ActionMethod
Record an eventclient.recordEvent(payload, callback)
Record a batch of eventsclient.recordBatchEvents(payload, callback)
List all events in accountclient.listEventActions(options = {}, callback)

Forms

ActionMethod
List all formsclient.listForms(callback)
Fetch a formclient.fetchForm(formId, callback)

Note: The beta purchases endpoint has been deprecated and its methods have been removed from the package except createPurchase, which now sends requests to the Order creation endpoint here.

Orders

ActionMethod
Record an order for a subscriberclient.createUpdateOrder(payload, callback)
Record a batch of ordersclient.createUpdateBatchOrders(payload, callback)
Record a refund for an orderclient.createUpdateRefund(payload, callback)

Shopper Activity

ActionMethod
Create or update a cart for a customerclient.createUpdateCartActivity(payload, callback)
Create or update an order for a customerclient.createUpdateOrderActivity(payload, callback)
Create or update a productclient.createUpdateProductActivity(payload, callback)

Subscribers

ActionMethod
List all subscribersclient.listSubscribers(options = {}, callback)
Update a subscriberclient.createUpdateSubscriber(payload, callback)
Fetch a subscriberclient.fetchSubscriber(idOrEmail, callback)
Unsubscribe from a campaignclient.unsubscribeFromCampaign(idOrEmail, campaignId, callback)
Unsubscribe from all mailingsclient.unsubscribeFromAllMailings(idOrEmail, callback)
Delete a subscriberclient.deleteSubscriber(idOrEmail, callback)
Update a batch of subscribersclient.updateBatchSubscribers(payload, callback)
Unsubscribe a batch of subscribersclient.unsubscribeBatchSubscribers(payload, callback)

Tags

ActionMethod
List all tagsclient.listAllTags(callback)
Tag a subscriberclient.tagSubscriber(payload, callback)
Remove tag from subscriberclient.removeSubscriberTag(email, tag, callback)

User

ActionMethod
Fetch authenticated userclient.fetchUser(callback)

Webhooks

ActionMethod
List all webhooksclient.listWebhooks(callback)
Fetch a webhookclient.fetchWebhook(webhookId, callback)
Create a webhookclient.createWebhook(payload, callback)
Destroy a webhookclient.destroyWebhook(webhookId, callback)

Workflows

ActionMethod
List all workflowsclient.listAllWorkflows(options = {}, callback)
Fetch a workflowclient.fetchWorkflow(workflowId, callback)
Activate a workflowclient.activateWorkflow(workflowId, callback)
Pause a workflowclient.pauseWorkflow(workflowId, callback)
Start a subscriber on a workflowclient.startOnWorkflow(workflowId, payload, callback)
Remove a subscriber from a workflowclient.removeFromWorkflow(workflowId, idOrEmail, callback)

Workflow triggers

ActionMethod
List all workflow triggersclient.listTriggers(workflowId, callback)
Create a workflow triggerclient.createTrigger(workflowId, payload, callback)
Update a triggerclient.updateTrigger(workflowId, triggerId, payload, callback)

See the official REST API docs for a complete API reference.

Examples

Listing subscribers

The listSubscribers accepts an optional object of filter arguments. Refer to Drip's API docs for all the available filters.

/**
 * Using a promise
 */

const options = {
  status: "unsubscribed",
  page: 2
  // or with more options
};

client.listSubscribers(options)
  .then((response) => {
    // do something with the raw response object or with `response.body`
  })
  .catch((error) => {
    // do something with the error
  });

/**
 * Using a callback
 */

client.listSubscribers(options, (error, response, body) => {
  // do someting with the response or handle errors
});

Updating a batch of subscribers

The updateBatchSubscribers method takes a batch object for the payload and is most suitable for sending thousands of subscriber updates.

Because Drip's batch APIs support a maximum of 1000 records, this method breaks the payload into N "batches" and calls the API N times. The callback is invoked only after all batches' API calls have returned, and receives N-sized arrays for values (i.e. errors, responses, and bodies).

It is the responsibility of the caller to interpret these values and handle any errors.

var batch = {
  "batches": [{
    "subscribers": [
      {
        "email": "john@acme.com",
        "tags": "Dog Person"
      },
      {
        "email": "joe@acme.com",
        "tags": "Cat Person"
      }
      // Lots more subscribers...
    ]
  }]
}

client.updateBatchSubscribers(batch, function (errors, responses, bodies) {
  // Do stuff
  }
)

Sending a batch of events

The recordBatchEvents methods takes a batch object for the payload and is most suitable for sending thousands of events. Note that the batch events method will not break up the payload into nice chunks like the subscribers batch method. This will be handled in a future update.

var batch = {
  "batches": [{
    "events": [
      {
        "email": "john@acme.com",
        "action": "Opened a door"
      },
      {
        "email": "joe@acme.com",
        "action": "Closed a door"
      }
      // Lots more events...
    ]
  }]
}

client.recordBatchEvents(batch, function (error, response, body) {
  // Do stuff
  }
)

Contributing

  1. Fork it ( https://github.com/samudary/drip-nodejs/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Note: Jasmine is used for testing

Keywords

FAQs

Last updated on 31 Jan 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc