The SDK is currently in active development. For more details, see the U301 Postman docs.

Create a short link to any URL

Monthly link allowance

Newly created links count toward the workspace's monthly allowance across the website and API. New free accounts receive 100 links per month; eligible existing accounts keep 1,000. Reusing an existing link does not consume another slot. An oversized bulk request returns HTTP 429 without creating new links. See Monthly link allowances for limits, resets, and error handling.

Creating a short link in U301 is simple. Here's a minimal example:

u301.links.create
import { U301 } from 'u301';

const apiKey = '<YOUR_API_KEY>';
const workspaceId = '<YOUR_WORKSPACE_ID>';

const u301 = new U301({
  apiKey,
  workspaceId,
});
const link = await u301.links.create('https://example.com'); 
console.log(link);

the response

Request

NameLocationTypeRequiredDefaultDescription
AuthorizationHeaderstringBearer token used for authentication.
workspaceIdQuerystringWorkspace identifier for multi‑tenant routing.
urlBodystringDestination URL to shorten.
domainBodystringu301.coDomain for the short link.
slugBodystringRandom stringCustom path segment. When omitted, a random slug is generated.
reuseExistingBodybooleanfalseReuse an existing short link if the same url already exists.
passwordBodystringnullPassword required to open the short link.
commentBodystringnullComment for short URL

Response

NameTypeDescription
idstringUnique identifier of the link.
urlstringOriginal destination URL.
slugstringPath segment of the short link.
isCustomSlugbooleanWhether the slug was provided by the user.
domainstringDomain used for the short link.
isReusedbooleanIndicates the link was reused due to reuseExisting.
shortLinkstringFully qualified short link ({domain}/{slug}).
commentstringOptional note attached to the link.
response-example.json
{
  "id": "019a7d8c-4a85-7aa4-9862-ee2008f54854",
  "url": "https://example.com",
  "slug": "jtyZ",
  "isCustomSlug": false,
  "domain": "u301.co",
  "isReused": false,
  "shortLink": "u301.co/jtyZ",
  "comment": ""
}

Create multiple links in one call by passing an array to createMany:

u301.links.createMany
const link = await u301.links.createMany([
  'https://example.com',
  'https://example.org',
]);

Custom domain and path (slug)

Want a branded short link, like a fixed path https://u301.co/launch, or your own domain instead of u301.co? Provide domain and slug:

u301.links.create
const link = await u301.links.create({
  url: 'https://example.com',
  domain: 'u301.co', 
  slug: 'launch', 
});

Handle duplicate URLs

If the target URL already exists, you may prefer to reuse the existing short link instead of creating a new one. Set reuseExisting to true:

u301.links.create
const link = await u301.links.create({
  url: 'https://example.com',
  reuseExisting: true, 
});

The response marks isReused as true:

{
  "id": "019a7d8c-4a85-7aa4-9862-ee2008f54854",
  "url": "https://example.com",
  "slug": "jtyZ",
  "isCustomSlug": false,
  "domain": "u301.co",
  "isReused": true, 
  "shortLink": "u301.co/jtyZ",
  "comment": ""
}

Require a password before resolving to the target URL by setting password:

u301.links.create
const link = await u301.links.create({
  url: 'https://example.com',
  password: 'example-password', 
});

Try https://u301.co/4jnB with password example-password.

Last updated on