dub / dub-php
Requires
- php: ^8.2
- brick/date-time: ^0.7.0
- brick/math: ^0.12.1
- galbar/jsonpath: ^3.0
- guzzlehttp/guzzle: ^7.0
- phpdocumentor/type-resolver: ^1.8
- speakeasy/serializer: ^4.0.3
Requires (Dev)
- laravel/pint: ^1.18.1
- phpstan/phpstan: ^2.1.0
- phpunit/phpunit: ^10
- roave/security-advisories: dev-latest
- dev-main
- v0.12.0
- v0.11.37
- v0.11.36
- v0.11.35
- v0.11.34
- v0.11.33
- v0.11.32
- v0.11.31
- v0.11.30
- v0.11.29
- v0.11.28
- v0.11.27
- v0.11.26
- v0.11.25
- v0.11.24
- v0.11.23
- v0.11.22
- v0.11.21
- v0.11.20
- v0.11.19
- v0.11.18
- v0.11.17
- v0.11.16
- v0.11.15
- v0.11.14
- v0.11.13
- v0.11.12
- v0.11.11
- v0.11.10
- v0.11.9
- v0.11.8
- v0.11.7
- v0.11.6
- v0.11.5
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.6
- v0.10.5
- v0.10.4
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.0
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.0
- v0.6.9
- v0.6.8
- v0.6.7
- v0.6.6
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.4
- v0.4.3
- v0.4.2
- 0.0.1
- dev-speakeasy-sdk-regen-1741392995
- dev-enable-laravel
This package is auto-updated.
Last update: 2025-03-14 00:21:36 UTC
README
Summary
Dub.co API: Dub is link management infrastructure for companies to create marketing campaigns, link sharing features, and referral programs.
Table of Contents
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 "dub/dub-php"
SDK Example Usage
Example 1
declare(strict_types=1); require 'vendor/autoload.php'; use Dub; use Dub\Models\Operations; $sdk = Dub\Dub::builder() ->setSecurity( 'DUB_API_KEY' ) ->build(); $request = new Operations\CreateLinkRequestBody( url: 'https://google.com', tagIds: [ 'clux0rgak00011...', ], externalId: '123456', ); $response = $sdk->links->create( request: $request ); if ($response->linkSchema !== null) { // handle response }
Example 2
declare(strict_types=1); require 'vendor/autoload.php'; use Dub; use Dub\Models\Operations; $sdk = Dub\Dub::builder() ->setSecurity( 'DUB_API_KEY' ) ->build(); $request = new Operations\UpsertLinkRequestBody( url: 'https://google.com', tagIds: [ 'clux0rgak00011...', ], externalId: '123456', ); $response = $sdk->links->upsert( request: $request ); if ($response->linkSchema !== null) { // handle response }
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
token |
http | HTTP Bearer |
To authenticate with the API the token
parameter must be set when initializing the SDK. For example:
declare(strict_types=1); require 'vendor/autoload.php'; use Dub; use Dub\Models\Operations; $sdk = Dub\Dub::builder() ->setSecurity( 'DUB_API_KEY' ) ->build(); $request = [ new Operations\RequestBody( url: 'https://google.com', tagIds: [ 'clux0rgak00011...', ], externalId: '123456', ), ]; $response = $sdk->links->createMany( request: $request ); if ($response->responseBodies !== null) { // handle response }
Available Resources and Operations
Available methods
analytics
- retrieve - Retrieve analytics for a link, a domain, or the authenticated workspace.
customers
create- Create a customer ⚠️ Deprecated- delete - Delete a customer
- get - Retrieve a customer
- list - Retrieve a list of customers
- update - Update a customer
domains
- create - Create a domain
- delete - Delete a domain
- list - Retrieve a list of domains
- update - Update a domain
embedTokens
- referrals - Create a new referrals embed token
events
- list - Retrieve a list of events
folders
- create - Create a new folder
- delete - Delete a folder
- list - Retrieve a list of folders
- update - Update a folder
links
- createMany - Bulk create links
- deleteMany - Bulk delete links
- updateMany - Bulk update links
- create - Create a new link
- delete - Delete a link
- get - Retrieve a link
- list - Retrieve a list of links
- count - Retrieve links count
- update - Update a link
- upsert - Upsert a link
metatags
- get - Retrieve the metatags for a URL
partners
- create - Create a new partner
- createLink - Create a link for a partner
- analytics - Retrieve analytics for a partner
- updateSale - Update a sale for a partner.
- upsertLink - Upsert a link for a partner
qrCodes
- get - Retrieve a QR code
tags
- create - Create a new tag
- delete - Delete a tag
- list - Retrieve a list of tags
- update - Update a tag
track
workspaces
Pagination
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
returned object will be a Generator
instead of an individual response.
Working with generators is as simple as iterating over the responses in a foreach
loop, and you can see an example below:
declare(strict_types=1); require 'vendor/autoload.php'; use Dub; use Dub\Models\Operations; $sdk = Dub\Dub::builder() ->setSecurity( 'DUB_API_KEY' ) ->build(); $request = new Operations\GetLinksRequest(); $responses = $sdk->links->list( request: $request ); foreach ($responses as $response) { if ($response->statusCode === 200) { // handle response } }
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 Errors\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 createMany
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Errors\BadRequest | 400 | application/json |
Errors\Unauthorized | 401 | application/json |
Errors\Forbidden | 403 | application/json |
Errors\NotFound | 404 | application/json |
Errors\Conflict | 409 | application/json |
Errors\InviteExpired | 410 | application/json |
Errors\UnprocessableEntity | 422 | application/json |
Errors\RateLimitExceeded | 429 | application/json |
Errors\InternalServerError | 500 | application/json |
Errors\SDKException | 4XX, 5XX | */* |
Example
declare(strict_types=1); require 'vendor/autoload.php'; use Dub; use Dub\Models\Errors; use Dub\Models\Operations; $sdk = Dub\Dub::builder() ->setSecurity( 'DUB_API_KEY' ) ->build(); try { $request = [ new Operations\RequestBody( url: 'https://google.com', tagIds: [ 'clux0rgak00011...', ], externalId: '123456', ), ]; $response = $sdk->links->createMany( request: $request ); if ($response->responseBodies !== null) { // handle response } } catch (Errors\BadRequestThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\UnauthorizedThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\ForbiddenThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\NotFoundThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\ConflictThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\InviteExpiredThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\UnprocessableEntityThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\RateLimitExceededThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\InternalServerErrorThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\SDKException $e) { // handle default exception throw $e; }
Server Selection
Override Server URL Per-Client
The default server can be overridden globally using the setServerUrl(string $serverUrl)
builder method when initializing the SDK client instance. For example:
declare(strict_types=1); require 'vendor/autoload.php'; use Dub; use Dub\Models\Operations; $sdk = Dub\Dub::builder() ->setServerURL('https://api.dub.co') ->setSecurity( 'DUB_API_KEY' ) ->build(); $request = [ new Operations\RequestBody( url: 'https://google.com', tagIds: [ 'clux0rgak00011...', ], externalId: '123456', ), ]; $response = $sdk->links->createMany( request: $request ); if ($response->responseBodies !== null) { // handle response }
Development
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!