telnyx / telnyx-php
Telnyx PHP SDK
Installs: 506 076
Dependents: 2
Suggesters: 0
Security: 0
Stars: 33
Watchers: 8
Forks: 33
Open Issues: 21
pkg:composer/telnyx/telnyx-php
Requires
- php: ^8.1
- php-http/discovery: ^1
- psr/http-client: ^1
- psr/http-client-implementation: ^1
- psr/http-factory-implementation: ^1
- psr/http-message: ^1|^2
Requires (Dev)
- dev-master
- v4.0.0
- v3.0.1
- v3.0.0
- 2.8.1
- v2.8.0
- v2.7.1
- v2.7.0
- v2.6.0
- v2.5.2
- v2.5.1
- v2.5.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.1
- 2.0.0
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- v0.0.1
- dev-release-please--branches--master--changes--next
- dev-next
- dev-generated
- dev-fix-api-base
- dev-dependabot/composer/symfony/process-5.4.46
- dev-issue_73_update_v1
- dev-issue_73_solved_1
- dev-issue_73_1
- dev-vidhan/issue_73
- dev-semgrep-INFRA-8882
- dev-September2021
- dev-update_mock_version
- dev-CallControl
- dev-Connections
- dev-milestone4
This package is auto-updated.
Last update: 2025-10-09 16:18:54 UTC
README
Note
The Telnyx PHP API Library is currently in beta and we're excited for you to experiment with it!
This library has not yet been exhaustively tested in production environments and may be missing some features you'd expect in a stable release. As we continue development, there may be breaking changes that require updates to your code.
We'd love your feedback! Please share any suggestions, bug reports, feature requests, or general thoughts by filing an issue.
The Telnyx PHP library provides convenient access to the Telnyx REST API from any PHP 8.1.0+ application.
It is generated with Stainless.
Documentation
Installation
To use this package, install via Composer by adding the following to your application's composer.json
:
{ "repositories": [ { "type": "vcs", "url": "git@github.com:team-telnyx/telnyx-php.git" } ], "require": { "telnyx/telnyx-php": "dev-main" } }
Usage
This library uses named parameters to specify optional arguments. Parameters with a default value must be set by name.
<?php use Telnyx\Client; $client = new Client(apiKey: getenv("TELNYX_API_KEY") ?: "My API Key"); $response = $client->calls->dial( connectionID: "conn12345", from: "+15557654321", to: "+15551234567" ); var_dump($response->data);
Value Objects
It is recommended to use the static with
constructor HangupTool::with(hangup: [], ...)
and named parameters to initialize value objects.
However, builders are also provided (new HangupTool)->withHangup([])
.
Handling errors
When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of Telnyx\Core\Exceptions\APIException
will be thrown:
<?php use Telnyx\Core\Exceptions\APIConnectionException; try { $numberOrder = $client->numberOrders->create(); } catch (APIConnectionException $e) { echo "The server could not be reached", PHP_EOL; var_dump($e->getPrevious()); } catch (RateLimitError $_) { echo "A 429 status code was received; we should back off a bit.", PHP_EOL; } catch (APIStatusError $e) { echo "Another non-200-range status code was received", PHP_EOL; echo $e->getMessage(); }
Error codes are as follows:
Cause | Error Type |
---|---|
HTTP 400 | BadRequestException |
HTTP 401 | AuthenticationException |
HTTP 403 | PermissionDeniedException |
HTTP 404 | NotFoundException |
HTTP 409 | ConflictException |
HTTP 422 | UnprocessableEntityException |
HTTP 429 | RateLimitException |
HTTP >= 500 | InternalServerException |
Other HTTP error | APIStatusException |
Timeout | APITimeoutException |
Network error | APIConnectionException |
Retries
Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
You can use the maxRetries
option to configure or disable this:
<?php use Telnyx\Client; use Telnyx\RequestOptions; // Configure the default for all requests: $client = new Client(maxRetries: 0); // Or, configure per-request: $result = $client->numberOrders->create( requestOptions: RequestOptions::with(maxRetries: 5) );
Advanced concepts
Making custom or undocumented requests
Undocumented properties
You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
Note: the extra*
parameters of the same name overrides the documented parameters.
<?php use Telnyx\RequestOptions; $numberOrder = $client->numberOrders->create( requestOptions: RequestOptions::with( extraQueryParams: ["my_query_parameter" => "value"], extraBodyParams: ["my_body_parameter" => "value"], extraHeaders: ["my-header" => "value"], ), ); var_dump($numberOrder["my_undocumented_property"]);
Undocumented request params
If you want to explicitly send an extra param, you can do so with the extra_query
, extra_body
, and extra_headers
under the request_options:
parameter when making a request, as seen in the examples above.
Undocumented endpoints
To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using client.request
, like so:
<?php $response = $client->request( method: "post", path: '/undocumented/endpoint', query: ['dog' => 'woof'], headers: ['useful-header' => 'interesting-value'], body: ['hello' => 'world'] );
Versioning
This package follows SemVer conventions. As the library is in initial development and has a major version of 0
, APIs may change at any time.
This package considers improvements to the (non-runtime) PHPDoc type definitions to be non-breaking changes.
Requirements
PHP 8.1.0 or higher.