LinkForge

Aug 10, 2026

Automating Link Creation With an API

Creating links by hand is fine until it isn't. Once link creation is part of a repeating process — publishing a post, adding a product, sending a campaign — doing it manually is both slow and a source of inconsistency, because humans forget conventions and scripts don't.

When it's worth automating

Reasonable triggers:

  • You're creating more than a handful of links a week on a schedule
  • Links need to follow a naming convention exactly, every time
  • Something else already knows the destination — a CMS, a product feed, a scheduler
  • You want links to exist before a human needs them, not after

If you make a few links a month by hand, the API is overhead. Be honest about which you are.

Authentication

LinkForge's API uses bearer keys prefixed lf_, sent in an Authorization header, against endpoints under /api/v1. Create a key from Settings, name it after the thing that will use it, and treat it like a password.

Two habits worth having from the start:

One key per integration. If the publishing script and the reporting job share a key, you can't revoke one without breaking the other. Separate keys mean you can kill a compromised one immediately.

Never commit a key. Environment variables, not source files. A key in a repository is a key in everyone's clone forever, including after you delete it.

Rate limits, and how to behave

There's a per-minute limit. Two rules keep you inside it:

Don't hammer in a tight loop. If you're creating hundreds of links, space the requests out. A short pause between calls costs you seconds and avoids being throttled.

Back off on failure, don't retry immediately. If a request fails, wait — and wait longer each time. Immediate retries turn a small problem into a rate-limit ban. Retry a few times with increasing delays, then give up and log it loudly.

For genuinely large batches, use bulk import instead of the API in a loop. It's built for that shape of work — see bulk shortening.

Make creation idempotent

The single most important design decision. If your script runs twice — a retry, a cron overlap, someone re-running it — you do not want two links to the same destination with split analytics.

The fix is to derive the slug deterministically from something stable, like the source system's id. post-4417 rather than a random back-half. Then creating it twice is either a no-op or a recognisable conflict, instead of silent duplication.

This one decision prevents most of the mess that accumulates in automated link setups.

Handle the errors that will actually happen

  • Slug already taken — either your idempotency working as intended, or a genuine collision. Decide which and handle it explicitly rather than falling back to a random slug, which quietly destroys your convention.
  • Invalid destination URL — validate before sending, especially if the URL comes from user input or a feed.
  • Rate limited — back off as above.
  • Network failure — the request may have succeeded even though you didn't get the response. This is why deterministic slugs matter: you can safely check whether the link exists rather than blindly creating another.

Store the result

Whatever creates the link should record the short URL against the source record. Otherwise you'll be querying the API every time you need it, or worse, creating a second link because you couldn't find the first.

A sensible pattern

  1. Something publishes — a post, a product, a campaign.
  2. Your script derives a deterministic slug from its id.
  3. It checks whether that link already exists; if so, it uses it.
  4. If not, it creates the link with UTMs and tags attached.
  5. It stores the short URL back on the source record.
  6. Failures are logged loudly, not swallowed.

That's a few dozen lines and it removes an entire category of manual work and human inconsistency.

Read the API docs — endpoints, auth and rate limits, or create a key to start.

Track every click, free

Unlimited short links with real-time analytics.

Create free account