Introduktion

RuleMailer API v3.0
RuleMailer är utrustat med ett kraftfullt API. Utöka din applikation till att även kommunicera med RuleMailer. Det är väldigt enkelt att komma igång.
Här nedan följer en presentation av alla funktioner.
API example module for RuleMailer
Holds all the API functions for RuleMailer API.
All methods return an array, with first two elements being: error_code and status. For example: array( error_code = 0, status = Success ).
The code examples are written in PHP and are called with:
$wsdl = 'http://one.rulemailer.com/api3.3.php?wsdl'; //url to the wsdl
$soapClient = new SOAPClient($wsdl); //setup the soapclient
$key='xxx'; // the key is used in every call to the web service
Functions
Creates a Campaign
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| string | $campaign_name | The campaign name |
| int | $list_id | The recipient list |
| int | $email_id | The id of the email to be sent, set to empty if the email shall be created in RuleMailer |
| string | $time_to_send | Time to send the campaign (Now | Never | Schedule) |
| string | $send_date | If Schedule, the date to send (YYYY-MM-DD) |
| string | $send_time | If Schedule, the time to send (HH:MM:SS) |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| int | $id | The id of the created campaign |
Example code:
$campaign_name = 'Test Campaign';
$time_to_send = 'Later';
$campaign = $soapClient->campaignCreate($key, $campaign_name, $list_id, $email_id, $time_to_send);
$campaign_id = $campaign->id;
Updates a Campaign
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $campaign_id | The campaign id |
| string | $campaign_name | The campaign name |
| int | $list_id | The recipient list |
| int | $email_id | The id of the email to be sent, set to empty if the email shall be created in RuleMailer |
| string | $time_to_send | Time to send the campaign (Now | Never | Schedule) |
| string | $send_date | If Schedule, the date to send (YYYY-MM-DD) |
| string | $send_time | If Schedule, the time to send (HH:MM:SS) |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| int | $id | The id of the updated campaign |
Example code:
$campaign_name = 'Test Campaign';
$time_to_send = 'Later';
$campaign = $soapClient->campaignCreate($key, $campaign_name, $list_id, $email_id, $time_to_send);
$campaign_id = $campaign->id;
Get the campaign statistics and overview for the 7 first days
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $campaign_id | The campaign id |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| string | $campaign_name | The Campaign name |
| string | $send_date | The date the campaign got sent |
| int | $total_recipients | Total Recipients |
| int | $total_sent | Total emails sent |
| int | $total_opens | Total emails opened |
| int | $total_clicks | Total links clicked |
| int | $total_forwards | Total email forwarded |
| int | $total_browser_view | Total emails viewed in browser |
| int | $total_unsubscriptions | Total unsubscriptions |
| int | $total_clicks | Total links clicked |
| int | $total_hard_bounce | Total hard bounced emails |
| int | $total_soft_bounce | Total soft bounced emails |
| array | $open_activities | - (string) $date, the date
- (int) $total, total opens
- (int) $unique, unique opens
|
| array | $click_activities | - (string) $date, the date
- (int) $total, total clicks
- (int) $unique, unique clicks
|
Example code:
$campaign_statistics = $soapClient->campaignStatisticsOverview($key, $SAMPLE_CAMPAIGN_ID);
echo $campaign_statistics->campaign_name;
echo $campaign_statistics->send_date;
echo $campaign_statistics->total_sent;
echo $campaign_statistics->total_opens;
echo $campaign_statistics->total_clicks;
echo $campaign_statistics->total_forwards;
echo $campaign_statistics->total_browser_view;
echo $campaign_statistics->total_unsubscriptions;
echo $campaign_statistics->total_hard_bounces;
echo $campaign_statistics->total_soft_bounces;
foreach ($campaign_statistics->open_activities as $open_activity) {
echo $open_activity->date;
echo $open_activity->total;
echo $open_activity->unique;
}
foreach ($campaign_statistics->click_activities as $click_activity) {
echo $click_activity->date;
echo $click_activity->total;
echo $click_activity->unique;
}Get subscriber statistics for a specific campaign
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| string | $campaign_id | The campaign id |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| string | $campaign_name | The Campaign name |
| string | $send_date | The date the campaign got sent |
| array | $subscriber_activities | - (int) subscriber_id, the id of the subscriber
- (string) email, the email address of the subscriber
- (int) $total_opens, total opened
- (int) $total_clicks, total clicked links
- (int) $total_opens, total opened
- (array) $subscriber_activity => (string) $date, (string) $activity, (opende | clicked)
|
Example code:
$campaign_statistics_subscribers = $soapClient->campaignStatisticsSubscribers($key, $SAMPLE_CAMPAIGN_ID);
echo $campaign_statistics_subscribers->campaign_name;
echo $campaign_statistics_subscribers->send_date;
foreach ($campaign_statistics_subscribers->subscribers_activities as $subscriber_activity) {
echo $subscriber_activity->subscriber_id;
echo $subscriber_activity->email;
echo $subscriber_activity->total_opens;
echo $subscriber_activity->total_clicks;
echo $subscriber_activity->unsubscribed;
foreach ($subscriber_activity->activities as $activity) {
echo $activity->time;
echo $activity->activity;
}
}Creates the email to send out with a campaign
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| string | $from_name | The sender name of the email |
| string | $from_email | The sender email address |
| string | $email_subject | The email subject |
| string | $email_plain_text | The plain text content, must contain at least %Link:Unsubscribe% |
| string | $email_html | The HTML version, must contain at least <html><body>%Link:Unsubscribe%</body><html> |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| int | $id | the id of the created email |
Example code:
$from_name = 'John Doe';
$from_email= 'john@example.net';
$email_subject = 'Test subject';
$email_plain_text = "Hi! \n%Link:Unsubscribe%";
$email_html = '<html><body>Hi!<br><%Link:Unsubscribe%</body><html>';
$email = $soapClient->emailCreate($key, $from_name, $from_email, $email_subject, $email_plain_text, $email_html);
$email_id = $email->id;
Creates an email from an existing template
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| string | $from_name | The sender name of the email |
| string | $from_email | The sender email address |
| int | $template_id | The template id |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| int | $id | the id of the created email |
Example code:
$from_name = 'John Doe';
$from_email= 'john@example.net';
$template_id = '123';
$email = $soapClient->emailCreateFromTemplate($key, $from_name, $from_email, $template_id);
$email_id = $email->id;
Creates a subscriber list
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| string | $name | The list’s name |
| string | $type | The list type (Single | Double | Receipt) Single is a standard list, Double is a double opt-in list and Reciept, is a reciept type of list, which you can use for transactional emails. |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
Example code:
$list_create = $soapClient->listCreate($key, $list_name, $type);
$error_code = $list_create_result->error_code;
$status = $list_create->status;
$list_id = $list_create->id;
Creates a custom field for the list
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $list_id | The list id |
| string | $custom_field_name | The name of the custom field |
| string | $custom_field_type | Type of custom field (Single line | Drop down | Checkboxes | Date field | Hidden field) |
| array | $presets | Values for the more advanced field types like Drop down or Checkboxes- (string) $label, display label
- (string) $value, saved value
|
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| int | $custom_field_id | the id of the created custom field |
| string | $custom_field_name | the name of the created custom field |
Example code:
$custom_field_name = 'First name';
$custom_field_type = 'Single line';
$presets = '';
$custom_field = $soapClient->listCustomFieldUpdate($key, $list_id, $custom_field_id, $custom_field_name, $custom_field_type, $presets);
$custom_field_id = $custom_field->id;
$custom_field_name = $custom_field->name;
Returns all custom fields for a list
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $list_id | The list id |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| array | $custom_fields | - (int) $id, the id of the custom field
- (string) $name, the name of the custom field
- (string) $type, the type of the custom field
- (array) $preset => (string) $label, (string) $value
|
Example code:
$custom_fields = $soapClient->listCustomFieldsGet($key, $list_id);
foreach ($custom_fields->custom_fields as $custom_field) {
echo $custom_field->id;
echo $custom_field->name;
echo $custom_field->type;
foreach ($custom_field->preset as $preset) {
echo $preset->label;
echo $preset->value;
}
}Updates a custom field in the list
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $list_id | The list id |
| int | $custom_field_id | The id of the custom field |
| string | $custom_field_name | The new name of the custom field |
| string | $custom_field_type | The new type of custom field (Single line | Drop down | Checkboxes | Date field | Hidden field) |
| array | $presets | Values for the more advanced field types like Drop down or Checkboxes- (string) $label, display label
- (string) $value, saved value
|
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| int | $custom_field_id | the id of the updated custom field |
| string | $custom_field_name | the name of the updated custom field |
Example code:
$custom_field_name = 'First name';
$custom_field_type = 'Single line';
$presets = '';
$custom_field = $soapClient->listCustomFieldUpdate($key, $list_id, $custom_field_id, $custom_field_name, $custom_field_type, $presets);
$custom_field_id = $custom_field->id;
$custom_field_name = $custom_field->name;
Deletes a subscriber list
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $list_ide | The list id |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
Example code:
$list_delete = $soapClient->listDelete($key, $list_id);
$error_code = $list_delete->error_code;
$status = $list_delete->status;
Get all the subscriber lists
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| array | $list | - (int) $id, the list id
- (string) $name, the list name
|
Example code:
$lists_get = $soapClient->listsGet($key);
foreach ($lists_get->lists as $lists) {
echo $lists->id;
echo $lists->name;
}Get information on single subscriber
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $list_id | The list id |
| string | $email | The emailaddress |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| int | $subscriber_id | The id of the subscriber |
| string | $email | The subscribers email address |
| string | $bounce_type | The bounce type (Not bounced | Hard bounce | Soft bounce) |
| string | $subscription_status | The subscriber status (Subscribed | Unsubscribed) |
| string | $subscription_date | The date of subscription |
| string | $unsubscription_date | The date of unsubscription |
| array | $custom_fields | - (int) $id, the custom field id
- (string) $value, the subscribers custom field value
|
Example code:
$response = $soapClient->subscriberGet($key, $list_id, $email_address);
echo $response->subscriber_id;
echo $response->email;
echo $response->bounce_type;
echo $response->subscription_status;
echo $response->subscription_date;
echo $response->unsubscription_date;
foreach ($response->custom_fields as $custom_field) {
echo $custom_field->id;
echo $custom_field->value;
}Gets all persons in a list
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $list_id | The list id |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| array | $subscribers | - (int) $subscriber_id, The id of the subscriber
- (string) $email, The subscribers email address
- (string) $bounce_type, The bounce type (Not bounced | Hard bounce | Soft bounce)
- (string) $subscription_status, The subscriber status (Subscribed | Unsubscribed)
- (string) $subscription_date, The date of subscription
- (string) $unsubscription_date, The date of unsubscription
- (array) $custom_fields => (int) $id, the custom field id, (string) $value, the subscribers custom field value
|
Example code:
$response = $soapClient->subscribersGet($key, $SAMPLE_LIST_ID);
foreach ($response->subscribers as $subscriber) {
echo $subscriber->subscriber_id;
echo $subscriber->email;
echo $subscriber->subscription_status;
echo $subscriber->bounce_type;
echo $subscriber->subscription_date;
echo $subscriber->unsubscription_date;
foreach ($subscriber->custom_fields as $custom_field) {
echo $custom_field->id;
echo $custom_field->value;
}
}Subscribes multiple persons, to a list, at once
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $list_id | The list id |
| string | $field_terminator | Corresponds to settings for csv-file, if not used, set to ”. |
| string | $field_enclosed | Corresponds to settings for csv-file, if not used, set to ”. |
| array | $field_mapping | Map columns in the csv-file against list custom fields ids in Rulemailer.- (int) $column_id, the column id in the csv file
- (int) $custom_field_id, the coresponding custom field id
|
| string | $importdata | The data to import |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
| int | $total_subscribed | The total subscribed subscribers |
Example code:
$SAMPLE_EMAIL_ADDRESSES = "'test@example.net';'John'\n'test@example.org';'Albert'"; //Rembember one subscriber on each row //Rembember one subscriber on each row
$field_terminator = ";"; // corresponds to settings for csv-file, if not used, set to ''.
$field_enclosed = "'"; // corresponds to settings for csv-file, if not used, set to ''.
$field_mapping = array(array('column_id' => '2', 'custom_field_id' => '1'));
$response = $soapClient->subscribersSubscribe($key, $SAMPLE_LIST_ID, $field_terminator, $field_enclosed, $field_mapping, $SAMPLE_EMAIL_ADDRESSES);
$total_subscribed = $response->total_subscribed;Subscribes a person to a list
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $list_id | The list id |
| string | $email | The emailaddress |
| array | $custom_fields | >Optional array for custom fields where each element is a id/value pair.- (int) $id,
- (string) $value
|
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
Example code:
$SAMPLE_LIST_ID = '1';
$SAMPLE_EMAIL_ADDRESS = 'test@example.com';
$SAMPLE_CUSTOM_FIELDS = array(array('id'=>'1', 'value' => 'John'), array('id'=>'2', 'value' => 'Doe'));
$response = $soapClient->subscriberSubscribe($key, $SAMPLE_LIST_ID, $SAMPLE_EMAIL_ADDRESS, $SAMPLE_CUSTOM_FIELDS);
$error_code = $response->error_code; //all calls resturns this
$status = $response->status; //all calls resturns thisUnsubscribes a person from a list
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $list_id | The list id |
| string | $email | The emailaddress |
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
Example code:
$response = $soapClient->subscriberUnsubscribe($key, $SAMPLE_LIST_ID, $SAMPLE_EMAIL_ADDRESS);
$error_code = $response->error_code; //all calls resturns this
$status = $response->status; //all calls resturns this
Update an existing person in a list
Input parameters:
| Type | Name | Description |
|---|
| string | $key | The key |
| int | $list_id | The list id |
| string | $email | The emailaddress |
| array | $custom_fields | >Optional array for custom fields where each element is a id/value pair.- (int) $id,
- (string) $value
|
Output parameters:
| Type | Name | Description |
|---|
| int | $error_code | The error code |
| string | $status | The status: Success | error message |
Example code:
$response = $soapClient->subscriberUpdate($key, $SAMPLE_LIST_ID, $SAMPLE_EMAIL_ADDRESS, $SAMPLE_CUSTOM_FIELDS);
$error_code = $response->error_code; //all calls resturns this
$status = $response->status; //all calls resturns this