aweber-api
Minimal higher-level wrapper around AWeber's API for Node.js.
Features
- Promise-based
- Minimal
- Resilient to upstream changes to the AWeber API
Installation
Install using npm:
$ npm install aweber-api --save
Getting Started
- In order to use the AWeber API, you will first need to register for a free developer account.
- Once you have an account, log in and create an app, making note of your consumer key and secret.
With a consumer key and secret, you are now ready to authenticate your app and verify one or more accounts. We'll start by verifying a single account. Open a Node.js console session:
$ node
> Aweber = require('aweber-api')
[Function: Aweber]
> aw = Aweber('your-consumer-key', 'your-consumer-secret')
> aw.getAuthorizationUrl().then(console.log).catch(console.log)
Promise { <pending> }
> https://auth.aweber.com/1.0/oauth/authorize?oauth_token=XXXXXXXXXXXXXXXXXXXXXXXX
Visit the URL this generates. You will be prompted to enter the credentials for the AWeber account you'd like to access via the API (NOTE: AWeber account, NOT your labs developer account).
After submitting the form, copy the verifier code that was generated and return to your node console session:
> aw.getAccessToken('your-verifier-token').then(console.log).catch(console.log)
Promise { <pending> }
{ token: "XXXXXXXXXXXXXXXXXXXXXXXX", tokenSecret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }
At this point, your account is fully authenticated. Make note of your token and token secret. These should be stored securely for future use.
Usage
aweber-api exports a factory function for creating new aweber
instances.
Consumer key and secret are required.
const Aweber = ; // ... const aw = ;
Available Options
Overview of defaults:
;
Methods
OAuth
Aweber#getAuthorizationUrl([callbackUrl])
Resets the instance's internal token value to an empty string, requests a new temporary token, stores the new token internally, and returns the URL where authorization can be made. An optional callback url may be specified. Returns a Promise.
Aweber#getAccessToken(verifier)
Request a new token and token secret. This method requires the verifier code obtained from the user authorization process. Returns a Promise.
HTTP Verbs
See the official AWeber API docs for specifics on using individual endpoints.
Aweber#del(url, options)
Makes a single DELETE
request to the AWeber API for the given resource,
returning a Promise.
Params
url
{String}: URL of the resource to be deleted (host and query params optional)options
{Object}: Options objectoptions.params
{Object}: Dictionary of query parameters to specify
Example
// All of the following are equivalent:aw;aw;aw;
Aweber#get(url, options)
Makes a single GET
request to the AWeber API for the given resource,
returning a Promise.
Params
url
{String}: URL of the resource to be retrieved (host and query params optional)options
{Object}: Options objectoptions.params
{Object}: Dictionary of query parameters to specify
Example
// All of the following are equivalent:aw;aw;aw;
Aweber#patch(url, options)
Makes a single PATCH
request to the AWeber API for the given resource,
returning a Promise.
Params
url
{String}: URL of the resource to be updated (host and query params optional)options
{Object}: Options objectoptions.data
{Object}: Dictionary of fields with their updated valuesoptions.params
{Object}: Dictionary of query parameters to specify
Example
const opts = data: subject: 'new value' ; // All of the following are equivalent:aw;aw;
Aweber#post(url, options)
Makes a single POST
request to the AWeber API for the given resource,
returning a Promise.
Params
url
{String}: URL of the resource to be created (host and query params optional)options
{Object}: Options objectoptions.data
{Object}: Dictionary of field/value pairsoptions.params
{Object}: Dictionary of query parameters to specify
Example
const data = foo: 1 bar: true ;const params = 'ws.op': 'create' ; // All of the following are equivalent:aw;aw;aw;aw;
Aweber#put(url, options)
Makes a single PUT
request to the AWeber API for the given resource,
returning a Promise.
Params
url
{String}: URL of the resource to be updated (host and query params optional)options
{Object}: Options objectoptions.data
{Object}: Dictionary containing fully updated recordoptions.params
{Object}: Dictionary of query parameters to specify
Example
const opts = data: id: 1 foo: 1 bar: true ; // All of the following are equivalent:aw;aw;
License
MIT