PHPackages                             dub/dub-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dub/dub-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dub/dub-php
===========

v0.15.7(3mo ago)510.7k↓25.4%4[1 issues](https://github.com/dubinc/dub-php/issues)[1 PRs](https://github.com/dubinc/dub-php/pulls)MITPHPPHP &gt;=8.2CI passing

Since Jun 4Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/dubinc/dub-php)[ Packagist](https://packagist.org/packages/dub/dub-php)[ RSS](/packages/dub-dub-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (123)Used By (0)

dub/dub-php
===========

[](#dubdub-php)

 [![](https://camo.githubusercontent.com/096b86187dea2c62026c9750456a53a3e7c20fdd95fa1b55f5cc9a67ebc2078d/68747470733a2f2f637573746f6d2d69636f6e2d6261646765732e64656d6f6c61622e636f6d2f62616467652f2d4275696c742532304279253230537065616b656173792d3231323031353f7374796c653d666f722d7468652d6261646765266c6f676f436f6c6f723d464245333331266c6f676f3d737065616b65617379266c6162656c436f6c6f723d353435343534)](https://speakeasyapi.dev/) [ ![](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667) ](https://opensource.org/licenses/MIT)

Summary
-------

[](#summary)

Dub API: Dub is the modern link attribution platform for short links, conversion tracking, and affiliate programs.

Table of Contents
-----------------

[](#table-of-contents)

- [dub/dub-php](#dubdub-php)
    - [SDK Installation](#sdk-installation)
    - [SDK Example Usage](#sdk-example-usage)
    - [Authentication](#authentication)
    - [Available Resources and Operations](#available-resources-and-operations)
    - [Pagination](#pagination)
    - [Error Handling](#error-handling)
    - [Server Selection](#server-selection)
- [Development](#development)
    - [Maturity](#maturity)
    - [Contributions](#contributions)

SDK Installation
----------------

[](#sdk-installation)

The SDK relies on [Composer](https://getcomposer.org/) 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
-----------------

[](#sdk-example-usage)

### Example 1

[](#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',
    externalId: '123456',
    tagIds: [
        'clux0rgak00011...',
    ],
    testVariants: [
        new Operations\TestVariants(
            url: 'https://example.com/variant-1',
            percentage: 50,
        ),
        new Operations\TestVariants(
            url: 'https://example.com/variant-2',
            percentage: 50,
        ),
    ],
);

$response = $sdk->links->create(
    request: $request
);

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

### Example 2

[](#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',
    externalId: '123456',
    tagIds: [
        'clux0rgak00011...',
    ],
    testVariants: [
        new Operations\UpsertLinkTestVariants(
            url: 'https://example.com/variant-1',
            percentage: 50,
        ),
        new Operations\UpsertLinkTestVariants(
            url: 'https://example.com/variant-2',
            percentage: 50,
        ),
    ],
);

$response = $sdk->links->upsert(
    request: $request
);

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

Authentication
--------------

[](#authentication)

### Per-Client Security Schemes

[](#per-client-security-schemes)

This SDK supports the following security scheme globally:

NameTypeScheme`token`httpHTTP BearerTo 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\GetLinksRequest(
    pageSize: 50,
);

$responses = $sdk->links->list(
    request: $request
);

foreach ($responses as $response) {
    if ($response->statusCode === 200) {
        // handle response
    }
}
```

Available Resources and Operations
----------------------------------

[](#available-resources-and-operations)

Available methods### [Analytics](docs/sdks/analytics/README.md)

[](#analytics)

- [retrieve](docs/sdks/analytics/README.md#retrieve) - Retrieve analytics for a link, a domain, or the authenticated workspace.

### [Bounties](docs/sdks/bounties/README.md)

[](#bounties)

- [listSubmissions](docs/sdks/bounties/README.md#listsubmissions) - List bounty submissions
- [approveSubmission](docs/sdks/bounties/README.md#approvesubmission) - Approve a bounty submission
- [rejectSubmission](docs/sdks/bounties/README.md#rejectsubmission) - Reject a bounty submission

### [Commissions](docs/sdks/commissions/README.md)

[](#commissions)

- [list](docs/sdks/commissions/README.md#list) - List all commissions
- [update](docs/sdks/commissions/README.md#update) - Update a commission.

### [Customers](docs/sdks/customers/README.md)

[](#customers)

- [list](docs/sdks/customers/README.md#list) - Retrieve a list of customers
- [get](docs/sdks/customers/README.md#get) - Retrieve a customer
- [delete](docs/sdks/customers/README.md#delete) - Delete a customer
- [update](docs/sdks/customers/README.md#update) - Update a customer

### [Domains](docs/sdks/domains/README.md)

[](#domains)

- [list](docs/sdks/domains/README.md#list) - Retrieve a list of domains
- [create](docs/sdks/domains/README.md#create) - Create a domain
- [delete](docs/sdks/domains/README.md#delete) - Delete a domain
- [update](docs/sdks/domains/README.md#update) - Update a domain
- [register](docs/sdks/domains/README.md#register) - Register a domain
- [checkStatus](docs/sdks/domains/README.md#checkstatus) - Check the availability of one or more domains

### [EmbedTokens](docs/sdks/embedtokens/README.md)

[](#embedtokens)

- [referrals](docs/sdks/embedtokens/README.md#referrals) - Create a referrals embed token

### [Events](docs/sdks/events/README.md)

[](#events)

- [list](docs/sdks/events/README.md#list) - Retrieve a list of events

### [Folders](docs/sdks/folders/README.md)

[](#folders)

- [list](docs/sdks/folders/README.md#list) - Retrieve a list of folders
- [create](docs/sdks/folders/README.md#create) - Create a folder
- [delete](docs/sdks/folders/README.md#delete) - Delete a folder
- [update](docs/sdks/folders/README.md#update) - Update a folder

### [Links](docs/sdks/links/README.md)

[](#links)

- [list](docs/sdks/links/README.md#list) - Retrieve a list of links
- [create](docs/sdks/links/README.md#create) - Create a link
- [count](docs/sdks/links/README.md#count) - Retrieve links count
- [get](docs/sdks/links/README.md#get) - Retrieve a link
- [delete](docs/sdks/links/README.md#delete) - Delete a link
- [update](docs/sdks/links/README.md#update) - Update a link
- [createMany](docs/sdks/links/README.md#createmany) - Bulk create links
- [deleteMany](docs/sdks/links/README.md#deletemany) - Bulk delete links
- [updateMany](docs/sdks/links/README.md#updatemany) - Bulk update links
- [upsert](docs/sdks/links/README.md#upsert) - Upsert a link

### [Partners](docs/sdks/partners/README.md)

[](#partners)

- [list](docs/sdks/partners/README.md#list) - List all partners
- [create](docs/sdks/partners/README.md#create) - Create or update a partner
- [retrieveLinks](docs/sdks/partners/README.md#retrievelinks) - Retrieve a partner's links.
- [createLink](docs/sdks/partners/README.md#createlink) - Create a link for a partner
- [upsertLink](docs/sdks/partners/README.md#upsertlink) - Upsert a link for a partner
- [analytics](docs/sdks/partners/README.md#analytics) - Retrieve analytics for a partner
- [ban](docs/sdks/partners/README.md#ban) - Ban a partner
- [deactivate](docs/sdks/partners/README.md#deactivate) - Deactivate a partner

### [Payouts](docs/sdks/payouts/README.md)

[](#payouts)

- [list](docs/sdks/payouts/README.md#list) - List all payouts

### [QRCodes](docs/sdks/qrcodes/README.md)

[](#qrcodes)

- [get](docs/sdks/qrcodes/README.md#get) - Retrieve a QR code

### [Tags](docs/sdks/tags/README.md)

[](#tags)

- [list](docs/sdks/tags/README.md#list) - Retrieve a list of tags
- [create](docs/sdks/tags/README.md#create) - Create a tag
- [delete](docs/sdks/tags/README.md#delete) - Delete a tag
- [update](docs/sdks/tags/README.md#update) - Update a tag

### [Track](docs/sdks/track/README.md)

[](#track)

- [lead](docs/sdks/track/README.md#lead) - Track a lead
- [sale](docs/sdks/track/README.md#sale) - Track a sale

Pagination
----------

[](#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(
    pageSize: 50,
);

$responses = $sdk->links->list(
    request: $request
);

foreach ($responses as $response) {
    if ($response->statusCode === 200) {
        // handle response
    }
}
```

Error Handling
--------------

[](#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:

PropertyTypeDescription`$message`*string*The error message`$statusCode`*int*The HTTP status code`$rawResponse`*?\\Psr\\Http\\Message\\ResponseInterface*The raw HTTP response`$body`*string*The response contentWhen 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 `list` method throws the following exceptions:

Error TypeStatus CodeContent TypeErrors\\BadRequest400application/jsonErrors\\Unauthorized401application/jsonErrors\\Forbidden403application/jsonErrors\\NotFound404application/jsonErrors\\Conflict409application/jsonErrors\\InviteExpired410application/jsonErrors\\UnprocessableEntity422application/jsonErrors\\RateLimitExceeded429application/jsonErrors\\InternalServerError500application/jsonErrors\\SDKException4XX, 5XX\*/\*### Example

[](#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\GetLinksRequest(
        pageSize: 50,
    );

    $responses = $sdk->links->list(
        request: $request
    );

    foreach ($responses as $response) {
        if ($response->statusCode === 200) {
            // 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
----------------

[](#server-selection)

### Override Server URL Per-Client

[](#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\GetLinksRequest(
    pageSize: 50,
);

$responses = $sdk->links->list(
    request: $request
);

foreach ($responses as $response) {
    if ($response->statusCode === 200) {
        // handle response
    }
}
```

Development
===========

[](#development)

Maturity
--------

[](#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
-------------

[](#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](https://docs.speakeasyapi.dev/docs/using-speakeasy/client-sdks)

[](#sdk-created-by-speakeasy)

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance83

Actively maintained with recent releases

Popularity33

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

119

Last Release

91d ago

PHP version history (3 changes)0.0.1PHP ^8.1

v0.7.0PHP ^8.2

v0.12.36PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/debb9ba8696361140a3cc49e57c13e2a208eadf8a7c14dca08aec67939d39e1c?d=identicon)[devkiran](/maintainers/devkiran)

![](https://www.gravatar.com/avatar/3629e3bc0494e7fda4e3c2011620cac6856407dc39c32dad0b41c2352a571947?d=identicon)[steventey](/maintainers/steventey)

---

Top Contributors

[![speakeasybot](https://avatars.githubusercontent.com/u/108416695?v=4)](https://github.com/speakeasybot "speakeasybot (143 commits)")[![devkiran](https://avatars.githubusercontent.com/u/4593041?v=4)](https://github.com/devkiran "devkiran (100 commits)")[![speakeasy-github[bot]](https://avatars.githubusercontent.com/in/308252?v=4)](https://github.com/speakeasy-github[bot] "speakeasy-github[bot] (64 commits)")[![steven-tey](https://avatars.githubusercontent.com/u/28986134?v=4)](https://github.com/steven-tey "steven-tey (45 commits)")[![mfbx9da4](https://avatars.githubusercontent.com/u/1690659?v=4)](https://github.com/mfbx9da4 "mfbx9da4 (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dub-dub-php/health.svg)

```
[![Health](https://phpackages.com/badges/dub-dub-php/health.svg)](https://phpackages.com/packages/dub-dub-php)
```

###  Alternatives

[clerkinc/backend-php

2755.0k](/packages/clerkinc-backend-php)[polar-sh/sdk

4014.5k4](/packages/polar-sh-sdk)[blair2004/nexopos

The Free Modern Point Of Sale System build with Laravel, TailwindCSS and Vue.js.

1.2k2.3k](/packages/blair2004-nexopos)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
