Dub’s API is now generally available. Read the announcement.

Base URL

Dub’s API is built on REST principles and is served over HTTPS. To ensure data privacy, unencrypted HTTP is not supported.

The Base URL for all API endpoints is:

Terminal
https://api.dub.co

Authentication

Authentication to Dub’s API is performed via the Authorization header with a Bearer token. To authenticate, you need to include the Authorization header with the word Bearer followed by your API key in your requests like so:

Terminal
Authorization: Bearer dub_xxxxxx

Here are examples of how to authenticate with Dub’s API in different programming languages:

curl --request GET \
  --url https://api.dub.co/links \
  --header 'Authorization: Bearer dub_xxxxxx'

Learn more about how to get your API key.

Native SDKs

Dub offers native SDKs in some of the most popular programming languages:

You can find the full list of SDKs here.

Error Handling

Dub API returns machine readable error codes, human readable error messages and a link to the docs for more information.

Here is how an error response looks like:

{
  "error": {
    "code": "not_found",
    "message": "The requested resource was not found.",
    "doc_url": "https://dub.co/docs/api-reference/errors#not-found"
  }
}

Here is a list of all error codes Dub API returns:

Pagination

Dub’s API supports pagination. This is useful when you have a large number of resources and you want to retrieve them in smaller chunks.

These list API methods share a common set of parameters that allow you to control the number of items returned and the page number. For example, you can:

Parameters

page
string
default:"1"

The page number to retrieve. By default, the first page is returned.

pageSize
string

The number of items to retrieve per page. The default value varies by endpoint. Maximum value is 100.

sortBy
string

The field to sort the results by.

sortOrder
string

The order to sort the results by. Can be asc or desc.

Example

The following example demonstrates how to retrieve the first page of 10 links:

curl --request GET \
  --url https://api.dub.co/links?page=1&pageSize=10 \
  --header 'Authorization: Bearer <token>'