Skip to main content

snipp-gg/snipp-js

@snipp-gg/snipp

Installation

npm install @snipp-gg/snipp
Requires Node.js 18 or later. Zero dependencies — uses native fetch and FormData.

Getting started

import { SnippClient } from "@snipp-gg/snipp";

const client = new SnippClient({ apiKey: process.env.SNIPP_API_KEY });

const me = await client.getUser("@me");
console.log(me.user.username);

Methods

getUser(id, options?)

Fetch a user by ID. Pass "@me" for the authenticated user.
OptionTypeDescription
includePostsbooleanInclude the user’s public uploads.
postsLimitnumberNumber of posts to return (1-50).
const user = await client.getUser("@me", { includePosts: true, postsLimit: 10 });

getPost(code)

Fetch a post by its share code.
const post = await client.getPost("AbCd1234");
console.log(post.post.url);

upload(file, options?)

Upload a file. Accepts a File, Blob, Buffer, or Uint8Array.
OptionTypeDescription
privacy"public" | "unlisted" | "private"Visibility of the upload.
filenamestringFilename sent with the upload (defaults to "upload").
import { readFileSync } from "node:fs";

const buffer = readFileSync("./image.png");
const result = await client.upload(buffer, { privacy: "unlisted", filename: "image.png" });
console.log(result.url);

listUploads()

List the authenticated user’s recent uploads.
const uploads = await client.listUploads();

editUpload(code, options)

Edit an existing upload’s title, description, or privacy.
OptionTypeDescription
titlestringNew title (max 30 chars). Empty string to clear.
descriptionstringNew description (max 200 chars). Empty string to clear.
privacy"public" | "unlisted" | "private"New visibility setting.
await client.editUpload("AbCd1234", { title: "New title", privacy: "public" });

deleteUpload(filename)

Delete an upload by its filename.
await client.deleteUpload("a3f7b2c91d4e8f0612ab34cd56ef7890.png");

discover()

Browse public uploads from the community.
const feed = await client.discover();

listBlocks()

List the users you have blocked.
const { blocks } = await client.listBlocks();

blockUser(targetId)

Block a user by their ID.
await client.blockUser("123456789012345678");

unblockUser(targetId)

Unblock a user by their ID.
await client.unblockUser("123456789012345678");

Error handling

All API errors throw a SnippError with status and message properties.
import { SnippClient, SnippError } from "@snipp-gg/snipp";

try {
  await client.getUser("nonexistent");
} catch (err) {
  if (err instanceof SnippError) {
    console.error(err.status, err.message);
  }
}