PHP code example of brolese / infobip-api-php-client

1. Go to this page and download the library: Download brolese/infobip-api-php-client 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/ */

    

brolese / infobip-api-php-client example snippets


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

    $client = new GuzzleHttp\Client();

    $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
    }

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

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

    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";
    }

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

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

    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";
    }