Skip to content

SDKs

The official SDKs call the Shortn API for you: they send your key, build the URLs, turn error answers into exceptions and retry what is safe to retry. They are optional. Every SDK covers the same endpoints with the same names, so what you learn in one carries over to the others, and anything you can do with an SDK you can also do over plain HTTP (see making requests).

Coming soon: the SDK packages are being published. Until then, use the API directly; everything on this page works the same over plain HTTP.
LanguagePackageRequiresSource
JavaScript and TypeScript@jednasoftware/shortn-sdk (npm)Node.js 20+shortn-sdk-js
Pythonshortn-sdk (PyPI)Python 3.10+shortn-sdk-python
Gogithub.com/jedna-software/shortn-sdk-goGo 1.22+shortn-sdk-go
PHPjednasoftware/shortn-sdk (Packagist)PHP 8.1+shortn-sdk-php
Rubyshortn-sdk (RubyGems)Ruby 3.1+shortn-sdk-ruby

Each repository’s README documents every method and option.

Install

npm install @jednasoftware/shortn-sdk

Create a client

Read the key from the environment; see API keys.

import { Shortn } from "@jednasoftware/shortn-sdk";

const shortn = new Shortn({ apiKey: process.env.SHORTN_API_KEY });

Create a link

Parameters and results use the API’s own field names, as the reference lists them.

const link = await shortn.links.create({
  url: "https://example.com/spring",
  title: "Spring campaign",
  workspace_public_id: "8c0f6b52-4d0e-4a71-9a3e-2f6d1c7b5a10",
});
console.log(link.short_url, link.public_id);

Send a lead

Send the visitor’s click id (snt_click_id, see send conversion events) with an idempotency_key from your own system, so a retry is recorded once.

await shortn.conversions.trackLead({
  click_id: clickId,
  event_name: "signup",
  idempotency_key: `signup_${user.id}`,
});

Handle errors

An error answer raises one error type with the HTTP status, the error code (branch on this), the message, and the hint, details and request_id when the API sends them.

import { ShortnAPIError } from "@jednasoftware/shortn-sdk";

try {
  await shortn.links.get(publicId);
} catch (err) {
  if (err instanceof ShortnAPIError && err.code === "link_not_found") {
    // ...
  } else {
    throw err;
  }
}

What every SDK does

  • Endpoints: each group of the API is a property of the client, with one method per endpoint:

    GroupMethods
    linkslist, get, create, update, delete (suspends), enable, set A/B winner
    analyticsa link’s clicks
    workspaceslist, get
    tags, teamslist, create, get, update, delete
    utmTemplates, destinationslist, create, update, delete
    domainslist, create, verify, delete
    reportslist, get, create, update and delete rules
    conversionstrack and validate leads, sales and refunds; summary, attribution, timeline, events
    publicvalidate a URL, draw a QR code, list plans (no key needed)

    Names follow each language: utmTemplates.create in JavaScript, utm_templates.create in Python and Ruby, UTMTemplates.Create in Go.

  • Results are the API’s JSON, with every field kept, including ones added after your SDK version.

  • Retries follow the safe-retry rules: 429, 503 and network errors are retried a few times with backoff, honouring Retry-After, for reads, updates, deletes and conversion events that carry an idempotency_key. Creating a link, tag or team is never retried. Give sales and refunds an idempotency_key too if you want them retried. Test-mode events are never retried, because test events are never deduplicated. When Retry-After asks for a longer wait than the SDK allows, such as after the monthly limit, the error is returned at once. You can change the attempts or turn retries off.

  • Timeouts apply to each attempt and can be changed.

  • Base URL defaults to https://app.shortn.link; the SDK adds /api/v1.

  • The client sends a User-Agent such as shortn-sdk-python/0.1.0, plus your own suffix if you set one.

Found a bug or a missing endpoint? Open an issue in the SDK’s repository.

Last updated on