Skip to content

2020/unbounce-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unbounce API

Browser and node module for making API requests against Unbounce API.

Please note: This module uses Popsicle to make API requests. Promises must be supported or polyfilled on all target environments.

Installation

npm install unbounce-api --save
bower install unbounce-api --save

Usage

Node

var UnbounceApi = require('unbounce-api');

var client = new UnbounceApi();

Browsers

<script src="unbounce-api/index.js">

<script>
  var client = new window.UnbounceApi();
</script>

Authentication

OAuth 2.0

This API supports authentication with OAuth 2.0. Initialize the OAuth2 instance with the application client id, client secret and a redirect uri to authenticate with users.

var auth = new UnbounceApi.OAuth2({
  clientId:     '123',
  clientSecret: 'abc',
  redirectUri:  'http://example.com/auth/callback'
});

All getToken() calls are asynchronous and return promise objects which resolve to an access token instance.

  1. Redirect user to auth.code.getUri().
  2. Parse response uri and get an access token instance using auth.code.getToken(uri).
Access Tokens

Access token instances can be manually re-created. This is critical for access token reuse, such as saving credentials to a database for reusing later in the codebase.

var token = auth.createToken('access token', 'refresh token');

An access token instance (manually created or automatically generated by a getToken() method) can be passed into any API request. This will sign the API request with the current users access token credentials.

// Existing API client instance.
client.resource('/').get(null, {
  user: token
});

// New API client instance.
var client = new UnbounceApi({
  user: token
});

Options

You can set options when you initialize a client or at any time with the options property. You may also override options for a single request by passing an object as the second argument of any request method. For example:

var client = new UnbounceApi({ ... });

client.options = { ... };

client.resource('/').get(null, {
  baseUri: 'http://example.com',
  headers: {
    'Content-Type': 'application/json'
  }
});

Base URI

You can override the base URI by setting the baseUri property, or initializing a client with a base URI. For example:

new UnbounceApi({
  baseUri: 'https://example.com'
});

Base URI Parameters

If the base URI has parameters inline, you can set them by updating the baseUriParameters property. For example:

client.options.baseUriParameters.version = 'v0.4';

Resources

All methods return a HTTP request instance of Popsicle, which allows the use of promises (and streaming in node).

resources

Global API meta-information.

var resource = client.resources;
GET

Retrieve the global API meta-information.

resource.get().then(function (res) { ... });

resources.accounts

The accounts collection is the entry point to the rest of the Unbounce API. Your API key will give you access to all of the clients owned by your primary account.

var resource = client.resources.accounts;
GET

Retrieve the accounts collection.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.accounts.accountId(account_id)

  • account_id string

Unbounce pages belong to clients which, in turn, belong to accounts. This API exposes a single Unbounce Account to you.

var resource = client.resources.accounts.accountId(account_id);
GET

Retrieve the details of a single account.

resource.get().then(function (res) { ... });
Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.accounts.accountId(account_id).subAccounts

API Sub Accounts are Unbounce Clients

var resource = client.resources.accounts.accountId(account_id).subAccounts;
GET

Retrieve all sub-accounts for the specified account.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

  • count boolean

When true, don't return the response's collection attribute.

  • from string

Limit results to those created after from.

  • to string

Limit results to those created before to.

  • offset integer

Omit the first offset number of results.

  • limit integer, default: 50

Only return limit number of results.

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.accounts.accountId(account_id).pages

Pages.

var resource = client.resources.accounts.accountId(account_id).pages;
GET

Retrieve a list of all pages for the specified account.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

  • count boolean

When true, don't return the response's collection attribute.

  • from string

Limit results to those created after from.

  • to string

Limit results to those created before to.

  • offset integer

Omit the first offset number of results.

  • limit integer, default: 50

Only return limit number of results.

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.subAccounts.subAccountId(sub_account_id)

  • sub_account_id string

Unbounce users can use sub-accounts to manage multiple projects or clients. Each sub-account has it's own collection of pages, domains and other objects. For interactive applications, you'd often want to allow users to select a particular sub-account to work with.

var resource = client.resources.subAccounts.subAccountId(sub_account_id);
GET

Retrieve the details of a single sub-account.

resource.get().then(function (res) { ... });
Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.subAccounts.subAccountId(sub_account_id).domains

Custom domains.

var resource = client.resources.subAccounts.subAccountId(sub_account_id).domains;
GET

Retrieve a list of all custom domains belonging to a given sub-account.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

  • count boolean

When true, don't return the response's collection attribute.

  • from string

Limit results to those created after from.

  • to string

Limit results to those created before to.

  • offset integer

Omit the first offset number of results.

  • limit integer, default: 50

Only return limit number of results.

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.subAccounts.subAccountId(sub_account_id).leads

The leads collection provides access to all of the leads for a sub-account.

var resource = client.resources.subAccounts.subAccountId(sub_account_id).leads;
GET

Retrieve a list of all leads for a given sub-account.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

  • count boolean

When true, don't return the response's collection attribute.

  • from string

Limit results to those created after from.

  • to string

Limit results to those created before to.

  • offset integer

Omit the first offset number of results.

  • limit integer, default: 50

Only return limit number of results.

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.subAccounts.subAccountId(sub_account_id).pageGroups

Pages may optionally be organized into groups.

var resource = client.resources.subAccounts.subAccountId(sub_account_id).pageGroups;
GET

Retrieve a list of all page groups for a given sub-account.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

  • count boolean

When true, don't return the response's collection attribute.

  • from string

Limit results to those created after from.

  • to string

Limit results to those created before to.

  • offset integer

Omit the first offset number of results.

  • limit integer, default: 50

Only return limit number of results.

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.subAccounts.subAccountId(sub_account_id).pages

Pages.

var resource = client.resources.subAccounts.subAccountId(sub_account_id).pages;
GET

Retrieve a list of all pages for a given sub-account.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

  • count boolean

When true, don't return the response's collection attribute.

  • from string

Limit results to those created after from.

  • to string

Limit results to those created before to.

  • offset integer

Omit the first offset number of results.

  • limit integer, default: 50

Only return limit number of results.

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.domains.domainId(domain_id)

  • domain_id string

Customers can register custom domains with Unbounce, then publish pages to those domains.

var resource = client.resources.domains.domainId(domain_id);
GET

Retrieve a custom domain that has been registered with Unbounce.

resource.get().then(function (res) { ... });
Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.domains.domainId(domain_id).pages

Pages.

var resource = client.resources.domains.domainId(domain_id).pages;
GET

Retrieve a list of all pages based on the domain.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

  • count boolean

When true, don't return the response's collection attribute.

  • from string

Limit results to those created after from.

  • to string

Limit results to those created before to.

  • offset integer

Omit the first offset number of results.

  • limit integer, default: 50

Only return limit number of results.

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.pages

Access all pages for the authenticated principal. An authenticated principal is either an API Key, or an OAuth client. We provide this top-level resource specifically for OAuth clients. Any Unbounce customer can be invited to author or view a page on a different client than their own. The legacy Pages resource we provide doesn't allow for accessing these external pages. This top-level resource allows you to additionally filter pages based on the specified role.

var resource = client.resources.pages;
GET

Retrieve a list of all pages.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

  • count boolean

When true, don't return the response's collection attribute.

  • from string

Limit results to those created after from.

  • to string

Limit results to those created before to.

  • offset integer

Omit the first offset number of results.

  • limit integer, default: 50

Only return limit number of results.

  • with_stats boolean

When true, include page stats for the collection.

  • role string, one of (viewer, author), default: viewer

Restricts the scope of the returned pages.

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.pages.pageId(page_id)

  • page_id string

Page.

var resource = client.resources.pages.pageId(page_id);
GET

Retrieve a single page.

resource.get().then(function (res) { ... });
Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.pages.pageId(page_id).formFields

Form Fields specifically refers to the forms you can add to Unbounce landing pages in the Unbounce page editor.

var resource = client.resources.pages.pageId(page_id).formFields;
GET

Retrieve a full list of all form fields across all page variants of a specific page.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

  • count boolean

When true, don't return the response's collection attribute.

  • include_sub_pages boolean

When true, include sub page form fields in the response

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.pages.pageId(page_id).leads

The leads collection provides access to all of the submitted leads associated with a specific page.

var resource = client.resources.pages.pageId(page_id).leads;
GET

Retrieve a list of all leads for a given page.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

  • count boolean

When true, don't return the response's collection attribute.

  • from string

Limit results to those created after from.

  • to string

Limit results to those created before to.

  • offset integer

Omit the first offset number of results.

  • limit integer, default: 50

Only return limit number of results.

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
POST

Create a new lead. New leads created via the API are marked distinctly from those created through the webapp. Leads created via the API will have a new attribute in their extra_data field:

{ 'created_by': 'api' }
resource.post().then(function (res) { ... });
Body

application/vnd.unbounce.api.v0.4+json

{
  "$schema" : "http://json-schema.org/draft-04/schema#",
  "description" : "Representation of a new lead",
  "type" : "object",
  "additionalProperties" : false,
  "required" : [ "form_submission" ],
  "properties" : {
    "conversion" : {
      "description" : "Whether this lead should be marked as having converted or not.",
      "type" : "boolean"
    },
    "form_submission" : {
      "type" : "object",
      "additionalProperties" : false,
      "required" : [ "variant_id", "submitter_ip", "form_data" ],
      "properties" : {
        "variant_id" : {
          "description" : "The published page variant Id.",
          "type" : "string"
        },
        "submitter_ip" : {
          "description" : "Originating IP address of the lead.",
          "type" : "string"
        },
        "form_data" : {
          "description" : "Form fields and form values representing a lead.",
          "type" : "object"
        }
      }
    },
    "visitor_id" : {
      "description" : "Unbounce's internal visitor ID for tracking the lead.",
      "type" : "string"
    }
  },
  "id" : "https://api.unbounce.com/raml/v0.4/schema/new_lead.json"
}

resources.pageGroups.pageGroupId(page_group_id).pages

Pages may optionally be organized into groups. Each page group provides a link to the pages it contains in its meta data collection.

var resource = client.resources.pageGroups.pageGroupId(page_group_id).pages;
GET

Retrieve a list of all pages that belong to a given page group.

resource.get().then(function (res) { ... });
Query Parameters
resource.get({ ... });
  • sort_order string, one of (asc, desc), default: asc

Sort by creation date.

  • count boolean

When true, don't return the response's collection attribute.

  • from string

Limit results to those created after from.

  • to string

Limit results to those created before to.

  • offset integer

Omit the first offset number of results.

  • limit integer, default: 50

Only return limit number of results.

Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.leads.leadId(lead_id)

  • lead_id string

There are two sets of data associated with each lead; the form data submitted when the lead was collected, and any optional extra data provided by 3rd party integrations with Unbounce (such as lead scoring or social data). Fields within the form data collection use a normalized form of the form field name.

var resource = client.resources.leads.leadId(lead_id);
GET

Retrieve a single lead.

resource.get().then(function (res) { ... });
Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.users.self

Data for the currently authenticated user. Note that using an API Key does not authenticate as a user.

var resource = client.resources.users.self;
GET

Retrieve the current user.

resource.get().then(function (res) { ... });
Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

resources.users.userId(user_id)

  • user_id string

User data.

var resource = client.resources.users.userId(user_id);
GET

Retrieves a particular user.

resource.get().then(function (res) { ... });
Headers
resource.get(null, {
  headers: { ... }
});
  • Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json

Custom Resources

You can make requests to a custom path in the API using the #resource(path) method.

client.resource('/example/path').get();

License

Apache 2.0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published