PHP code example of zavudev / sdk

1. Go to this page and download the library: Download zavudev/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/ */

    

zavudev / sdk example snippets




use Zavudev\Client;

$client = new Client(apiKey: getenv('ZAVUDEV_API_KEY') ?: 'My API Key');

$messageResponse = $client->messages->send(
  to: '+14155551234', text: 'Hello from Zavu!'
);

var_dump($messageResponse->message);



use Zavudev\Client;

$client = new Client(apiKey: getenv('ZAVUDEV_API_KEY') ?: 'My API Key');

$page = $client->messages->list();

var_dump($page);

// fetch items from the current page
foreach ($page->getItems() as $item) {
  var_dump($item->id);
}
// make additional network requests to fetch items from all pages, including and after the current page
foreach ($page->pagingEachItem() as $item) {
  var_dump($item->id);
}



use Zavudev\Core\Exceptions\APIConnectionException;
use Zavudev\Core\Exceptions\RateLimitException;
use Zavudev\Core\Exceptions\APIStatusException;

try {
  $messageResponse = $client->messages->send(to: '+14155551234');
} catch (APIConnectionException $e) {
  echo "The server could not be reached", PHP_EOL;
  var_dump($e->getPrevious());
} catch (RateLimitException $e) {
  echo "A 429 status code was received; we should back off a bit.", PHP_EOL;
} catch (APIStatusException $e) {
  echo "Another non-200-range status code was received", PHP_EOL;
  echo $e->getMessage();
}



use Zavudev\Client;

// Configure the default for all requests:
$client = new Client(requestOptions: ['maxRetries' => 0]);

// Or, configure per-request:
$result = $client->messages->send(
  to: '+14155551234',
  text: 'Hello from Zavu!',
  requestOptions: ['maxRetries' => 5],
);



$messageResponse = $client->messages->send(
  to: '+14155551234',
  text: 'Hello from Zavu!',
  requestOptions: [
    'extraQueryParams' => ['my_query_parameter' => 'value'],
    'extraBodyParams' => ['my_body_parameter' => 'value'],
    'extraHeaders' => ['my-header' => 'value'],
  ],
);



$response = $client->request(
  method: "post",
  path: '/undocumented/endpoint',
  query: ['dog' => 'woof'],
  headers: ['useful-header' => 'interesting-value'],
  body: ['hello' => 'world']
);