snipp-gg/snipp-js
@snipp-gg/snipp
Installation
fetch and FormData.
Getting Started
Regional endpoints
Passregion 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 aSnippError with these properties:
Migrating from 2.x
3.0 follows the reorganized Snipp API.- Posts use one shape everywhere:
privacy(waspost_privacy),created_at(wascreated),view_count(wasviews),files[].name(wasfile_name), andfile_countreplacesis_album. The top-levelurls,file, andthumbnail_urlare gone; readfiles. upload()resolves to{ url, post };message,file, andprocessing_timeare gone.- Users carry
plan(free,plus, orultra) in place ofplus,ultra, andbadges,created_atin place ofcreated, andblockingin place ofblocked_by_you. - The API now sends every error as an
errorobject withtype,message, and any context fields.SnippErrorgainstype, and context fields moved from the top ofbodyintobody.error. A check likeerr.body?.suspendedbecomeserr.type === "suspended".