kutt - v4.0.0
    Preparing search index...

    Class LinkAPI

    Provides Kutt v2 short-link operations using this instance's configuration.

    By default, the configuration is copied from KUTT_CONFIG when the instance is created.

    import { LinkAPI } from "kutt";

    const links = new LinkAPI().setAPIKey("YOUR_API_KEY");
    const page = await links.listV2({ limit: 10 });

    Hierarchy (View Summary)

    Index
    • Creates or reuses a short link using this instance's configuration.

      Parameters

      • link: TNewLinkV2

        The destination URL and optional short-link settings.

      Returns Promise<TLinkV2>

      The created or reused link, with createdAt and updatedAt converted to Date objects.

      HTTPError If the API returns an unsuccessful HTTP response.

      If the request fails, times out, or the response cannot be decoded.

      import { Kutt } from "kutt";

      const kutt = new Kutt().setAPIKey("YOUR_API_KEY");
      const link = await kutt.links().createV2({
      target: "https://example.com/article",
      customURL: "article",
      expireIn: "2 days",
      });
    • Gets the API key sent in the X-API-KEY request header.

      Returns string

      The configured API key, or an empty string when no key is set.

    • Gets the API base URL used to resolve endpoint paths such as v2/links.

      Returns string

      The configured API base URL.

    • Gets a page of short links using this instance's configuration.

      Parameters

      • pagination: TAPIPaginationOptionsV2

        Page size, offset, and administrator visibility settings. Pass {} to use the API server's defaults.

      Returns Promise<TAPIPaginatedResponseV2<TLinkV2>>

      A page of links with normalized dates and pagination metadata.

      HTTPError If the API returns an unsuccessful HTTP response.

      If the request fails, times out, or the response cannot be decoded.

      import { Kutt } from "kutt";

      const kutt = new Kutt().setAPIKey("YOUR_API_KEY");
      const page = await kutt.links().listV2({ limit: 10, skip: 0, all: false });
    • Deletes a short link using this instance's configuration.

      Parameters

      • linkId: string

        The link's unique ID.

      Returns Promise<string>

      The deletion message returned by the API.

      HTTPError If the API returns an unsuccessful HTTP response.

      If the request fails, times out, or the response cannot be decoded.

      import { Kutt } from "kutt";

      const kutt = new Kutt().setAPIKey("YOUR_API_KEY");
      const message = await kutt.links().removeV2("497f6eca-6276-4993-bfeb-53cbbbba6f08");
    • Sets the API key sent in the X-API-KEY request header.

      Parameters

      • apiKey: string

        API key to send. An empty string omits the header.

      • Optionalseal: boolean

        Whether to prevent further changes to this setting. Defaults to false.

      Returns this

      This instance for chained configuration calls.

      If the API key setting is already sealed.

      import { Kutt } from "kutt";

      const kutt = new Kutt().setAPIKey("YOUR_API_KEY");
    • Sets the API base URL used to resolve endpoint paths such as v2/links.

      Parameters

      • baseURL: string

        API root URL, such as https://kutt.to/api/.

      • Optionalseal: boolean

        Whether to prevent further changes to this setting. Defaults to false.

      Returns this

      This instance for chained configuration calls.

      If the base URL setting is already sealed.

      import { Kutt } from "kutt";

      const kutt = new Kutt().setBaseURL("https://kutt.example.com/api/", true);
    • Sets the request timeout in milliseconds.

      Parameters

      • timeout: number

        Timeout passed to AbortSignal.timeout when a request starts.

      • Optionalseal: boolean

        Whether to prevent further changes to this setting. Defaults to false.

      Returns this

      This instance for chained configuration calls.

      If the timeout setting is already sealed.

      import { Kutt } from "kutt";

      const kutt = new Kutt().setTimeout(10_000);
    • Gets a short link's visit statistics using this instance's configuration.

      Parameters

      • linkId: string

        The link's unique ID.

      Returns Promise<TLinkStatsV2>

      The link and its daily, weekly, monthly, and yearly statistics with normalized dates.

      HTTPError If the API returns an unsuccessful HTTP response.

      If the request fails, times out, or the response cannot be decoded.

      import { Kutt } from "kutt";

      const kutt = new Kutt().setAPIKey("YOUR_API_KEY");
      const stats = await kutt.links().statsV2("497f6eca-6276-4993-bfeb-53cbbbba6f08");
    • Updates a short link using this instance's configuration.

      Parameters

      • linkId: string

        The link's unique ID.

      • link: TUpdateLinkV2

        The short-link address, destination URL, and optional changes.

      Returns Promise<TLinkV2>

      The updated link, with createdAt and updatedAt converted to Date objects.

      HTTPError If the API returns an unsuccessful HTTP response.

      If the request fails, times out, or the response cannot be decoded.

      import { Kutt } from "kutt";

      const kutt = new Kutt().setAPIKey("YOUR_API_KEY");
      const link = await kutt.links().updateV2(
      "497f6eca-6276-4993-bfeb-53cbbbba6f08",
      { address: "article", target: "https://example.com/updated-article" },
      );