Short.io Node.js SDK
The Short.io Node.js official SDK client is a library that allows you to integrate short.io URL shortening and link management API with your Node.js application in an easy and elegant way.
API reference
See the API docs for more information.
Installing
To install this package, type:
npm i @short.io/client-node
Getting Started
First you need to get your API key from the Short.io dashboard in the Integrations & API section.
This SDK contains methods for working with links, domains and statistics. Import the Shortio class:
import { Shortio } from "shortio";
Usage
Then create an instance of the Shortio class, and pass your API key as the first parameter:
const shortio = new Shortio("YOUR_API_KEY");
To get the domain list, you can use the following code:
const domains = await shortio.domain.list();
Get the link list of the first domain above:
const links = await shortio.link.list(domains[0].id);
Get the link statistics of the first link above:
const stats = await shortio.statistics.getByLink(links[0].idString);
Create links:
const link = await shortio.link.create({
domain: "link.example.com",
path: "example",
originalURL: "https://example.com",
});
console.log(link.shortURL);
const publicLink = await shortio.link.createPublic({
domain: "link.example.com",
originalURL: "https://example.com",
publicAPIKey: "PUBLIC_API_KEY",
});
console.log(publicLink.shortURL);
const secureLink = await shortio.link.createSecure({
domain: "link.example.com",
publicAPIKey: "PUBLIC_API_KEY",
originalURL: "https://example.com",
});
console.log(secureLink.shortURL);