Skip to content

speakeasy-api/speakeasy-client-sdk-php

Repository files navigation

speakeasy-api/speakeasy-client-sdk-php

SDK Installation

The SDK relies on Composer to manage its dependencies.

To install the SDK and add it as a dependency to an existing composer.json file:

composer require "speakeasy-api/speakeasy-client-sdk-php"

SDK Example Usage

Example

declare(strict_types=1);

require 'vendor/autoload.php';

use Speakeasy\SpeakeasyClientSDK;
use Speakeasy\SpeakeasyClientSDK\Models\Operations;
use Speakeasy\SpeakeasyClientSDK\Models\Shared;

$security = new Shared\Security(
    apiKey: '<YOUR_API_KEY_HERE>',
);

$sdk = SpeakeasyClientSDK\SDK::builder()->setSecurity($security)->build();

$request = new Operations\GetApisRequest();

$response = $sdk->apis->getApis(
    request: $request
);

if ($response->apis !== null) {
    // handle response
}

Available Resources and Operations

Available methods
  • getAccess - Get access allowances for a particular workspace
  • getAccessToken - Get or refresh an access token for the current workspace.
  • getUser - Get information about the current user.
  • validateApiKey - Validate the current api key.
  • getEventsByTarget - Load recent events for a particular workspace
  • getTargets - Load targets for a particular workspace
  • getTargetsDeprecated - Load targets for a particular workspace
  • post - Post events for a specific workspace
  • search - Search events for a particular workspace by any field
  • create - Create an organization
  • createFreeTrial - Create a free trial for an organization
  • get - Get organization
  • getAll - Get organizations for a user
  • getUsage - Get billing usage summary for a particular organization
  • suggest - Generate suggestions for improving an OpenAPI document.
  • suggestOpenAPI - (DEPRECATED) Generate suggestions for improving an OpenAPI document.
  • suggestOpenAPIRegistry - Generate suggestions for improving an OpenAPI document stored in the registry.

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.

By default an API error will raise a Errorors\SDKException exception, which has the following properties:

Property Type Description
$message string The error message
$statusCode int The HTTP status code
$rawResponse ?\Psr\Http\Message\ResponseInterface The raw HTTP response
$body string The response content

When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the deleteApi method throws the following exceptions:

Error Object Status Code Content Type
Errorors\Error 4XX application/json
Speakeasy\SpeakeasyClientSDK\Models\Errorors.SDKException 4xx-5xx /

Example

declare(strict_types=1);

require 'vendor/autoload.php';

use Speakeasy\SpeakeasyClientSDK;
use Speakeasy\SpeakeasyClientSDK\Models\Operations;
use Speakeasy\SpeakeasyClientSDK\Models\Shared;

$security = new Shared\Security(
    apiKey: '<YOUR_API_KEY_HERE>',
);

$sdk = SpeakeasyClientSDK\SDK::builder()->setSecurity($security)->build();

try {
    $request = new Operations\DeleteApiRequest(
        apiID: '<id>',
        versionID: '<id>',
    );

    $response = $sdk->apis->deleteApi(
        request: $request
    );

    if ($response->statusCode === 200) {
        // handle response
    }
} catch (Errorors\ErrorThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errorors\SDKException $e) {
    // handle default exception
    throw $e;
}

Server Selection

Server Selection

Select Server by Name

You can override the default server globally by passing a server name to the server: str optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:

Name Server Variables
prod https://api.prod.speakeasyapi.dev None

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the server_url: str optional parameter when initializing the SDK client instance. For example:

Summary

Speakeasy API: The Speakeasy API allows teams to manage common operations with their APIs

For more information about the API: The Speakeasy Platform Documentation

Table of Contents

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release !

SDK Created by Speakeasy