PHPackages                             infobip-ecommerce/api-php-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. infobip-ecommerce/api-php-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

infobip-ecommerce/api-php-client
================================

PHP library for consuming Infobip's API

3.1.11(2y ago)010.0k—6.7%1MITPHPPHP &gt;=7.2

Since Feb 10Pushed 2y ago2 watchersCompare

[ Source](https://github.com/SiiPoland/infobip-api-php-client)[ Packagist](https://packagist.org/packages/infobip-ecommerce/api-php-client)[ Docs](https://www.infobip.com)[ RSS](/packages/infobip-ecommerce-api-php-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (12)Used By (0)

Infobip API PHP Client
======================

[](#infobip-api-php-client)

[![Packegist](https://camo.githubusercontent.com/e6a836dacc6fcdca126fcc09339d541f0e4573fec834ff2eaae4bb8ec8d15042/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f696e666f6269702f696e666f6269702d6170692d7068702d636c69656e74)](https://packagist.org/packages/twilio/sdk?query=infobip-api-php-client)[![MIT License](https://camo.githubusercontent.com/be83dfb422b5ff2739afb59cf20b3db049ebfacf938f74160bf58b1b13d60bf1/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6963656e73652f696e666f6269702f696e666f6269702d6170692d7068702d636c69656e74)](https://opensource.org/licenses/MIT)

This is a PHP Client for Infobip API and you can use it as a dependency to add [Infobip APIs](https://www.infobip.com/docs/api) to your application. To use this, you'll need an Infobip account. If not already having one, you can create a [free trial](https://www.infobip.com/docs/freetrial) account [here](https://www.infobip.com/signup).

Built on top of [OpenAPI Specification](https://swagger.io/specification/), powered by [OpenAPI Generator](https://openapi-generator.tech/).

[![Infobip](https://camo.githubusercontent.com/dad543469504a09843380e4a5c5c9e38fc17ff3a6f22180b879e626913b76a95/68747470733a2f2f7564657369676e6373732e636f6d2f77702d636f6e74656e742f75706c6f6164732f323032302f30312f496e666f6269702d6c6f676f2d7472616e73706172656e742e706e67)](https://camo.githubusercontent.com/dad543469504a09843380e4a5c5c9e38fc17ff3a6f22180b879e626913b76a95/68747470733a2f2f7564657369676e6373732e636f6d2f77702d636f6e74656e742f75706c6f6164732f323032302f30312f496e666f6269702d6c6f676f2d7472616e73706172656e742e706e67)

#### Table of contents:

[](#table-of-contents)

- [Documentation](#documentation)
- [General Info](#general-info)
- [Installation](#installation)
- [Quickstart](#quickstart)
- [Ask for help](#ask-for-help)

Documentation
-------------

[](#documentation)

Infobip API Documentation can be found [here](https://www.infobip.com/docs/api).

General Info
------------

[](#general-info)

For `infobip-api-php-client` versioning we use [Semantic Versioning](https://semver.org) scheme.

Published under [MIT License](LICENSE).

PHP versions
------------

[](#php-versions)

All versions above 7.2

Installation
------------

[](#installation)

#### Using Composer

[](#using-composer)

To start using the library add it as dependecy in your `composer.json` file like shown below.

```
"require": {
	"infobip/infobip-api-php-client": "3.0.0"
}
```

And simply run `composer install` to download dependencies.

#### Without Composer

[](#without-composer)

If your setup prevents you from using `composer` you can manually download this package and all of its dependencies and reference them from your code. However, there are solutions that can automate this process. One of them is `php-download` online tool. You can use it to find pre-composed [infobip client package](https://php-download.com/package/infobip/infobip-api-php-client), download it from there and use in your project without manually collecting the dependencies.

Quickstart
----------

[](#quickstart)

#### Initialize the Configuration &amp; HTTP client

[](#initialize-the-configuration--http-client)

We support multiple authentication methods, e.g. you can use [API Key Header](https://www.infobip.com/docs/essentials/api-authentication#api-key-header), in this case, `API_KEY_PREFIX` will be "App".

The `API_KEY` can be created via the [web interface](https://portal.infobip.com/settings/accounts/api-keys).

To see your `URL_BASE_PATH`, log in to the [Infobip API documentation](https://www.infobip.com/docs/api) hub with your Infobip credentials.

```
    $configuration = (new Configuration())
        ->setHost(URL_BASE_PATH)
        ->setApiKeyPrefix('Authorization', API_KEY_PREFIX)
        ->setApiKey('Authorization', API_KEY);

    $client = new GuzzleHttp\Client();
```

#### Send an SMS

[](#send-an-sms)

Simple example for sending an SMS message.

```
    $sendSmsApi = new SendSMSApi($client, $configuration);
    $destination = (new SmsDestination())->setTo('41793026727');
    $message = (new SmsTextualMessage())
        ->setFrom('InfoSMS')
        ->setText('This is a dummy SMS message sent using infobip-api-php-client')
        ->setDestinations([$destination]);
    $request = (new SmsAdvancedTextualRequest())
        ->setMessages([$message]);
```

```
    try {
        $smsResponse = $sendSmsApi->sendSmsMessage($request);
    } catch (Throwable $apiException) {
        // HANDLE THE EXCEPTION
    }
```

Fields provided within `ApiException` object are `code` referring to the HTTP Code response, as well as the `responseHeaders` and `responseBody`. Also, you can get the deserialized response body using `getResponseObject` method.

```
    $apiException->getCode();
    $apiException->getResponseHeaders();
    $apiException->getResponseBody();
    $apiException->getResponseObject();
```

Additionally, you can pull out the `bulkId` and `messageId`(s) from `SmsResponse` object and use them to fetch a delivery report for given message or bulk. Bulk ID will be received only when you send a message to more than one destination address or multiple messages in a single request.

```
    $bulkId = $smsResponse->getBulkId();
    $messageId = $smsResponse->getMessages()[0]->getMessageId();
```

#### Receive SMS message delivery report

[](#receive-sms-message-delivery-report)

For each SMS that you send out, we can send you a message delivery report in real time. All you need to do is specify your endpoint, e.g. `https://{yourDomain}/delivery-reports`, when sending SMS in `notifyUrl` field of `SmsTextualMessage`, or subscribe for reports by contacting our support team.

You can use data models from the library and the pre-configured `\Infobip\ObjectSerializer` serializer.

Example of webhook implementation:

```
    use \Infobip\ObjectSerializer;

    $data = file_get_contents("php://input");
    $type = '\Infobip\Model\SmsDeliveryResult';
    $deliveryReports = ObjectSerializer::deserialize($data, $type);

    foreach ($deliveryReports->getResults() as $report) {
        echo $report->getMessageId() . " - " . $report->getStatus()->getName() . "\n";
    }
```

If you prefer to use your own serializer, please pay attention to the supported [date format](https://www.infobip.com/docs/essentials/integration-best-practices#date-formats).

#### Fetching delivery reports

[](#fetching-delivery-reports)

If you are for any reason unable to receive real time delivery reports on your endpoint, you can use `messageId` or `bulkId` to fetch them. Each request will return a batch of delivery reports - only once.

```
    $numberOfReportsLimit = 10;
    $deliveryReports = $sendSmsApi->getOutboundSmsMessageDeliveryReports($bulkId, $messageId, $numberOfReportsLimit);
    foreach ($deliveryReports->getResults() as $report) {
        echo $report->getMessageId() . " - " . $report->getStatus()->getName() . "\n";
    }
```

#### Unicode &amp; SMS preview

[](#unicode--sms-preview)

Infobip API supports Unicode characters and automatically detects encoding. Unicode and non-standard GSM characters use additional space, avoid unpleasant surprises and check how different message configurations will affect your message text, number of characters and message parts.

```
    $previewResponse = $sendSmsApi->previewSmsMessage((new SmsPreviewRequest())
        ->setText("Let's see how many characters will remain unused in this message."));
    echo $previewResponse;
```

#### Receive incoming SMS

[](#receive-incoming-sms)

If you want to receive SMS messages from your subscribers we can have them delivered to you in real time. When you buy and configure a number capable of receiving SMS, specify your endpoint as explained [here](https://www.infobip.com/docs/api#channels/sms/receive-inbound-sms-messages), e.g. `https://{yourDomain}/incoming-sms`. Example of webhook implementation:

```
    use \Infobip\ObjectSerializer;

    $data = file_get_contents("php://input");
    $type = '\Infobip\Model\SmsInboundMessageResult';
    $messages = ObjectSerializer::deserialize($data, $type);

    foreach ($messages->getResults() as $message) {
        echo $message-> getFrom() . " - " . $message-> getCleanText() . "\n";
    }
```

#### Two-Factor Authentication (2FA)

[](#two-factor-authentication-2fa)

For 2FA quick start guide please check [these examples](two-factor-authentication.md).

Infobip\\SendWhatsappApi
========================

[](#infobipsendwhatsappapi)

All URIs are relative to .

MethodHTTP requestDescription[**sendWhatsappMessage()**](SendWhatsappApi.md#sendWhatsappMessage)**POST** /whatsapp/1/message/templateSend whatsapp message.`sendWhatsappMessage()`
-----------------------

[](#sendwhatsappmessage)

```
sendWhatsappMessage($pi_integrator, $pi_platform, $whatsapp_message): \Infobip\Model\WhatsappResponse
```

Send whatsapp message.

Sends whatsapp message using predefined whatsapp templates

### Example

[](#example)

```
