| OS | PHP |
|---|---|
| Windows 2022 | 8.0, 8.1, 8.2, 8.3 |
| Windows 2025 | 8.0, 8.1, 8.2, 8.3 |
| Ubuntu 22.04 | 8.0, 8.1, 8.2, 8.3 |
| Ubuntu 24.04 | 8.0, 8.1, 8.2, 8.3 |
composer require bandwidth/sdk require"vendor/autoload.php"; $config = newBandwidthLib\Configuration( array( 'messagingBasicAuthUserName' => 'username', 'messagingBasicAuthPassword' => 'password', 'voiceBasicAuthUserName' => 'username', 'voiceBasicAuthPassword' => 'password', 'twoFactorAuthBasicAuthUserName' => 'username', 'twoFactorAuthBasicAuthPassword' => 'password', 'webRtcBasicAuthUserName' => 'username', 'webRtcBasicAuthPassword' => 'password' ) ); $client = newBandwidthLib\BandwidthClient($config); $accountId = "12345";$voiceClient = $client->getVoice()->getClient(); $body = newBandwidthLib\Voice\Models\CreateCallRequest(); $body->from = "+15554443333"; $body->to = "+15554442222"; $body->answerUrl = "https://test.com"; $body->applicationId = "3-d-4-b-5"; try{$response = $voiceClient->createCall($voiceAccountId, $body); print_r($response)} catch (Exception$e){print_r($e)}$messagingClient = $client->getMessaging()->getClient(); $body = newBandwidthLib\Messaging\Models\MessageRequest(); $body->from = "+12345678901"; $body->to = array("+12345678902"); $body->applicationId = "1234-ce-4567-de"; $body->text = "Greetings!"; try{$response = $messagingClient->createMessage($messagingAccountId, $body); print_r($response)} catch (Exception$e){print_r($e)}$speakSentence = BandwidthLib\Voice\Bxml\SpeakSentence::make("Hello!") ->voice("susan") ->locale("en_US") ->gender("female"); $response = BandwidthLib\Voice\Bxml\Response::make() ->addVerb($speakSentence); echo$response->toBxml();$mfaClient = $client->getTwoFactorAuth()->getMFA(); $body = newBandwidthLib\TwoFactorAuth\Models\TwoFactorCodeRequestSchema(); $body->from = "+15554443333"; $body->to = "+15553334444"; $body->applicationId = "3-a-b-d"; $body->scope = "scope"; $body->digits = 6; $body->message = "Your temporary{NAME}{SCOPE} code is{CODE}"; $mfaClient->createVoiceTwoFactor($accountId, $body); $body = newBandwidthLib\TwoFactorAuth\Models\TwoFactorVerifyRequestSchema(); $body->from = "+15554443333"; $body->to = "+15553334444"; $body->applicationId = "3-a-b-d"; $body->scope = "scope"; $body->code = "123456"; $body->digits = 6; $body->expirationTimeInMinutes = 3; $response = $mfaClient->createVerifyTwoFactor($accountId, $body); echo$response->getResult()->valid;$webRtcClient = $client->getWebRtc()->getClient(); $createSessionBody = newBandwidthLib\WebRtc\Models\Session(); $createSessionBody->tag = 'new-session'; $createSessionResponse = $webRtcClient->createSession($accountId, $createSessionBody); $sessionId = $createSessionResponse->getResult()->id; $createParticipantBody = newBandwidthLib\WebRtc\Models\Participant(); $createParticipantBody->callbackUrl = 'https://sample.com'; $createParticipantBody->publishPermissions = array( BandwidthLib\WebRtc\Models\PublishPermissionEnum::AUDIO, BandwidthLib\WebRtc\Models\PublishPermissionEnum::VIDEO ); $body = newBandwidthLib\WebRtc\Models\Subscriptions(); $body->sessionId = "1234-abcd"; $createParticipantResponse = $webRtcClient->createParticipant($accountId, $createParticipantBody); $participantId = $createParticipantResponse->getResult()->participant->id; $webRtcClient->addParticipantToSession($accountId, $sessionId, $participantId, $body);This package can be used with PHP >= 7.2
Documentation for this package can be found at https://dev.bandwidth.com/sdks/php/
Information for credentials for this package can be found at https://dev.bandwidth.com/guides/accountCredentials.html