PHP code example of prelude-so / php-sdk

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

    

prelude-so / php-sdk example snippets




use Prelude\Client;

$client = new Client(apiToken: getenv('API_TOKEN') ?: 'My API Token');

$verification = $client->verification->create(
  target: ['type' => 'phone_number', 'value' => '+30123456789']
);

var_dump($verification->id);



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

try {
  $verification = $client->verification->create(
    target: ['type' => 'phone_number', 'value' => '+30123456789']
  );
} 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 Prelude\Client;

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

// Or, configure per-request:
$result = $client->verification->create(
  target: ['type' => 'phone_number', 'value' => '+30123456789'],
  requestOptions: ['maxRetries' => 5],
);



$verification = $client->verification->create(
  target: ['type' => 'phone_number', 'value' => '+30123456789'],
  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']
);

composer