PHP code example of inmobile / inmobile-sdk

1. Go to this page and download the library: Download inmobile/inmobile-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

inmobile / inmobile-sdk example snippets


/*
 * Require autoload, to automatically load the SDK, after installing via composer.
 * Execute the following command now, if you haven't already: composer 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"
 *     }
 * ]
 */

$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');

$api->messages()->sendUsingQuery(
    Message::create('Hello World')
        ->from('INMBL')
        ->to(4512345678)
);

$api->messages()->getStatusReport($limit = 20);

$api->messages()->cancel('MESSAGEID-1');

// Or multiple messages
$api->messages()->cancel(['MESSAGEID-1', 'MESSAGEID-2']);

$api->lists()->getAll();

$api->lists()->find($listId);

$api->lists()->create($listName);

$api->lists()->update($listId, $newName);

$api->lists()->delete($listId);

$api->blacklist()->get($pageLimit = 20);

$api->blacklist()->getAll();

$api->blacklist()->findEntryById('ENTRYID-1');

$api->blacklist()->findEntryByNumber($countryCode = 45, $phoneNumber = 12345678);

$api->blacklist()->createEntry($countryCode = 45, $phoneNumber = 12345678, $comment = null);

$api->blacklist()->deleteEntryById('ENTRYID-1');

$api->blacklist()->deleteEntryByNumber($countryCode = 45, $phoneNumber = 12345678);

$api->recipients()->get($listId = 'LIST-1', $limit = 20);

$api->recipients()->getAll($listId = 'LIST-1');

$api->recipients()->findById($listId = 'LIST-1', $id = 'RECIPIENT-1');

$api->recipients()->findByPhoneNumber($listId = 'LIST-1', $countryCode = 45, $phoneNumber = 12345678);

$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'))
);

$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'))
);

$api->recipients()->createOrUpdateByPhoneNumber(
    $listId = 'LIST-1',
    $countryCode = 45,
    $phoneNumber = 12345678,
    Recipient::create(45, 12345678)
        ->addField('firstname', 'John')
        ->addField('lastname', 'Doe')     
);

$api->recipients()->deleteById($listId = 'LIST-1', $id = 'RECIPIENT-1');

$api->recipients()->deleteByPhoneNumber($listId = 'LIST-1', $countryCode = 45, $phoneNumber = 12345678);

$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'));

$api->templates()->getAll();

$api->templates()->find($templateId);

$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>')
);

$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')
);

$api->emails()->getEvents($limit = 20);

$api->emailTemplates()->getAll();

$api->emailTemplates()->find($templateId);