Giter Club home page Giter Club logo

inmobile-php-api-client's Introduction

Inmobile PHP SDK for v4

Requirements

  • PHP 7.4 or 8.x.

Getting started

The latest version of the client can be found on packagist here

  1. composer require inmobile/inmobile-sdk
  2. 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/

Endpoints

The SDK is split up into different classes for each "endpoint" in the InMobile API.

Messages

This can be accessed by calling ->messages() on InmobileApi. Below you will find an example of all the actions.

Send message

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)
]);

Send message using query

Send one message using query parameters.

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

Get status reports

Get all SMS reports

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

Cancel messages

Cancel one or multiple messages by their ID

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

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

Lists

This can be accessed by calling ->lists() on InmobileApi. Below you will find an example of all the actions.

Get

Fetch a paginated list of all lists.

$api->lists()->get($pageLimit = 20)

Get all

Fetch all lists. This automatically runs through every page and returns an array of all lists.

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

Find

Find a list by its ID

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

Create

Create a new list

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

Update

Update a list with a new name

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

Delete

Delete a list by its ID

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

Blacklist

This can be accessed by calling ->blacklist() on InmobileApi. Below you will find an example of all the actions.

Get

Fetch a paginated list of all entries in your blacklist

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

Get all

Fetch all entries in a blacklist. This automatically runs through every page and returns an array of all entries.

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

Find by ID

Find an entry by ID

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

Find by phone number

Find an entry by phone number

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

Create

Create a new entry in the blacklist

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

Delete by ID

Delete an entry by ID

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

Delete by phone number

Delete an entry by phone number

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

Recipients

This can be accessed by calling ->recipients() on InmobileApi. Below you will find an example of all the actions.

Get

Get a paginated response of all recipients in a list

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

Get all

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 by ID

Find a recipient by ID

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

Find by phone number

Find a recipient by phone number

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

Create

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

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

Delete by ID

Delete a recipient by ID

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

Delete by phone number

Delete a recipient by phone number

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

Delete all recipients on a list

This deletes all recipients on the given list

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

inmobile-php-api-client's People

Contributors

talkar avatar kristho91 avatar inmobiletalkar avatar inmobilebuildbot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.