codechito/php-client-sdk

PHP Client for using TransmitMessage's API.

dev-master 2020-01-29 01:17 UTC

This package is auto-updated.

Last update: 2024-03-29 04:19:17 UTC


README

Specialty messaging services tailored towards your business

How to Build

The generated code has dependencies over external libraries like UniRest. These dependencies are defined in the composer.json file that comes with the SDK. To resolve these dependencies, we use the Composer package manager which requires PHP greater than 5.3.2 installed in your system. Visit https://getcomposer.org/download/ to download the installer file for Composer and run it in your system. Open command prompt and type composer --version. This should display the current version of the Composer installed if the installation was successful.

  • Using command line, navigate to the directory containing the generated files (including composer.json) for the SDK.
  • Run the command composer install. This should install all the required dependencies and create the vendor directory in your project directory.

Building SDK - Step 1

[For Windows Users Only] Configuring CURL Certificate Path in php.ini

CURL used to include a list of accepted CAs, but no longer bundles ANY CA certs. So by default it will reject all SSL certificates as unverifiable. You will have to get your CA's cert and point curl at it. The steps are as follows:

  1. Download the certificate bundle (.pem file) from https://curl.haxx.se/docs/caextract.html on to your system.
  2. Add curl.cainfo = "PATH_TO/cacert.pem" to your php.ini file located in your php installation. “PATH_TO” must be an absolute path containing the .pem file.
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
;curl.cainfo =

How to Use

The following section explains how to use the TransmitMessage library in a new project.

1. Open Project in an IDE

Open an IDE for PHP like PhpStorm. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.

Open project in PHPStorm - Step 1

Click on Open in PhpStorm to browse to your generated SDK directory and then click OK.

Open project in PHPStorm - Step 2

2. Add a new Test Project

Create a new directory by right clicking on the solution name as shown below:

Add a new project in PHPStorm - Step 1

Name the directory as "test"

Add a new project in PHPStorm - Step 2

Add a PHP file to this project

Add a new project in PHPStorm - Step 3

Name it "testSDK"

Add a new project in PHPStorm - Step 4

Depending on your project setup, you might need to include composer's autoloader in your PHP code to enable auto loading of classes.

require_once "../vendor/autoload.php";

It is important that the path inside require_once correctly points to the file autoload.php inside the vendor directory created during dependency installations.

Add a new project in PHPStorm - Step 4

After this you can add code to initialize the client library and acquire the instance of a Controller class. Sample code to initialize the client library and using controller methods is given in the subsequent sections.

3. Run the Test Project

To run your project you must set the Interpreter for your project. Interpreter is the PHP engine installed on your computer.

Open Settings from File menu.

Run Test Project - Step 1

Select PHP from within Languages & Frameworks

Run Test Project - Step 2

Browse for Interpreters near the Interpreter option and choose your interpreter.

Run Test Project - Step 3

Once the interpreter is selected, click OK

Run Test Project - Step 4

To run your project, right click on your PHP file inside your Test project and click on Run

Run Test Project - Step 5

How to Test

Unit tests in this SDK can be run using PHPUnit.

  1. First install the dependencies using composer including the require-dev dependencies.
  2. Run vendor\bin\phpunit --verbose from commandline to execute tests. If you have installed PHPUnit globally, run tests using phpunit --verbose instead.

You can change the PHPUnit test configuration in the phpunit.xml file.

Initialization

Authentication

In order to setup authentication and initialization of the API client, you need the following information.

Parameter Description
xApiKey Your Api key

API client can be initialized as following.

$xApiKey = 'xApiKey'; // Your Api key

$client = new TransmitMessageLib\TransmitMessageClient($xApiKey);

Class Reference

List of Controllers

Class: ContactsController

Get singleton instance

The singleton instance of the ContactsController class can be accessed from the API Client.

$contacts = $client->getContacts();

Method: getLists

Get metadata of all contact lists defined in your account. Metadata includes list names and corresponding descriptions, contact count within each list, created/updated date and time of each list, filters applied on the list (if any) and type of list.

function getLists(
        $sort = 'updated_at',
        $filters = null,
        $page = 0,
        $limit = 25)

Parameters

Parameter Tags Description
sort Optional DefaultValue Sort by (field name)
filters Optional Filter by (relevant field values)
page Optional DefaultValue The page number of the result to fetch
limit Optional DefaultValue The number of results to fetch per page; maximum 100

Example Usage

$sort = 'updated_at';
$filters = 'filters';
$page = 0;
$limit = 25;

$result = $contacts->getLists($sort, $filters, $page, $limit);

Method: createList

Create a new (Static or Dynamic) contact list. NOTE: Filters are required only in case of a Dynamic List, and are not necessary for a Static List.

function createList($body)

Parameters

Parameter Tags Description
body Required List details

Example Usage

$body = new ContactList();

$result = $contacts->createList($body);

Method: deleteList

Delete a contact list.

function deleteList($id)

Parameters

Parameter Tags Description
id Required List ID

Example Usage

$id = 'id';

$result = $contacts->deleteList($id);

Method: addListContacts

Add contacts into a static list. NOTE: This end point cannot be used to add contacts into a dynamic list.

function addListContacts(
        $id,
        $body)

Parameters

Parameter Tags Description
id Required Static List ID
body Required IDs of all contacts to be added to the list (max 100)

Example Usage

$id = 'id';
$body = new AddToContactList();

$result = $contacts->addListContacts($id, $body);

Method: removeListContacts

Remove contacts from a list. NOTE: This endpoint can be used to remove contacts only from a Static list.

function removeListContacts(
        $id,
        $body)

Parameters

Parameter Tags Description
id Required Static List ID
body Required IDs of all contacts to be removed from the list

Example Usage

$id = 'id';
$body = new AddToContactList();

$result = $contacts->removeListContacts($id, $body);

Method: formatNumber

Format a valid mobile number from any format to an international format.

function formatNumber($body)

Parameters

Parameter Tags Description
body Required Phone Number Object

Example Usage

$body = new PhoneNumber();

$result = $contacts->formatNumber($body);

Method: getAList

Get metadata for a selected contact list.

function getAList($iD)

Parameters

Parameter Tags Description
iD Required List ID

Example Usage

$iD = 'ID';

$result = $contacts->getAList($iD);

Method: removeContactField

Delete a custom contact field

function removeContactField($id)

Parameters

Parameter Tags Description
id Required The custom contact field ID

Example Usage

$id = 'id';

$result = $contacts->removeContactField($id);

Method: updateContactField

Update contact field information

function updateContactField(
        $id,
        $body)

Parameters

Parameter Tags Description
id Required The custom contact field ID
body Required The custom contact field details (name, type etc.)

Example Usage

$id = 'id';
$body = new ContactField();

$result = $contacts->updateContactField($id, $body);

Method: getContactFields

Get a list of custom contact fields and corresponding field details (name, type etc.)

function getContactFields()

Example Usage

$result = $contacts->getContactFields();

Method: createContactField

Create a custom contact field. Input additional relevant parameter values such as decimals for a numeric type field, or values for a list type field etc.

function createContactField($body)

Parameters

Parameter Tags Description
body Required Contact field details

Example Usage

$body = new ContactField();

$result = $contacts->createContactField($body);

Method: getListContacts

Get information of contacts within a contact list.

function getListContacts(
        $id,
        $sort = 'updated_at',
        $filters = null,
        $page = 0,
        $limit = 25)

Parameters

Parameter Tags Description
id Required List ID
sort Optional DefaultValue Sorted by (field name)
filters Optional Collection Filter by (contact data). Applicable for Static Lists only
page Optional DefaultValue The page of results to fetch
limit Optional DefaultValue The number of results to fetch per page; maximum 100

Example Usage

$id = 'id';
$sort = 'updated_at';
$filters = array('filters');
$page = 0;
$limit = 25;

$result = $contacts->getListContacts($id, $sort, $filters, $page, $limit);

Method: getContacts

Get information of all contacts in the TransmitMessage contacts database

function getContacts(
        $sort = 'updated_at',
        $filters = null,
        $page = 0,
        $limit = 25)

Parameters

Parameter Tags Description
sort Optional DefaultValue The output field to sort the results by
filters Optional Filter by (field values)
page Optional DefaultValue The page number of results to fetch
limit Optional DefaultValue The number of results to fetch per page; maximum 100

Example Usage

$sort = 'updated_at';
$filters = 'filters';
$page = 0;
$limit = 25;

$result = $contacts->getContacts($sort, $filters, $page, $limit);

Method: getAContact

Get information about a contact in your TransmitMessage contact database

function getAContact($id)

Parameters

Parameter Tags Description
id Required Contact Reference number

Example Usage

$id = 'id';

$result = $contacts->getAContact($id);

Method: createOrUpdateContact

Create a new contact or Update details of an existing contact

function createOrUpdateContact(
        $contactRef,
        $body)

Parameters

Parameter Tags Description
contactRef Required Contact reference number
body Required Contact details

Example Usage

$contactRef = 'contact_ref';
$body = new Contact();

$result = $contacts->createOrUpdateContact($contactRef, $body);

Method: removeAContact

Remove a contact record

function removeAContact($id)

Parameters

Parameter Tags Description
id Required Contact ID

Example Usage

$id = 'id';

$result = $contacts->removeAContact($id);

Back to List of Controllers

Class: AccountsController

Get singleton instance

The singleton instance of the AccountsController class can be accessed from the API Client.

$accounts = $client->getAccounts();

Method: getAccountBalance

Get Account Balance

function getAccountBalance()

Example Usage

$result = $accounts->getAccountBalance();

Method: getSenderIds

Get Sender Ids

function getSenderIds(
        $sort = 'name',
        $filters = null,
        $page = 0,
        $limit = 25)

Parameters

Parameter Tags Description
sort Optional DefaultValue Sort by (field name)
filters Optional Filter results by (field value)
page Optional DefaultValue The page number of results to fetch
limit Optional DefaultValue The number of results to fetch per page; maximum 100

Example Usage

$sort = 'name';
$filters = 'filters';
$page = 0;
$limit = 25;

$result = $accounts->getSenderIds($sort, $filters, $page, $limit);

Back to List of Controllers

Class: MMSController

Get singleton instance

The singleton instance of the MMSController class can be accessed from the API Client.

$mMS = $client->getMMS();

Method: cancelMMSCampaign

Cancel an MMS Campaign. NOTE: Can only cancel campaigns in SCHEDULED or VALIDATING status

function cancelMMSCampaign($id)

Parameters

Parameter Tags Description
id Required MMS Campaign ID

Example Usage

$id = 'id';

$result = $mMS->cancelMMSCampaign($id);

Method: getMMSCampaignLinkHits

Get information about link hits from an MMS Campaign successfully sent

function getMMSCampaignLinkHits(
        $id,
        $sort = 'last_hit',
        $filters = null,
        $page = 0,
        $limit = 25)

Parameters

Parameter Tags Description
id Required MMS Campaign ID
sort Optional DefaultValue Sort by (field name)
filters Optional Filter by (field value)
page Optional DefaultValue The page number of results to fetch
limit Optional DefaultValue The number of results to fetch per page; maximum 100

Example Usage

$id = 'id';
$sort = 'last_hit';
$filters = 'filters';
$page = 0;
$limit = 25;

$result = $mMS->getMMSCampaignLinkHits($id, $sort, $filters, $page, $limit);

Method: getMMSMessage

Get information about an MMS Message

function getMMSMessage($id)

Parameters

Parameter Tags Description
id Required MMS ID

Example Usage

$id = 'id';

$result = $mMS->getMMSMessage($id);

Method: getMMSCampaigns

Get information of all MMS Campaigns

function getMMSCampaigns(
        $sort = 'updated_at',
        $filters = null,
        $page = 0,
        $limit = 25)

Parameters

Parameter Tags Description
sort Optional DefaultValue Sort by (field name)
filters Optional Filter by (field value)
page Optional DefaultValue The page of results to fetch
limit Optional DefaultValue The number of results to fetch per page; maximum 100

Example Usage

$sort = 'updated_at';
$filters = 'filters';
$page = 0;
$limit = 25;

$result = $mMS->getMMSCampaigns($sort, $filters, $page, $limit);

Method: getMMSCampaign

Get information about a specific MMS Campaign

function getMMSCampaign($id)

Parameters

Parameter Tags Description
id Required Campaign ID

Example Usage

$id = 'id';

$result = $mMS->getMMSCampaign($id);

Method: sendMMS

Send MMS to single contact

function sendMMS($body)

Parameters

Parameter Tags Description
body Required MMS Details

Example Usage

$body = new MMS();

$result = $mMS->sendMMS($body);

Method: sendMMSCampaign

Send an MMS Campaign

function sendMMSCampaign($body)

Parameters

Parameter Tags Description
body Required MMS campaign details

Example Usage

$body = new MMSCampaign();

$result = $mMS->sendMMSCampaign($body);

Back to List of Controllers

Class: SMSController

Get singleton instance

The singleton instance of the SMSController class can be accessed from the API Client.

$sMS = $client->getSMS();

Method: getSMSInbox

Get all the inbound SMS messages (MOs and Replies)

function getSMSInbox(
        $sort = 'received_at',
        $filters = null,
        $page = 0,
        $limit = 25)

Parameters

Parameter Tags Description
sort Optional DefaultValue Sort by (field name)
filters Optional Filter by (field value)
page Optional DefaultValue The page of results to fetch
limit Optional DefaultValue The number of results to fetch per page; maximum 100

Example Usage

$sort = 'received_at';
$filters = 'filters';
$page = 0;
$limit = 25;

$result = $sMS->getSMSInbox($sort, $filters, $page, $limit);

Method: cancelSMSCampaign

Cancel an SMS Campaign. NOTE: Only campaigns in SCHEDULED or VALIDATING status can be cancelled

function cancelSMSCampaign($id)

Parameters

Parameter Tags Description
id Required SMS Campaign ID

Example Usage

$id = 'id';

$result = $sMS->cancelSMSCampaign($id);

Method: getSMSCampaignLinkHits

Get SMS Campaign link hits

function getSMSCampaignLinkHits(
        $id,
        $sort = 'last_hit',
        $filters = null,
        $page = 0,
        $limit = 25)

Parameters

Parameter Tags Description
id Required SMS Campaign ID
sort Optional DefaultValue Sort by (field name)
filters Optional Filter by (field value)
page Optional DefaultValue The page number of results to fetch
limit Optional DefaultValue The number of results to fetch per page; maximum 100

Example Usage

$id = 'id';
$sort = 'last_hit';
$filters = 'filters';
$page = 0;
$limit = 25;

$result = $sMS->getSMSCampaignLinkHits($id, $sort, $filters, $page, $limit);

Method: getSMSCampaignReplies

Fetch replies to a campaign from recipients

function getSMSCampaignReplies(
        $id,
        $sort = 'received_at',
        $filters = null,
        $page = 0,
        $limit = 25)

Parameters

Parameter Tags Description
id Required SMS Campaign ID
sort Optional DefaultValue Sort by (field name)
filters Optional Filter by (field value)
page Optional DefaultValue The page number of results to fetch
limit Optional DefaultValue The number of results to fetch per page; maximum 100

Example Usage

$id = 'id';
$sort = 'received_at';
$filters = 'filters';
$page = 0;
$limit = 25;

$result = $sMS->getSMSCampaignReplies($id, $sort, $filters, $page, $limit);

Method: getSMSCampaignReport

Fetch the activity details report for an SMS campaign already sent. NOTE: The information can be retrieved only for those campaigns that have either been already sent, is in the process of getting sent or for throttled campaigns that is at least partially sent.

function getSMSCampaignReport($id)

Parameters

Parameter Tags Description
id Required SMS Campaign ID

Example Usage

$id = 'id';

$result = $sMS->getSMSCampaignReport($id);

Method: getSMSCampaigns

Fetch a list and details of all SMS campaigns in your TransmitMessage account across all statuses

function getSMSCampaigns(
        $sort = 'updated_at',
        $filters = null,
        $page = 0,
        $limit = 25)

Parameters

Parameter Tags Description
sort Optional DefaultValue Sort by (field name)
filters Optional Filter by (field value)
page Optional DefaultValue The page of results to fetch
limit Optional DefaultValue The number of results to fetch per page; maximum 100

Example Usage

$sort = 'updated_at';
$filters = 'filters';
$page = 0;
$limit = 25;

$result = $sMS->getSMSCampaigns($sort, $filters, $page, $limit);

Method: getSMSCampaign

Fetch details of a specific SMS Campaign

function getSMSCampaign($id)

Parameters

Parameter Tags Description
id Required SMS Campaign ID

Example Usage

$id = 'id';

$result = $sMS->getSMSCampaign($id);

Method: sendSMS

Send SMS

function sendSMS($body)

Parameters

Parameter Tags Description
body Required SMS details (from, to and content)

Example Usage

$body = new SMS();

$result = $sMS->sendSMS($body);

Method: getSMSRecord

Fetch details of an SMS sent

function getSMSRecord($id)

Parameters

Parameter Tags Description
id Required Message ID of the SMS

Example Usage

$id = 'id';

$result = $sMS->getSMSRecord($id);

Method: sendSMSCampaign

Send SMS Campaign

function sendSMSCampaign($body)

Parameters

Parameter Tags Description
body Required SMS campaign details

Example Usage

$body = new SMSCampaign();

$result = $sMS->sendSMSCampaign($body);

Back to List of Controllers