Skip to main content
snipp-gg/snipp-js
@snipp-gg/snipp

Installation

Requires Node.js 18 or later. Zero dependencies. Uses native fetch and FormData.

Getting Started

Regional endpoints

Pass region to pin the client to a specific regional host. Uploads run at the same speed either way; this controls which region stores your files.

Methods

Every method resolves to the parsed JSON response. Posts, files, and users follow the shapes in the API reference, and the package ships JSDoc typedefs (Post, PostFile, User, PostList, and the rest) for editor completion.

getUser(id)

Fetch a user by ID. Pass "@me" for the authenticated user. api_key, key_has_uploads_access, upload_count, and limits are only present on yourself.

getUserPosts(id, options?)

List a user’s public posts, newest first. Team, private, unlisted, moderated, and restricted posts are never included. Pass "@me" for your own public posts.

listPosts(options?)

List your own posts of every privacy, newest first. Team posts are not included. Takes the same limit and cursor options as getUserPosts. Follow next_cursor until it is null to walk every page.

getPost(code)

Fetch a post by its share code. Team posts are only readable by members of that team, and have like_count and liked set to null.

upload(file, options?)

Upload a file as a new post. Accepts a File, Blob, Buffer, or Uint8Array. Resolves to { url, post }, where url is the direct file URL and post.url is the share page, https://snipp.gg/p/{code} or https://{domain}/{code} on your link domain.

updatePost(code, options)

Update a post’s title, description, or privacy. Only the fields you pass are changed. A team post’s privacy cannot be changed. Resolves to { post }.

addFiles(code, files, options?)

Add one or more files to an existing post, turning it into an album. The post’s share code, privacy, title, and description are preserved. Posts cap at 50 files total. Requests that would exceed the cap are rejected. New files inherit the post’s privacy. Resolves to { post, failed? }; failed lists the files that were rejected, each with its index and error.

deleteFile(code, name)

Delete one file from a post, by the name it has in post.files. Deleting a post’s only file deletes the post.

deletePost(code)

Delete a post and every file in it.

reportPost(code, reason?)

Report a post, with an optional reason (max 200 chars).

reportUser(id, reason?)

Report a user, with an optional reason (max 200 chars).

Error Handling

All API errors throw a SnippError with these properties:

Migrating from 2.x

3.0 follows the reorganized Snipp API.
  • Posts use one shape everywhere: privacy (was post_privacy), created_at (was created), view_count (was views), files[].name (was file_name), and file_count replaces is_album. The top-level urls, file, and thumbnail_url are gone; read files.
  • upload() resolves to { url, post }; message, file, and processing_time are gone.
  • Users carry plan (free, plus, or ultra) in place of plus, ultra, and badges, created_at in place of created, and blocking in place of blocked_by_you.
  • The API now sends every error as an error object with type, message, and any context fields. SnippError gains type, and context fields moved from the top of body into body.error. A check like err.body?.suspended becomes err.type === "suspended".