API client to access Text Marketer's RESTful API, allows you to send SMS, check credits, create accounts, and more.
This class has been designed to be sub-classed, so that you can create a subclass with your API username/password pre-set in the variables $defaultUsername and $defaultPassword and thus use new versions of this class as they are released, without the need for modifying your defaults.
CHANGE LOG
v1.4 Added delete scheduled SMS v1.3 Added schedule parameter to SMS send. v1.2 Misc refactoring and bug fixes. Improved suitability for subclassing. Added sub-account creation function. Updated to REST DTDs v1.6.
| copyright |
Copyright (c) 2012, Text Marketer |
|---|---|
| link |
http://www.textmarketer.co.uk/developers/restful-api.htm |
| version |
__construct(string $username = null, string $password = null, string $env = 'sandbox') : \TMRestClient
stringyour API Gateway Username
stringyour API Gateway Password
stringpossible values 'sandbox' or 'production'
\TMRestClientTMRestClient
isLoginValid() : boolean
isLoginValid())
echo 'Login is valid.';
} catch (Exception $ex) {
$errors = $tmClient->getLastErrors();
foreach($errors as $errorcode => $errormsg)
echo "Code $errorcode: $errormsg";
}
?>
| throws |
on error |
|---|---|
booleanTRUE if login valid, FALSE if username or password not correct
sendSMS(string $message, string $mobile_number, string $originator, integer $validity = 72, string $email = '', string $custom = '', string $schedule = null) : array
| link |
http://www.textmarketer.co.uk/blog/2009/07/bulk-sms/supported-and-unsupported-characters-in-text-messages-gsm-character-set/ |
|---|---|
| throws |
on error
|
stringThe textual content of the message to be sent. Up to 612 characters from the GSM alphabet. The SMS characters we can support is documented at @link http://www.textmarketer.co.uk/blog/2009/07/bulk-sms/supported-and-unsupported-characters-in-text-messages-gsm-character-set/. Please ensure that data is encoded in UTF-8.
stringThe mobile number of the intended recipient, in international format, e.g. 447777123123. Only one number is allowed. To send a message to multiple recipients, you must call the API for each number.
stringA string (up to 11 alpha-numeric characters) or the international mobile number (up to 16 digits) of the sender, to be displayed to the recipient, e.g. 447777123123 for a UK number.
integerOptional. An integer from 1 to 72, indicating the number of hours during which the message is valid for delivery. Messages which cannot be delivered within the specified time will fail.
stringOptional. Available to txtUs Plus customers only. Specifies the email address for incoming responses. If you specify an email address, you must specify an originator that is a txtUs Plus number that is on your account, or you will get an error response.
stringOptional. An alpha-numeric string, 1-20 characters long, which will be used to 'tag' your outgoing message and will appear in delivery reports, thus facilitating filtering of reports
stringOptional parameter to schedule the message to send at a given time, should be in ISO 8601 format or UNIX Timestamp (Europe/London time)
arrayarray with 4 keys: 'message_id', 'scheduled_id', 'credits_used', 'status' e.g. $result['message_id']
deleteSMS(string $scheduled_id) : array
| throws |
on error
|
|---|---|
stringThe id of the scheduled text message, as returned by the sendSMS method.
arrayarray with 2 keys: 'scheduled_id', 'status', e.g. $result['status']
getCredits() : int
| throws |
on error
|
|---|---|
intnumber of credits currently available on your account.
transferCreditsToAccount(integer $quantity, string $targetAccountNumber) : array
| throws |
on error
|
|---|---|
integerThe number of credits to transfer from the source account to the target account.
stringThe account number of the account to transfer the credits to (available in the web-based UI)
arrayarray with four keys: 'source_credits_before', 'source_credits_after', 'target_credits_before' and 'target_credits_after' e.g. $result['source_credits_after']
transferCreditsToUser(integer $quantity, string $target_username, string $target_password) : array
| throws |
on error
|
|---|---|
integerThe number of credits to transfer from the source account to the target account.
stringThe username of the account to transfer the credits to.
stringThe password of the account to transfer the credits to.
arrayarray with four keys: 'source_credits_before', 'source_credits_after', 'target_credits_before' and 'target_credits_after' e.g. $result['source_credits_after']
getKeyword($keyword)
| deprecated |
Replaced by TMRestClient=>getKeywordAvailability() |
|---|---|
getKeywordAvailability(string $keyword) : array
A reply keyword allows you receive incoming text messages to your account by providing people with a keyword, which they text to the short code 88802, e.g. text 'INFO' to 88802 to see this in action.
| throws |
on error
|
|---|---|
stringthe keyword to check is availability
arrayarray with two keys: 'available' and 'recycle' e.g. $result['available']
getGroups() : array
Also lists 'stop groups' - numbers in these groups will never be sent messages. Every account has at least one stop group, so that your recipients can always opt out of receiving messages from you. This is a legal requirement.
| throws |
on error
|
|---|---|
arrayarray with all groups, one per array row, each group row have 4 keys: 'is_stop', 'id', 'numbers' and 'name' e.g. name of the first returned group $groups[0]['name']
addNumbersToGroupWithName(array $numbersArray, string $groupName) : array
| throws |
on error
|
|---|---|
arrayThe MSISDN (mobile number(s)) you wish to add
stringGroup name or group ID to add the numbers to
arrayarray with 3 keys: 'added', 'stopped' and 'duplicates', each one with an array of numbers
addNumbersToGroup($groupName, $numbers)
| deprecated |
Replaced by TMRestClient->addNumbersArrayToGroup() |
|---|---|
getGroup(string $group) : array
Shows only one group, and includes all the numbers in the group, if there are any.
| throws |
on error
|
|---|---|
stringGroup name or group ID to get the details of
arrayarray with 5 keys: 'name', 'numbers', 'id', 'is_stop' and 'number'
addGroup(string $group) : array
| throws |
on error
|
|---|---|
stringthe new group name
arrayarray with 4 keys: 'name', 'numbers', 'id', 'is_stop'
getDeliveryReports() : array
| throws |
on error
|
|---|---|
arrayarray with 2 keys: 'userdirectory' and 'reports'; reports is an array where each row is a report array with keys 'name', 'last_updated', 'extension'
getDeliveryReport(string $name, string $date_start = null, string $date_end = null, string $custom = null) : array
Whereas the function getDeliveryReports() gets a list of available delivery report names, including delivery reports for campaigns. NOTE that an exception is thrown if no reports are found
e.g. for a delivery report with the name 'mycampaign-020411'
$result = $tmClient->getDeliveryReport('mycampaign-020411');
e.g. to get the delivery report details for 'mycampaign-020411' between 01:00 and 02:00 on 1st Jan 2011
$result = $tmClient->getDeliveryReport('mycampaign-020411', '2011-01-01T01:00:00+00:00', '2011-01-01T02:00:00+00:00');
$result = $tmClient->getDeliveryReport('mycampaign-020411', '2011-01-01T01:00:00+00:00', time());
e.g. to get delivery report details for all campaigns and API sends between the same dates as above
$result = $tmClient->getDeliveryReport('all', '2011-01-01T01:00:00+00:00', '2011-01-01T02:00:00+00:00');
$result = $tmClient->getDeliveryReport('all', '2011-01-01T01:00:00+00:00', time());
e.g. for a delivery report with the name 'mycampaign-020411' and custom tag 'test' or all
$result = $tmClient->getDeliveryReport('mycampaign-020411', null, null, 'test');
$result = $tmClient->getDeliveryReport('all', null, null, 'test');
$result = $tmClient->getDeliveryReport('mycampaign-020411', '2011-01-01T01:00:00+00:00', '2011-01-01T02:00:00+00:00', 'test');
$result = $tmClient->getDeliveryReport('all', '2011-01-01T01:00:00+00:00', time(), 'test');
| throws |
on error OR NO REPORTS FOUND (404)
|
|---|---|
stringName of the delivery report to retrieve or 'all' to retrieve all campaign/API report data
stringOptional parameter get delivery report from $date_start, should be in ISO 8601 or UNIX Timestamp (Europe/London time)
stringOptional parameter get delivery report to $date_end, should be in ISO 8601 or UNIX Timestamp (Europe/London time)
stringOptional Can specify a custom 'tag', which will restrict the search to those messages you sent with that tag (see 'custom' parameter of sendSms method).
arrayarray with 4 keys: 'name', 'last_updated', 'extension' and 'reportrow', reportrow is an array with keys 'message_id', 'mobile_number', 'status' and 'last_updated'
createSubAccount(string $companyName, \type $notificationMobile = null, \type $notificationEmail = null, string $username = null, string $password = null, string $promoCode = null, boolean $overrideRates = false) : array
createAccount('New Company');
} catch (Exception $ex) {
$errors = $tmClient->getLastErrors();
foreach($errors as $errorcode => $errormsg)
echo "Code $errorcode: $errormsg";
}
?>
| throws |
on error |
|---|---|
stringthe company name for the new account owner
\type(optional) the mobile number of the account (required if $notificationEmail is not set)
\type(optional) the email address of the account (required if $notificationMobile is not set)
string(optional) the username you wish to set on the new account - the API username will be the same
string(optional) the password you wish to set on the new account - the API password will be the same
string(optional) a promotional code entitling the account to extra credits
booleanIf set to true, use the credits rates set on your main account (the account used to access the API), rather than the Text Marketer defaults.
arrayarray with 10 keys: 'api_password', 'api_username', 'company_name', 'create_date', 'credits', 'password' and 'username', 'notification_email', 'notification_mobile', 'account_id'
getLastErrors() : array
arrayassociative array with 'error_code'=>'error message' format. Could have more then 1 error code.
isLoginValid())
echo 'Login is valid.';
} catch (Exception $ex) {
$errors = $tmClient->getLastErrors();
foreach($errors as $errorcode => $errormsg)
echo "Code $errorcode: $errormsg";
}
?>
addError(string $code, string $msg, boolean $new = true)
stringError code
stringError message
booleanTRUE is a new error, code
restGatewayCall($service = 'credits', $method = 'GET', $params = NULL) : string
| throws |
on error |
|---|---|
string$xml XML response from the REST API
doCreateAccount(string $companyName, \type $notificationMobile = null, \type $notificationEmail = null, string $username = null, string $password = null, string $promoCode = null, boolean $overrideRates = false, $resource = 'account/sub') : array
| throws |
on error |
|---|---|
string
\type
\type
string
string
string
boolean
array
PROD_URL
SAND_URL
VERSION
| var | |
|---|---|
defaultUsername
| var | |
|---|---|
defaultPassword
| var | |
|---|---|
username
password
lastErrors
apiUrl
responseBody
forceSandbox