AWeber API (1.0)

Download OpenAPI specification:Download

We are constantly working to improve this documentation. If you have feedback and questions, please contact the AWeber API team at api@aweber.com.

The AWeber API is a REST API that uses the OAuth 2.0 authentication model.

Please see the below resources for further information:

Getting Started

Creating a Developer Account

To start developing, you will first need to create a free developer account. After you create a developer account, log in and create an app.

What is the AWeber API?

The AWeber API is a JSON based REST API.

This means that resources are represented as JSON dictionaries and you use a different HTTP verb to do your standard CRUD operations on them:

  • POST: Create new resources.
  • GET: Retrieve a resource.
  • PATCH: Update existing resources.
  • DELETE: Delete existing resources.

Note

Within this document, campaigns is a generic term that refers to both Broadcast and Follow Up messages. Currently the AWeber API does not support Campaigns, which is an email automation platform available to customers within the AWeber web platform.

Authentication

Before you can make requests to the API, you need to support our authentication protocol. We currently require all new applications using the API to make use of the OAuth 2.0 authentication protocol.

We recommend that you start out by visiting the OAuth 2.0 Overview. This will walk you through the authentication process.

How Resources are Arranged in the AWeber API

API resources are arranged in the AWeber API based on their relationships to each other. We illustrate these relationships on the image below with the URLs of the resources. When we refer to the relationships of the resources, we say an Account has Lists, a List has Subscribers, etc. We can also say Subscribers belong to a List, or Lists belong to an Account, and so on.

A single resource is referred to as an Entry and is shown as a yellow circle on the image. Entries are contained in Collections which are shown as a blue box on the image. These resources are contained under version '1.0' of the API.

[Resource Map]

 

How Collections are Represented

Collections are represented as an ordered sequence of entries. They are paginated using the ws.size and ws.start query parameters where ws.size is the maximum number of entries to return and ws.start is the zero-based index to start the page at. The response represents a page of entries and includes at least the following body properties:

Name Type Description
entries List of Objects The entries on the requested page
start Non-negative Integer The starting offset of the page
total_size Non-negative Integer The total size of the collection*
next_collection_link URL Link to the next page unless this is the final page
prev_collection_link URL Link to the previous page unless this is the first page

Though you can specify the exact page that you want using ws.size and ws.start, you should use the next_collection_link and prev_collection_link properties in the response to traverse the collection. If the prev_collection_link is absent, then the current page is the first page. Likewise, if the next_collection_link is absent, then the current page is the last page in the collection.

Authentication Overview

The AWeber API uses the OAuth 2.0 specification for authentication. OAuth 2.0 is the successor to OAuth 1, which AWeber’s API formerly used. If you have an existing OAuth 1 application, documentation regarding how to connect with OAuth 1 is available. Please plan to move to OAuth 2.0 as soon as you are able.

Connecting your integration to an AWeber customer account requires the use of OAuth 2.0. This step is required before you start making requests to AWeber’s API in order to do things like add subscribers, check your broadcast stats, or sending messages. We use OAuth 2.0 in order to ensure that an integration has permission to access a given AWeber account.

You'll need the following to get started:

  • An AWeber developer account
  • An app created in that account
  • An AWeber customer account
  • An HTTP library capable of making OAuth 2.0 requests.

If you need a customer account you can sign up for a free trial to get started. These examples will be using Python 3 and requests_oauthlib as the HTTP library. You will find there are lots of good libraries available for every programming language. The set up and usage varies between libraries. Be sure to read the documentation for the library you select. For a full sample in Python as well as PHP and C#.NET please see our code samples on GitHub.

OAuth 2.0

The following endpoints and scopes are used to authenticate.

Security scheme type: OAuth2
authorizationCode OAuth Flow
Authorization URL: https://auth.aweber.com/oauth2/authorize
Token URL: https://auth.aweber.com/oauth2/token
Refresh URL: https://auth.aweber.com/oauth2/token
Scopes:
  • account.read -
    Access account information and associated integrations.
    Required for the following endpoints: get accounts, get account, get integrations, get integration
  • list.read -
    Retrieve lists, custom fields, tags, and sign up forms
    Required for the following endpoints: get list, get lists, find lists, get tags for list, get custom fields, get custom field, get webforms for list, get split tests for list, get split test components, get split test component, get webforms for account, get split tests for account
  • list.write -
    Create, edit, and delete custom fields
    Required for the following endpoints: add custom field, update custom field, delete custom field
  • subscriber.read -
    Retrieve subscribers and their activity
    Required for the following endpoints: get subscribers, get subscriber, get subscriber activity, get subscribers for message
  • subscriber.write -
    Created, edit, delete, and move subscribers
    Required for the following endpoints: add subscriber, move subscriber, update subscriber, delete subscriber
  • subscriber.read-extended -
    Retrieve subscriber PII such as name, email, IP address, etc.
    Required for the following endpoints: find subscribers for account, find subscribers for list required to return subscriber fields that are considered PII and normally omitted from responses (currently: email, ip_address, miscellaneous notes, and name)
  • email.read -
    Retrieve email activity related to broadcasts and follow-ups
    Required for the following endpoints: get messages, get message, get broadcasts, get broadcast, get message opens, get message open, get message tracked events, get message tracked event, get total broadcasts, get campaigns, get campaign, find campaigns, get links, get link, get clicks, get click, get broadcast statistics, get broadcast statistic
  • email.write -
    Create and send email broadcasts
    Required for the following endpoints: create broadcast, update broadcast, delete broadcast, cancel broadcast, schedule broadcast

What is OAuth 2.0?

OAuth is a way for a developer to securely access information without knowing someone’s password or other login details. The end result of OAuth is an access token, which proves that the developer has permission to access the data held in the API and should always be kept safe and secure. If you are creating an application that cannot store secrets in an secure way (e.g. a mobile application or a WordPress plugin) use Proof Key for Code Exchange (PKCE) which does not require the client secret to be used or stored. See Public or confidential? below for more detail.

The general flow of OAuth 2.0 is a back and forth handshake between the developer, the AWeber customer, and AWeber’s API. In this guide you’ll learn to do the following:

  1. Build an authorization URL
  2. Get an authorization code
  3. Trade your authorization code for an access token
  4. Refresh your access token after it expires using the refresh token

If your client is a public client, then you do not have a client secret and you are required to use the code verifier and code challenge instead of the client secret. The steps required are the same except that the client_secret is not used. See Public or confidential? below for more detail.

Step 1: Build an authorization URL

The first thing you’ll need to do is create a hyperlink to start the authorization process. This code provides AWeber’s API with information such as which integration is making the request and what access the integration requires. Please review the example below:

https://auth.aweber.com/oauth2/authorize?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_CALLBACK&scope=YOUR_REQUESTED_SCOPES&state=STATE_TOKEN

The components of this URL are as follows:

  • The base URL is provided by AWeber and connects you to our servers.

  • response_type tells AWeber what you want us to send back. For this step you should always use code since you want an authorization code.

  • client_id is the Client ID listed in your developer account. It uniquely identifies your integration to AWeber.

  • redirect_uri is your callback. This is where the user-agent (in most cases the customer’s browser) will be sent after the customer clicks authorize. This should be a uri that your application can read because that’s where we’ll provide our response. When you provide your callback, make sure it’s the same one you specified when creating your integration.

    If your application will be installed on multiple domains, you can send the authorization code out-of-band (OOB) instead. This will display the code in a page where users can copy and paste it into your application. To do this, configure your application's redirect URI to the special value urn:ietf:wg:oauth:2.0:oob and use this value for your redirect_uri.

  • state is a token you provide to AWeber for CSRF protection. You can also use this token as a session token to preserve user data between the auth steps, providing a better experience for your users. We pass this data back to you later and you can check that it matches the value you sent. A random string or a hash of a session cookie is acceptable here, it just needs to be something you know but a potential attacker doesn’t and it should change for each new user.

  • scope is a list of space separated permissions your integration requires. To change permissions later, all customers will need to repeat the authorization process. Please ensure you have the ones you need.

Below is an example using requests_oauthlib.

from requests_oauthlib import OAuth2Session

AUTHORIZE_URL = 'https://auth.aweber.com/oauth2/authorize'

Public or confidential?

The preceding examples assumed that your applications configuration is kept secret since the client secret is used to create and refresh tokens. The client secret is required to be kept secret at all times. Anyone that has access to your client identifier and secret can access the data of every AWeber customer using your application. This works well for applications that you host in a closed environment but it does not work for mobile applications or integrations without secure configuration (e.g., Wordpress plug-ins).

The OAuth 2.0 framework defines two client types in [RFC-6749]:

Confidential

Clients capable of maintaining the confidentiality of their credentials (e.g., client implemented on a secure server with restricted access to the client credentials), or capable of secure client authentication using other means.

Public

Clients incapable of maintaining the confidentiality of their credentials (e.g., clients executing on the device used by the resource owner, such as an installed native application or a web browser-based application), and incapable of secure client authentication via any other means.

Public clients cannot use the standard [OAuth 2.0 Authorization Code] flow since they are incapable of maintaining secrets. For this reason, the AWeber API supports supports Proof Key for Code Exchange (PKCE) as specified in [RFC-7636] for public clients.

There are a few differences in the authorization flow for PKCE. The most important is that you never include your client secret. Instead of using a client secret that is shared between the client and the authorization server, PKCE has the client create a string of ASCII characters known as the code verifier. A hashed digest of the verifier is sent with the authorization request (step 1) and the verifier is added to the token request (step 3). The server saves the hashed digest (also known as the code challenge) with the authorization code that it generates and compares the verifier to the challenge when redeeming the authorization code.

Let's walk through the differences from the standard flow step-by-step to see how PKCE works without a client secret.

Step 1: Build an authorization URL

The authorization URL for public clients requires two additional parameters to act as a transient secret. The code challenge is the hashed version of the code verifier. The code challenge method identifies the hash algorithm that was used to generate the challenge. This is required to be S256 since the AWeber API only supports SHA256 hashed challenges.

Before sending the authorization request, the client is required to generate a code verifier that is a random string of at least 43 characters and at most 128 characters. See [RFC-7636] for a precise description of the code verifier. Then the client generates the code challenge from the verifier by hashing the verifier using SHA-256 and Base64 encoding the resulting value using the url-safe base64 variant. The challenge and challenge method are sent as the code_challenge and code_challenge_method query parameters in the authorization URL.

The following python snippet will generate an acceptable random verifier and code challenge:

import base64
import hashlib
import os
import uuid

Have more than one user?

Sometimes an integration is used by many AWeber customers. You can have as many users as you like with this authentication process. Just start at the top and make a new request token for each user of your integration. Access tokens are tied to AWeber customer accounts so each account will have a new set of tokens. You can store them safely in a database and use the account ID to differentiate them.

Having trouble?

Here are some solutions to common problems:

  • Check the documentation for your chosen library. Are the calls being made correctly and is everything being passed around as it should be?
  • Is your access token still valid? Try refreshing the token and see if that fixes any 401 Unauthorized errors.
  • Did you copy your client ID and secret correctly? Make sure the ID and secret you’re using are the ones we provided in your developer account.
  • Make sure you’re using your AWeber customer account and not your AWeber developer account on the authorization login page.

If you still can’t figure it out we’re always happy to help you work through any errors. Send us an email at api@aweber.com and be sure to note any errors or information about the problem you’re having.

OAuth 2.0 Examples

The following examples show how to obtain an access token for an AWeber account using Python. For PHP and C#.NET versions please see our PHP code sample and C#.NET code sample on GitHub.

Get An Access Token

Below is a python example using the requests_oauthlib OAuth library to obtain an accounts access tokens.

You will need:

  • The Client ID, Client Secret, and Redirect URI from your integration, available on the My Apps Page.
  • The list of scopes to allow for the customer's account.
  • The username and password for an AWeber account that you want to connect.
from requests_oauthlib import OAuth2Session

AUTHORIZATION_BASE_URL = 'https://auth.aweber.com/oauth2/authorize'
TOKEN_URL = 'https://auth.aweber.com/oauth2/token'

client_id = '*****'
client_secret = '*****'
redirect_uri = 'YOUR_REDIRECT_URI'

Distributing the application's source code?

If you are making the source code of your integration public, you may not have a means to distribute the client secret securely. If you cannot guarantee the confidentiality of your client secret, then you are required to use Proof Key for Code Exchange as described in Public or confidential.

Below is an example on how to authenticate using PKCE with the requests_oauthlib library. You will need:

  • The Client ID, and Redirect URI from your integration, available on the My Apps Page.
  • The list of scopes to allow for the customer's account.
  • The username and password for an AWeber account that you want to connect.
import base64
import hashlib
import os
import urllib as parse

from requests_oauthlib import OAuth2Session

AUTHORIZATION_BASE_URL = 'https://auth.aweber.com/oauth2/authorize'
TOKEN_URL = 'https://auth.aweber.com/oauth2/token'

client_id = input('Your client ID:    ')
redirect_uri = input('Your redirect URI: ')

OAuth 2.0 Traces

This section contains low-level HTTP traces of the OAuth 2.0 authorization code flow. The client IDs, client secrets, authorization codes, and other details are fictitious and should not be used anywhere else.

Confidential protocol flow

The following HTTP trace shows the entire flow for a Confidential client using the following parameters:

Parameter Value
Client ID N1nwOnhAUyEjJcA0l4eI7dCfYKNVizSDE4Le0J4FRqc
Client secret rSu9NU70xOZFN2ojnWq3tLI49kb8vs84_KZQe1bcJy4
Scopes account.read list.read subscriber.read
Redirect URI https://127.0.0.1/oauth2-callback
State 62cdb1ee8a5c40f6ba0d5de1dfa83113
Authorization code VhXKzYi5paFfs1aYqgikSw

The web application initiates the authorization flow.

GET /oauth2/authorize?response_type=code&client_id=N1nwOnhAUyEjJcA0l4eI7dCfYKNVizSDE4Le0J4FRqc&redirect_uri=https%3A%2F%2F127.0.0.1%2Foauth2-callback&scope=account.read+list.read+subscriber.read&state=62cdb1ee8a5c40f6ba0d5de1dfa83113 HTTP/1.1
Host: auth.aweber.com

HTTP/1.1 200 OK
Content-Type: text/html

<html>.... authorization form ....</html>

The user authenticates and authorizes the application.

The authorization form action initiates a POST to the AWeber authorization server which redirects the user to the application-specified redirect URL.

POST /oauth2/authorize HTTP/1.1
Host: auth.aweber.com
Content-Type: application/x-www-form-urlencoded

parameters-omitted

HTTP/1.1 302 Found
Location: https://127.0.0.1/oauth2-callback?state=62cdb1ee8a5c40f6ba0d5de1dfa83113&code=VhXKzYi5paFfs1aYqgikSw

The external application exchanges the authorization code for an access token.

POST /oauth2/token HTTP/1.1
Host: auth.aweber.com
Content-Type: application/x-www-form-urlencoded
Accept: application/json
Authorization: Basic TjFud09uaEFVeUVqSmNBMGw0ZUk3ZENmWUtOVml6U0RFNExlMEo0RlJxYzpyU3U5TlU3MHhPWkZOMm9qbldxM3RMSTQ5a2I4dnM4NF9LWlFlMWJjSnk0

grant_type=authorization_code&code=VhXKzYi5paFfs1aYqgikSw&redirect_uri=https%3A%2F%2F127.0.0.1%2Foauth2-callback

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache

{
  "access_token": "uPloUGQL689I9qYk1nkwjb2yZirWnoja",
  "refresh_token": "XF2OZN3dmSSphGimcoNbq839UGT0lGo2",
  "expires_in": 7200,
  "state": "62cdb1ee8a5c40f6ba0d5de1dfa83113"
}

Public protocol flow

The following HTTP trace shows the entire flow for a Public client using the following parameters:

Parameter Value
Client ID N1nwOnhAUyEjJcA0l4eI7dCfYKNVizSDE4Le0J4FRqc
Code verifier HLBvz1g_bbLZ31kjvlXJ5Rl0W1GgxU8rjYJdQIIEH_Y
Scopes account.read list.read subscriber.read
Redirect URI https://127.0.0.1/oauth2-callback
State 62cdb1ee8a5c40f6ba0d5de1dfa83113
Authorization code VhXKzYi5paFfs1aYqgikSw

The web application initiates the authorization flow.

GET /oauth2/authorize?response_type=code&client_id=N1nwOnhAUyEjJcA0l4eI7dCfYKNVizSDE4Le0J4FRqc&code_challenge=-oiamT7-EafhQ27P3V9cGEtu3crg731kec-GWhgrTV8&code_challenge_method=S256&redirect_uri=https%3A%2F%2F127.0.0.1%2Foauth2-callback&scope=account.read+list.read+subscriber.read&state=62cdb1ee8a5c40f6ba0d5de1dfa83113 HTTP/1.1
Host: auth.aweber.com

HTTP/1.1 200 OK
Content-Type: text/html

<html>.... authorization form ....</html>

The authorization form action initiates a POST to the AWeber authorization server which redirects the user to the application-specified redirect URL.

The user authenticates and authorizes the application.

POST /oauth2/authorize HTTP/1.1
Host: auth.aweber.com
Content-Type: application/x-www-form-urlencoded

parameters-omitted

HTTP/1.1 302 Found
Location: https://127.0.0.1/oauth2-callback?state=62cdb1ee8a5c40f6ba0d5de1dfa83113&code=VhXKzYi5paFfs1aYqgikSw

The external application exchanges the authorization code for an access token.

POST /oauth2/token HTTP/1.1
Host: auth.aweber.com
Content-Type: application/x-www-form-urlencoded
Accept: application/json

grant_type=authorization_code&code=VhXKzYi5paFfs1aYqgikSw&code_verifier=HLBvz1g_bbLZ31kjvlXJ5Rl0W1GgxU8rjYJdQIIEH_Y&client_id=N1nwOnhAUyEjJcA0l4eI7dCfYKNVizSDE4Le0J4FRqc

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache

{
  "access_token": "uPloUGQL689I9qYk1nkwjb2yZirWnoja",
  "refresh_token": "XF2OZN3dmSSphGimcoNbq839UGT0lGo2",
  "expires_in": 7200,
  "state": "62cdb1ee8a5c40f6ba0d5de1dfa83113"
}

OAuth 2.0 Reference

These endpoints are used to authenticate with the api. The AWeber API uses the OAuth 2.0 model to handle authentication. OAuth is a standardized way for services to grant permission on a user's behalf to another application, without exposing their credentials (ie - username and password).</