- PHP 7.4, 8.0, 8.1, 8.2 or 8.3.
The latest version of the client can be found on packagist here
composer require inmobile/inmobile-sdk
- Initialize the
InmobileApi
class and start sending messages!
Each endpoint is split into a different class.
So the messages API would be accessed by calling ->messages()
, lists API by calling ->lists()
and so on.
Example:
/*
* Require autoload, to automatically load the SDK, after installing via composer.
* Execute the following command now, if you haven't already: composer require inmobile/inmobile-sdk
*/
require_once __DIR__ . '/vendor/autoload.php';
use Inmobile\InmobileSDK\InmobileApi;
use Inmobile\InmobileSDK\RequestModels\Message;
/*
* Initialize the Inmobile API Client
*/
$api = new InmobileApi('my-api-token');
/*
* Send the message
*/
$response = $api->messages()->send(
Message::create('This is a message text to be sent')
->from('1245')
->to('4512345678')
);
$response->toArray();
/**
* "results": [
* {
* "numberDetails": {
* "countryCode": "45",
* "phoneNumber": "12345678",
* "rawMsisdn": "45 12 34 56 78",
* "isValidMsisdn": true,
* "isAnonymized": false
* },
* "text": "This is a message text to be sent",
* "from": "1245",
* "smsCount": 1,
* "messageId": "INMBL",
* "encoding": "gsm7"
* }
* ]
*/
You can find the full API documentation here: https://api.inmobile.com/docs/
The SDK is split up into different classes for each "endpoint" in the InMobile API.
This can be accessed by calling ->messages()
on InmobileApi
. Below you will find an example of all the actions.
Send one or more messages.
$api->messages()->send(
Message::create('Hello World')
->from('INMBL')
->to(4512345678)
);
$api->messages()->send([
Message::create('Foobar')
->from('INMBL')
->to(4512345678),
Message::create('Barbiz')
->from('INMBL')
->to(4512345678)
->countryHint('DK')
]);
$api->messages()->sendUsingTemplate(
TemplateMessage::create()
->to(4512345678)
->setPlaceholders([
'{name}' => 'John',
'{lastname}' => 'Doe',
]),
'ecdcb257-c1e9-4b44-8a4e-f05822372d82',
);
// Multiple
$placeholders = [
'{name}' => 'John',
'{lastname}' => 'Doe',
];
$api->messages()->sendUsingTemplate([
TemplateMessage::create()->to(4512345678)->setPlaceholders($placeholders),
TemplateMessage::create()->to(4512345678)->setPlaceholders($placeholders),
], 'ecdcb257-c1e9-4b44-8a4e-f05822372d82');
Send one message using query parameters.
$api->messages()->sendUsingQuery(
Message::create('Hello World')
->from('INMBL')
->to(4512345678)
);
Get all SMS reports
$api->messages()->getStatusReport($limit = 20);
Cancel one or multiple messages by their ID
$api->messages()->cancel('MESSAGEID-1');
// Or multiple messages
$api->messages()->cancel(['MESSAGEID-1', 'MESSAGEID-2']);
This can be accessed by calling ->lists()
on InmobileApi
. Below you will find an example of all the actions.
Fetch all lists. This automatically runs through every page and returns an array of all lists.
$api->lists()->getAll();
Find a list by its ID
$api->lists()->find($listId);
Create a new list
$api->lists()->create($listName);
Update a list with a new name
$api->lists()->update($listId, $newName);
Delete a list by its ID
$api->lists()->delete($listId);
This can be accessed by calling ->blacklist()
on InmobileApi
. Below you will find an example of all the actions.
Fetch a paginated list of all entries in your blacklist
$api->blacklist()->get($pageLimit = 20);
Fetch all entries in a blacklist. This automatically runs through every page and returns an array of all entries.
$api->blacklist()->getAll();
Find an entry by ID
$api->blacklist()->findEntryById('ENTRYID-1');
Find an entry by phone number
$api->blacklist()->findEntryByNumber($countryCode = 45, $phoneNumber = 12345678);
Create a new entry in the blacklist
$api->blacklist()->createEntry($countryCode = 45, $phoneNumber = 12345678, $comment = null);
Delete an entry by ID
$api->blacklist()->deleteEntryById('ENTRYID-1');
Delete an entry by phone number
$api->blacklist()->deleteEntryByNumber($countryCode = 45, $phoneNumber = 12345678);
This can be accessed by calling ->recipients()
on InmobileApi
. Below you will find an example of all the actions.
Get a paginated response of all recipients in a list
$api->recipients()->get($listId = 'LIST-1', $limit = 20);
Fetch all recipients on a list. This automatically runs through every page and returns an array of all recipients.
$api->recipients()->getAll($listId = 'LIST-1');
Find a recipient by ID
$api->recipients()->findById($listId = 'LIST-1', $id = 'RECIPIENT-1');
Find a recipient by phone number
$api->recipients()->findByPhoneNumber($listId = 'LIST-1', $countryCode = 45, $phoneNumber = 12345678);
Create a recipient on a list
$api->recipients()->create(
$listId = 'LIST-1',
Recipient::create(45, 12345678)
->addField('firstname', 'John')
->addField('lastname', 'Doe')
->createdAt(new DateTime('2021-01-02 03:04:05'))
);
Update a recipient on a list
$api->recipients()->update(
$listId = 'LIST-1',
$id = 'RECIPIENT-1',
Recipient::create(45, 12345678)
->addField('firstname', 'John')
->addField('lastname', 'Doe')
->createdAt(new DateTime('2021-01-02 03:04:05'))
);
Create or update a recipient on a list if it doesn't exist.
$api->recipients()->createOrUpdateByPhoneNumber(
$listId = 'LIST-1',
$countryCode = 45,
$phoneNumber = 12345678,
Recipient::create(45, 12345678)
->addField('firstname', 'John')
->addField('lastname', 'Doe')
);
Delete a recipient by ID
$api->recipients()->deleteById($listId = 'LIST-1', $id = 'RECIPIENT-1');
Delete a recipient by phone number
$api->recipients()->deleteByPhoneNumber($listId = 'LIST-1', $countryCode = 45, $phoneNumber = 12345678);
This deletes all recipients on the given list
$api->recipients()->deleteAllFromList($listId = 'LIST-1');
$api->gdpr()->createDeletionRequest(NumberInfo::create($countryCode = '45', $phoneNumber = '12345678'));
$api->tools()->numbersToParse([
NumberToParse::create($countryHint = 'DK', $rawMsisdn = '12 34 56 78')
NumberToParse::create($countryHint = '45', $rawMsisdn = '12 34 56 78')
]);
// If you wish to parse a single number, you can do so by passing a single NumberToParse object
$api->tools()->numbersToParse(NumberToParse::create($countryHint = 'DK', $rawMsisdn = '12 34 56 78'));
Fetch all templates. This automatically runs through every page and returns an array of all templates.
$api->templates()->getAll();
Find a template by its ID
$api->templates()->find($templateId);
Send an email to one or more recipients with the specified subject and text / html body.
$api->emails()->send(
Email::create()
->from(EmailRecipient::create('[email protected]', 'John Doe'))
->to(EmailRecipient::create('[email protected]', 'Jane Doe'))
->subject('Hello World')
->text('Hello World')
->html('<h1>Hello World</h1>')
);
Send an email to one or more recipients using a template.
$api->emails()->sendUsingTemplate(
Email::create()
->from(EmailRecipient::create('[email protected]', 'John Doe'))
->to(EmailRecipient::create('[email protected]', 'Jane Doe'))
->templateId('ABCDEF12-3456-7890-ABCD-EF1234567890')
);
Get a paginated list of email events.
$api->emails()->getEvents($limit = 20);
Fetch all email templates. This automatically runs through every page and returns an array of all templates.
$api->emailTemplates()->getAll();
Find an email template by its ID
$api->emailTemplates()->find($templateId);