Subscribers API
- Table of Contents
- Remote Lists
- Get a list of subscribers
- Get subscriber details
- Create a new subscriber
- Update an existing subscriber
- Trigger Autoresponders on a Subscriber
- Unsubscribe
Remote Lists
Subscribers are not available on Remote Lists. API calls to these endpoints will return an error message if attempted on a Remote List.
Get a list of subscribers
Get the details for all subscribers on this list.
URL
GET /ga/api/v2/mailing_lists/:mailing_list_id/subscribers
Request Parameters
mailing_list_id |
The |
Pagination
This endpoint returns its records paginated. The subscriber records will be sorted by their id
in ascending order.
Querying without any additional parameters will return the first page. The following extra parameters may be specified.
page |
The page number to retrieve (starts at |
page_token |
The page token to retrieve. This is explained below. |
per_page |
The number of records to return per page (default |
There are two ways to page through the data:
-
Sequentially increment
page
to specify additional page numbers until you have retrieved every page of the results. When subscribers are added or removed the page boundaries may shift, and it’s possible that some subscribers will be missed between pages or returned on two adjacent pages. -
Provide in
page_token
thenext_page_token
value returned by the most recent call to this API which got the previous page. This guarantees that the next returned page will start immediately after the previous page, with all pages being contiguous and non-overlapping. When anext_page_token
of null is returned, that indicates that this is the last page.
If you are presenting a list of pages to the user, you probably want to use page
. If you want to retrieve all of the data, page_token
is likely what you want. (When retrieving all data, the page_token
method allows SendSage to more efficiently provide the data.)
Both page
and page_token
may not be specified in the same request.
Response
The response will be an array of subscriber hashes, the same as returned by the Get subscriber details endpoint documented below.
Example
> GET /ga/api/v2/mailing_lists/1/subscribers?per_page=2 HTTP/1.1
> Authorization: Basic MTpkOTgzOGM4MDBlMmY3ODAxMWY0MTc1NWUzMGIwY2QzNWJiYTA1ZDYx
> Accept: application/json
> Content-Type: application/json
< Content-Type: application/json; charset=utf-8
< X-UA-Compatible: IE=Edge
< ETag: "9394b6420de28ae7f15744c4a7aa9681"
< Cache-Control: max-age=0, private, must-revalidate
< Set-Cookie: _session_id=67423ec44938ad4beb4de1f8e9c684a0; path=/; HttpOnly
< X-Request-Id: 12cc0a5d90bbc75779478a30e8793e6b
< X-Runtime: 0.077669
< Connection: close
< Server: thin 1.5.0 codename Knife
{
"success": true,
"error_code": null,
"error_message": null,
"per_page": 2,
"page": 0,
"data": [
{
"id": 1,
"mailing_list_id": 1,
"email": "user-1@discardallmail.drh.net",
"created_at": "2015-03-09T10:34:04-05:00",
"created_at_epoch": 1425915244,
"status": "active",
"subscribe_time": "2015-03-09T10:34:04-05:00",
"subscribe_time_epoch": 1425915244,
"subscribe_ip": null,
"custom_fields": {
"new field 1": {
"name": "new field 1",
"type": "text",
"value": null
},
"new field 2": {
"name": "new field 2",
"type": "text",
"value": null
}
}
},
{
"id": 2,
"mailing_list_id": 1,
"email": "user-2@discardallmail.drh.net",
"created_at": "2015-03-09T10:36:55-05:00",
"created_at_epoch": 1425915415,
"status": "active",
"subscribe_time": "2015-03-09T10:36:55-05:00",
"subscribe_time_epoch": 1425915415,
"subscribe_ip": "10.0.81.5",
"custom_fields": {
"new field 1": {
"name": "new field 1",
"type": "text",
"value": null
},
"new field 2": {
"name": "new field 2",
"type": "text",
"value": null
}
}
}
],
"next_page_token": "EDZmZjYkFGOjlzM"
}
Get subscriber details
Get the details for up to 100 subscribers at a time.
URL
GET /ga/api/v2/mailing_lists/:mailing_list_id/subscribers/:subscriber_ids_or_emails
Request Parameters
mailing_list_id |
The |
subscriber_ids_or_emails |
A comma-separated list of up to |
Notes
-
The email addresses in the request should be URI encoded.
-
If the request includes an email address used by multiple subscribers on the mailing list (as might be the case if the mailing list uses an alternate primary key), the API will return all subscribers with that email address.
Response
The response will be a JSON array where each element contains the following keys.
id integer |
The |
||||||
mailing_list_id integer |
The |
||||||
email string |
The subscriber’s email address |
||||||
created_at string |
The date the subscriber record was added to SendSage Studio. |
||||||
email_format string |
The subscriber’s email format. This column is only presented for mailing lists which use the Format field. |
||||||
status string |
The status of the subscriber. |
||||||
subscribe_time string |
The time the subscriber subscribed. |
||||||
subscribe_ip string |
The IP the subscriber subscribed from. This can be null if it is unknown. |
||||||
custom_fields hash The key for each entry is the name of the custom field. The value is a hash with the keys listed below.
|
Example Request
> GET /ga/api/v2/mailing_lists/1/subscribers/1,2 HTTP/1.1
> Authorization: Basic MTo1ZTk2NDY1Yzg4M2YzMzA5ZjAxMDVhMmUxMDc2NjMyYjY4N2U2MWQy
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: sendsage-studio.dev
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/html
< X-UA-Compatible: IE=Edge
< ETag: "68a7c81054bbf60f3b6ee5c481e5245b"
< Cache-Control: max-age=0, private, must-revalidate
< Set-Cookie: _session_id=ef4d24b30d8700118859eb7a8d0d291c; path=/; HttpOnly
< X-Request-Id: 3a5478ebf7c8d5bc047c8d989403c863
< X-Runtime: 0.028557
< Connection: close
{
"data": [
{
"created_at": "2013-01-31T14:25:48-06:00",
"custom_fields": {
"First Name": {
"name": "First Name",
"type": "text",
"value": "Bob"
},
"boolean test": {
"name": "boolean test",
"type": "boolean",
"value": false
},
"boolean test yes by default": {
"name": "boolean test yes by default",
"type": "boolean",
"value": true
},
"radio test": {
"name": "radio test",
"type": "select_single_radio",
"value": "bar"
}
},
"email": "bob@example.com",
"id": 1,
"mailing_list_id": 1,
"status": "active",
"subscribe_ip": null,
"subscribe_time": "2013-01-31T14:25:48-06:00"
},
{
"created_at": "2013-01-31T14:25:48-06:00",
"custom_fields": {},
"email": "joe@example.net",
"id": 2,
"mailing_list_id": 1,
"status": "active",
"subscribe_ip": null,
"subscribe_time": "2013-01-31T14:25:48-06:00"
}
],
"error_code": null,
"error_message": null,
"success": true
}
Create a new subscriber
URL
POST /ga/api/v2/mailing_lists/:mailing_list_id/subscribers
Request Parameters
mailing_list_id integer |
The mailing list to onto which to add the subscriber |
Request Payload
The POST request should have a JSON document in its payload with all of the following keys.
subscriber hash
|
|||||||||||||||||||
confirmation_form_id integer |
If provided, this user will not be immediately added. Instead, the user will be sent a confirmation email. Only after clicking the link provided in the confirmation email will the user be added to the mailing list. If the new subscriber’s status is not
|
In order for an autoresponder to be triggered for later sending, the following must be true:
- The
skip_autoresponders
field must not be enabled. - The autoresponder must trigger on Subscription.
- The autoresponder trigger must be configured with the
Run From API?
option enabled. - If specified, the
autoresponder_filter
field will reduce the list of autoresponders that are run to those whose name matches the glob, where*
is a wildcard character. - If specified, the
autoresponder_exclude_reacted
field will cause all autoresponders to be skipped if any autoresponder remaining at this point contains a reaction in the queue for this subscriber. This only evaluates autoresponders that: (a) are configured withRun from API?
as true (step 3), (b) match the pattern provided inautoresponder_filter
if present (step 4), and (c) are paused or un-paused.
Response
A successful response will return the subscriber record using the format described in the “Get subscriber details” section of the API.
A failure will return a standard error response with an explanation of what went wrong.
Example
> POST /ga/api/v2/mailing_lists/4/subscribers HTTP/1.1
> Authorization: Basic MTo1ZTk2NDY1Yzg4M2YzMzA5ZjAxMDVhMmUxMDc2NjMyYjY4N2U2MWQy
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: sendsage-studio.dev
> Accept: */*
> Content-Length: 430
> Content-Type: application/json
{
"subscriber": {
"custom_fields": {
"First Name": "Ted",
"boolean test": false,
"boolean test yes by default": true,
"radio test": "bar"
},
"email": "ted@example.com",
"mailing_list_id": 4,
"status": "active",
"subscribe_ip": null,
"subscribe_time": "2013-02-01T08:22:42-06:00"
}
}
< HTTP/1.1 200 OK
< Content-Type: text/html
< X-UA-Compatible: IE=Edge
< ETag: "e5794f737673a63d76a5741a66332d22"
< Cache-Control: max-age=0, private, must-revalidate
< Set-Cookie: _session_id=d27440cb5fba4c7a579920acd8986636; path=/; HttpOnly
< X-Request-Id: 293ca6db3ed520f5be284686cfc7b7ed
< X-Runtime: 0.046717
< Connection: close
{
"data": {
"created_at": "2013-03-29T13:27:50-05:00",
"custom_fields": {
"First Name": {
"name": "First Name",
"type": "text",
"value": "Ted"
},
"boolean test": {
"name": "boolean test",
"type": "boolean",
"value": false
},
"boolean test yes by default": {
"name": "boolean test yes by default",
"type": "boolean",
"value": true
},
"radio test": {
"name": "radio test",
"type": "select_single_radio",
"value": "bar"
}
},
"email": "ted@example.com",
"id": 3386566,
"mailing_list_id": 4,
"status": "active",
"subscribe_ip": null,
"subscribe_time": "2013-02-01T08:22:42-06:00"
},
"error_code": null,
"error_message": null,
"success": true
}
Example code
Update an existing subscriber
URL
PUT /ga/api/v2/mailing_lists/:mailing_list_id/subscribers/:subscriber_id
Request Parameters
mailing_list_id |
The mailing list to onto which to add the subscriber |
subscriber_id |
The id of the subscriber to update |
Request Payload
The PUT request should have a JSON document in its payload with all of the following keys.
email(string):
The subscriber's email address
email_format(string):
The subscriber's email format. This column is only needed for mailing lists which use the `Format` field.
status(string):
The status of the subscriber.
subscribe_time(string):
The time the subscriber subscribed.
subscribe_ip(string):
The ip the subscriber subscribed from. This can be `null` if it is unknown.
custom_fields hash / optional |
A hash of custom field values. The keys of this hash should be the name of the custom field, and the values of this hash should be the new value of the custom field. run_autoresponders(boolean): Run autoresponders on this subscriber as though it was just created. Defaults to |
- The
run_autoresponders
option does not affect reactions that are already in the queue. Using this parameter, it is possible for an autoresponder to be sent to the same subscriber multiple times.
Response
A successful response will return the subscriber record using the format described in the “Get subscriber details” section of the API.
A failure will return a standard error response with an explanation of what went wrong.
Example
> PUT /ga/api/v2/mailing_lists/4/subscribers/10012 HTTP/1.1
> Authorization: Basic MTo1ZTk2NDY1Yzg4M2YzMzA5ZjAxMDVhMmUxMDc2NjMyYjY4N2U2MWQy
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: sendsage-studio.dev
> Accept: */*
> content-type: application/json
> Content-Length: 343
{
"subscriber": {
"custom_fields": {
"First Name": "bobbie",
"boolean test": false,
"boolean test yes by default": true,
"radio test": "bar"
},
"email": "renamed@example.com",
"status": "active",
"subscribe_ip": null,
"subscribe_time": "2013-02-01T08:22:42-06:00"
}
}
< HTTP/1.1 200 OK
< Content-Type: text/html
< X-UA-Compatible: IE=Edge
< ETag: "2b2badce6c43e80e30a9d85aea2c9dff"
< Cache-Control: max-age=0, private, must-revalidate
< Set-Cookie: _session_id=68685553f5c70ce29e9b03929e5201b0; path=/; HttpOnly
< X-Request-Id: bdce4f074d21a3a3c8ccfca067852cdd
< X-Runtime: 0.024645
< Connection: close
<
* Closing connection #0
{
"data": {
"created_at": "2013-02-01T08:22:42-06:00",
"custom_fields": {
"First Name": {
"name": "First Name",
"type": "text",
"value": "bobbie"
},
"boolean test": {
"name": "boolean test",
"type": "boolean",
"value": false
},
"boolean test yes by default": {
"name": "boolean test yes by default",
"type": "boolean",
"value": true
},
"radio test": {
"name": "radio test",
"type": "select_single_radio",
"value": "bar"
}
},
"email": "renamed@example.com",
"id": 10012,
"mailing_list_id": 4,
"status": "active",
"subscribe_ip": null,
"subscribe_time": "2013-02-01T08:22:42-06:00"
},
"error_code": null,
"error_message": null,
"success": true
}
Example code
Trigger Autoresponders on a Subscriber
This endpoint will trigger autoresponders for a single subscriber. The list of autoresponders to trigger may be provided by name or by ID.
Any autoresponder(s) may be triggered using this endpoint – it is not restricted to just autoresponders configured to use an “API” trigger.
If any error is returned by this method, no autoresponders will be triggered.
URL
POST /ga/api/v2/mailing_lists/:mailing_list_id/subscribers/:subscriber_id_or_email/trigger_autoresponders
Request Parameters
In the URL of the request, the following values must be replaced.
mailing_list_id integer |
The ID of the mailing list that contains the subscriber record. |
subscriber_id_or_email string |
This may either be the numeric ID for the subscriber record, or an email address. If this value is an email address, it must be URI escaped. For example, |
Request Payload
The body of this request should be a JSON hash with the following keys.
create_missing_subscriber boolean — default false
|
Studio can only send autoresponders to subscribers that are on the mailing list. If the subscriber is not found on the mailing list and this flag is true, the subscriber will be added to the mailing list.
NOTE: On-subscription autoresponders that are configured to respond to subscribers created on the API will be triggered on subscribers created due to this flag. This can be prevented with the WARNING: If you are also using this mailing list to send campaigns, you need to make sure you’re not implicitly subscribing people to get mailing list messages from you, if that’s not what you want. |
||||||||
reactivate_subscriber boolean — default false
|
Studio can only send autoresponders to subscribers that have a status of If the requested subscriber exists on the mailing list and is in a non-active status:
WARNING: If you are also using this mailing list to send campaigns, be careful with this flag! This will reactivate the subscriber, potentially causing them to receive campaigns from which they had previously unsubscribed. |
||||||||
skip_subscription_autoresponders boolean — default false
|
Set this value to |
||||||||
autoresponder_names array of strings |
The list of autoresponders, by name, that should be triggered. The asterisk ( </p> |
||||||||
autoresponder_ids array of integers |
The list of autoresponders, by numeric ID, that should be triggered. Only one of |
||||||||
content_replacement_fields hash of strings to strings |
If provided, the key/value pairs in this hash will be interpolated into the content of the autoresponder, prefixed with an
For example, if you provide the hash
These values are only used for interpolation into the email(s) generated by this API request. Any subsequent autoresponders or campaigns sent to this subscriber will have no knowledge or history of these These values are not passed to Special Sending Rules. Fields present in this hash will override Custom Field counterparts with the same name. If you include a `content_replacement_fields` key `First Name`, it will override any custom field named `API:First Name`. The hash keys are validated as follows:
If a key is passed that does not match this, an `invalid_request` error will be returned. |
||||||||
custom_fields hash
Each value in this hash contains custom field data to be applied to the subscriber record. These hashes should be like
By default, if the subscriber is not active, this update will be not be applied. If
The more specific hashes take precedence over the If the provided (or if a custom field is required, and not provided) custom fields result in a validation error on the subscriber record, no autoresponder will be sent. A validation error will be returned.
|
Response
A successful response will contain the following keys.
triggered_autoresponders array of hashes
|
|||||
subscriber hash |
The subscriber record that was used for this call, as described in the format described in the “Get subscriber details” section of this API. The record that is returned will be after any updates in this request have been applied. |
||||
subscription_result string |
The result of the subscript as a result of this API call. If the subscriber was created, this value will be created .If the subscriber already existed and was active, this value will be remained_active .If the subscriber already existed and was reactivated, this value will be reactivated .If none of those situations applied, this call should have already resulted in an error. |
Example
> POST /ga/api/v2/mailing_lists/2/subscribers/bob%40example.com/trigger_autoresponders HTTP/1.1
> Authorization: Basic MToyYjBmNTA5YjQ3MDk1ODk0Mzk5ZWRkMGVhODE1ZDlkMjQ4MzUwYjc4
> Accept: application/json
> Content-Type: application/json
{
"autoresponder_ids": [
203
],
"custom_fields": {
"for_new": {
"First Name": "Bob",
"Last Name": "Example"
}
},
"create_missing_subscriber": true
}
< Content-Type: application/json; charset=utf-8
< X-UA-Compatible: IE=Edge
< ETag: "29694bdf4c95e5a20de5d440073eff40"
< Cache-Control: max-age=0, private, must-revalidate
< Set-Cookie: _session_id=f6f0a9eac82fc88c3bbb036e0ac74390; path=/; HttpOnly
< X-Request-Id: a62aeb23d79348c61ddecaffaf231575
< X-Runtime: 0.183498
< Connection: close
< Server: thin
{
"success": true,
"data": {
"triggered_autoresponders": [
{
"id": 203,
"name": "by api"
}
],
"subscriber": {
"id": 3430120,
"mailing_list_id": 2,
"email": "bob@example.com",
"created_at": "2015-09-29T14:07:34-05:00",
"created_at_epoch": 1443553654,
"status": "active",
"subscribe_time": "2015-09-29T14:07:34-05:00",
"subscribe_time_epoch": 1443553654,
"subscribe_ip": null,
"custom_fields": {
"First Name": {
"name": "First Name",
"type": "text",
"value": "Bob"
},
"Last Name": {
"name": "Last Name",
"type": "text",
"value": "Example"
}
}
},
"subscription_result": "created"
},
"error_code": null,
"error_message": null
}
Unsubscribe
Unsubscribe a subscriber using a token from the delivered email. This will cause the unsubscribe event to be associated with the specific campaign/content in which the token was delivered.
The token which should be sent to this endpoint may be generated in the campaign content by including the replacement code %%unsubscribe_token%%
.
URL
POST /ga/api/v2/subscribers/unsubscribe
Request Payload
unsubscribe hash
|
Response
A successful response will return the subscriber record using the format described in the “Get subscriber details” section of the API.
A failure will return a standard error response with an explanation of what went wrong.
Example
> POST /ga/api/v2/subscribers/unsubscribe HTTP/1.1
> Authorization: Basic MTpiYTVhZjYzN2JhYjA0NzM0ZjMyMDUwMTBkZWQyZjA3NGMzYmU2YTM1
> Accept: application/json
> Content-Type: application/json
{
"unsubscribe": {
"token": "0E2MiJGZlV2Y10iY4gTZhJWO3QTYyETM2EWLy0SMtETLx0iM",
"ip": "127.0.0.7"
}
}
< Content-Type: application/json; charset=utf-8
< X-UA-Compatible: IE=Edge
< ETag: "4778db54a2512804124ea70383ffa61c"
< Cache-Control: max-age=0, private, must-revalidate
< Set-Cookie: _session_id=044b98a3732095dd7bedcd96497215da; path=/; HttpOnly
< X-Request-Id: d3c93e6c84f61186f733dbbb3c354265
< X-Runtime: 0.105547
< Connection: close
< Server: thin 1.5.0 codename Knife
{
"success": true,
"data": {
"id": 1,
"mailing_list_id": 1,
"email": "user-1@discardallmail.drh.net",
"created_at": "2015-06-19T14:19:12-05:00",
"created_at_epoch": 1434741552,
"status": "unsubscribed",
"subscribe_time": "2015-06-19T14:19:12-05:00",
"subscribe_time_epoch": 1434741552,
"subscribe_ip": null,
"custom_fields": {
"First Name": {
"name": "First Name",
"type": "text",
"value": "Bob the Builder"
}
}
},
"error_code": null,
"error_message": null
}