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.
npm install unbounce-api --save
bower install unbounce-api --save
var UnbounceApi = require('unbounce-api');
var client = new UnbounceApi();
<script src="unbounce-api/index.js">
<script>
var client = new window.UnbounceApi();
</script>
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.
- Redirect user to
auth.code.getUri()
. - Parse response uri and get an access token instance using
auth.code.getToken(uri)
.
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
});
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'
}
});
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'
});
If the base URI has parameters inline, you can set them by updating the baseUriParameters
property. For example:
client.options.baseUriParameters.version = 'v0.4';
All methods return a HTTP request instance of Popsicle, which allows the use of promises (and streaming in node).
Global API meta-information.
var resource = client.resources;
Retrieve the global API meta-information.
resource.get().then(function (res) { ... });
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;
Retrieve the accounts collection.
resource.get().then(function (res) { ... });
resource.get({ ... });
- sort_order string, one of (asc, desc), default: asc
Sort by creation date.
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
- 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);
Retrieve the details of a single account.
resource.get().then(function (res) { ... });
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
API Sub Accounts are Unbounce Clients
var resource = client.resources.accounts.accountId(account_id).subAccounts;
Retrieve all sub-accounts for the specified account.
resource.get().then(function (res) { ... });
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.
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
Pages.
var resource = client.resources.accounts.accountId(account_id).pages;
Retrieve a list of all pages for the specified account.
resource.get().then(function (res) { ... });
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.
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
- 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);
Retrieve the details of a single sub-account.
resource.get().then(function (res) { ... });
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
Custom domains.
var resource = client.resources.subAccounts.subAccountId(sub_account_id).domains;
Retrieve a list of all custom domains belonging to a given sub-account.
resource.get().then(function (res) { ... });
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.
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
The leads collection provides access to all of the leads for a sub-account.
var resource = client.resources.subAccounts.subAccountId(sub_account_id).leads;
Retrieve a list of all leads for a given sub-account.
resource.get().then(function (res) { ... });
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.
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
Pages may optionally be organized into groups.
var resource = client.resources.subAccounts.subAccountId(sub_account_id).pageGroups;
Retrieve a list of all page groups for a given sub-account.
resource.get().then(function (res) { ... });
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.
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
Pages.
var resource = client.resources.subAccounts.subAccountId(sub_account_id).pages;
Retrieve a list of all pages for a given sub-account.
resource.get().then(function (res) { ... });
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.
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
- domain_id string
Customers can register custom domains with Unbounce, then publish pages to those domains.
var resource = client.resources.domains.domainId(domain_id);
Retrieve a custom domain that has been registered with Unbounce.
resource.get().then(function (res) { ... });
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
Pages.
var resource = client.resources.domains.domainId(domain_id).pages;
Retrieve a list of all pages based on the domain.
resource.get().then(function (res) { ... });
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.
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
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;
Retrieve a list of all pages.
resource.get().then(function (res) { ... });
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.
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
- page_id string
Page.
var resource = client.resources.pages.pageId(page_id);
Retrieve a single page.
resource.get().then(function (res) { ... });
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
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;
Retrieve a full list of all form fields across all page variants of a specific page.
resource.get().then(function (res) { ... });
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
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
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;
Retrieve a list of all leads for a given page.
resource.get().then(function (res) { ... });
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.
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
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) { ... });
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"
}
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;
Retrieve a list of all pages that belong to a given page group.
resource.get().then(function (res) { ... });
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.
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
- 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);
Retrieve a single lead.
resource.get().then(function (res) { ... });
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
Data for the currently authenticated user. Note that using an API Key does not authenticate as a user.
var resource = client.resources.users.self;
Retrieve the current user.
resource.get().then(function (res) { ... });
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
- user_id string
User data.
var resource = client.resources.users.userId(user_id);
Retrieves a particular user.
resource.get().then(function (res) { ... });
resource.get(null, {
headers: { ... }
});
- Accept string, one of (application/vnd.unbounce.api.v0.4+json), default: application/vnd.unbounce.api.v0.4+json
You can make requests to a custom path in the API using the #resource(path)
method.
client.resource('/example/path').get();
Apache 2.0