### Example usage of IqdbQueries get and post Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/iqdb.md Shows how to use e621.iqdb.get to search by image URL and e621.iqdb.post to search by post ID. The get example uses v2: true and checks the result post type. ```typescript import E621 from "e621"; const e621 = new E621(); // search by image file URL const results = await e621.iqdb.get({ url: "https://example.com/image.png", v2: true, }); console.log(results[0]?.post instanceof (await import("e621/models")).BasicPost); // true // search by an existing post's id const byPost = await e621.iqdb.post({ post_id: 1234 }); console.log(byPost[0]?.post_id, byPost[0]?.score); ``` -------------------------------- ### Install Playwright and run tests Source: https://github.com/donovandmc/e621/blob/dev/README.md One-time setup for Playwright's Chromium browser, then run the test suite with npm test. ```bash npx playwright install --with-deps chromium # one-time npm test ``` -------------------------------- ### DText preview usage example Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/sessions.md Example that renders DText markup. Returns the rendered HTML plus post/item data. ```typescript const e621 = new E621(); const { html } = await e621.dtext.preview("hello **[world]**"); ``` -------------------------------- ### E621 Users API Examples Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/users.md Examples of using the E621 users API to fetch current user, get a user by name, toggle uploads, and handle errors. ```APIDOC ## E621 Users API ### Description Examples of using the E621 users API to retrieve current user, fetch a user by name, toggle uploads, and update user information. ### Methods #### users.me() - **Description**: Retrieves the current authenticated user. - **Returns**: FullCurrentUser - **Example**: ```typescript const me = await e621.users.me(); console.log(me.name, me.blacklisted_tags); ``` #### users.get(nameOrId) - **Description**: Fetches a user by name or ID. Returns null if not found and throwOnNotFound is false. - **Parameters**: - nameOrId (string | number) - Required - The username or user ID. - **Returns**: FullUser | FullCurrentUser | null - **Example**: ```typescript const someone = await e621.users.get("someone"); const none = await e621.users.get(1); // 404 → null (throwOnNotFound=false) ``` #### users.update(nameOrId, data) - **Description**: Updates a user's information. Throws on failure. - **Parameters**: - nameOrId (string | number) - Required - The username or user ID. - data (object) - Required - The update data, e.g., { name: "x" }. - **Returns**: 204 on success; throws UnexpectedResponseError on failure. - **Example**: ```typescript await e621.users.update("someone", { name: "x" }); ``` #### toggleUploads() - **Description**: Staff action to toggle uploads for a user. Returns a string (302). - **Returns**: string - **Example**: ```typescript await someone?.toggleUploads(); ``` ### Error Handling - **404**: users.get returns null when throwOnNotFound is false. - **UnexpectedResponseError**: Thrown when an expected response code is not received, e.g., 204 for update. ### Related - base-model.md — Base model semantics - types.md — User, CurrentUser, FullUser, FullCurrentUser, MinimalUser data shapes - endpoints.md — /users*.json routes ``` -------------------------------- ### Example: get popular posts for a day Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/popular.md Shows how to fetch the most popular posts for a specific day using the get method with v2 and extended mode. Logs the count and first post ID. ```typescript import E621 from "e621"; const e621 = new E621(); // most popular posts for a day const daily = await e621.popular.get({ date: "2025-01-01", scale: "day", v2: true, mode: "extended" }); console.log(daily.length, daily[0]?.id); ``` -------------------------------- ### Artists CRUD example Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/artists.md Shows the full CRUD workflow: create, get, update, and delete an artist. Requires authentication with `authUser` and `authKey`. ```typescript import E621 from "e621"; const e621 = new E621({ authUser: "u", authKey: "k" }); const artist = await e621.artists.create({ name: "new_artist", url_string: "https://example.com", }); // Artist (201) const found = await e621.artists.get("new_artist"); // Artist | null await e621.artists.update(found.id, { name: "renamed_artist" }); await e621.artists.delete("renamed_artist"); // null (204) ``` -------------------------------- ### Create Upload Example Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/uploads.md Demonstrates how to create a new post upload using a file and basic metadata. ```typescript import E621 from "e621"; import { readFile } from "node:fs/promises"; const e621 = new E621({ authUser: "u", authKey: "k" }); const file = new File([await readFile("art.png")], "art.png", { type: "image/png" }); const post = await e621.uploads.create({ file, rating: "s", tag_string: "canine original", }); console.log(post.id); ``` -------------------------------- ### Sessions create usage example Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/sessions.md Example that logs in with a username and password. The response sets the `_danbooru_session` cookie for subsequent browser-auth calls. ```typescript const e621 = new E621(); const res = await e621.sessions.create({ name: "user", password: "pass" }); // res sets the _danbooru_session cookie for subsequent browser-auth calls ``` -------------------------------- ### Install e621 package with npm Source: https://github.com/donovandmc/e621/blob/dev/README.md Install the e621 package using npm. Requires NodeJS 20.19.0 or higher. ```bash npm install e621 ``` -------------------------------- ### Instantiate E621 and check module availability Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/modules.md Shows how to create an E621 instance and verify that modules are spread over it. The example checks that e621.posts is an instance of the Posts module and that e621.iqdb.moduleKey equals 'iqdb'. ```typescript import E621 from "e621"; const e621 = new E621(); // modules spread over the instance: console.log(e621.posts instanceof (await import("e621/modules/Posts")).default); // true console.log(e621.iqdb.moduleKey === "iqdb"); // true ``` -------------------------------- ### Initialize E621 Client Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/E621.md Basic setup for the E621 client using authentication credentials and accessing various modules. ```typescript import E621 from "e621"; const e621 = new E621({ authUser: "myusername", authKey: "0123456789abcdef", // Account -> Manage API Access }); const post = await e621.posts.get(1234); // Post | null if (post) console.log(post.file?.url); // any module is reachable off the instance const user = await e621.users.get(9999); // FullUser | FullCurrentUser | null const wiki = await e621.wikiPages.get("help:home"); ``` -------------------------------- ### Error handling example for all modules Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/sessions.md Shows how to catch `UnexpectedResponseError` when an API call returns an unexpected status. The example uses `dtext.preview` with an empty string, illustrating that a 400 response causes a throw. ```typescript import E621 from "e621"; import { UnexpectedResponseError } from "e621"; const e621 = new E621(); try { await e621.dtext.preview(""); // 400 from API? -> throws } catch (err) { if (err instanceof UnexpectedResponseError) { console.log(err.response?.status, err.message); } } ``` -------------------------------- ### Favorites usage example Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/favorites.md Shows how to create a favorite and search favorites with v2 and extended mode. ```typescript import E621 from "e621"; const e621 = new E621({ authUser: "u", authKey: "k" }); const res = await e621.favorites.create(1234); console.log(res.favorite_count); // updated count const favs = await e621.favorites.search({ user_id: 9999, limit: 50, v2: true, mode: "extended", }); // Array ``` -------------------------------- ### Using Base module methods Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/Base.md Demonstrates how to interact with module methods for retrieving, creating, deleting, and redirecting resources. Note that get() returns null for missing items when throwOnNotFound is false. ```typescript import E621 from "e621"; const e621 = new E621(); // successStatus=200, throwOnNotFound=false → get() returns null for a missing artist const artist = await e621.artists.get("some_artist"); // Artist | null // successStatus=201, klass=Comment → creates a Comment model instance const comment = await e621.comments.create({ body: "nice post" }); console.log(comment.id, comment.body); // successStatus=204 → null await e621.comments.delete(comment.id); // a 302 endpoint returns the redirect Location string const url = await e621.users.clearFavorites(42); // string ``` -------------------------------- ### get method signature for iqdb_queries#show Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/iqdb.md Defines the get method that queries IQDB by image URL. Options include url, tags, score_cutoff, minimal_score, and v2. Non-v2 keys are prefixed with search[...]. Returns an array of IqdbResult. ```typescript @OperationID("iqdb_queries#show") async get(options?: O): Promise>> ``` -------------------------------- ### get Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/users.md Retrieves a user by id or name. Returns FullUser or FullCurrentUser, or null on 404. ```APIDOC ## get ### Description Retrieves a user by id or name. Returns FullUser or FullCurrentUser, or null on 404. ### Method GET ### Endpoint /users/:id_or_name ### Parameters #### Path Parameters - **idOrName** (string | number) - Required - User id or name ### Response #### Success Response (200) - **FullUser** (object) - User data when no blacklisted_tags present - **FullCurrentUser** (object) - User data with blacklisted_tags #### Response Example { "id": 1, "name": "user" } ``` -------------------------------- ### SDK Usage Mapping Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/endpoints.md Examples of how to use the e621 SDK to call various API endpoints, mapping module methods to SDK functions and routes. ```APIDOC ## SDK Usage Mapping ### Description Examples of how to use the e621 SDK to call various API endpoints, mapping module methods to SDK functions and routes. ### Code Example ```typescript import E621 from "e621"; const e621 = new E621(); // module method → SDK function → route await e621.posts.get(5); // posts_show → GET /posts/5.json await e621.posts.search({}); // posts_index → GET /posts.json await e621.users.me(); // users_me → GET /users/me.json await e621.favorites.create(5); // favorites_create → POST /favorites.json await e621.sessions.destroy("tok"); // sessions_destroy → DELETE /session.json await e621.dtext.preview("hi"); // dtextPreviews_create → POST /dtext_preview.json ``` ``` -------------------------------- ### sequence(options?) Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/post-actions.md Gets the post in a sequence. Delegates to e621.posts.showSeq. Returns the post in the model's default format. ```APIDOC ## sequence(options?) ### Description Gets the post in a sequence. Delegates to `e621.posts.showSeq`. Returns the post in the model's default format. ### Method GET ### Endpoint `e621.posts.showSeq` ### Parameters - **options** (`GetPostInSequenceOptions`) - Optional - The options for getting the sequence. ### Response Returns a `PostFormat` of the post. ``` -------------------------------- ### get method Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/users.md Retrieves a user by ID or name. Returns FullUser or FullCurrentUser based on blacklisted_tags, or null on 404. ```typescript async get(idOrName: string | number): Promise ``` -------------------------------- ### Error handling example for IqdbQueries post Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/iqdb.md Demonstrates catching UnexpectedResponseError when the API returns a 404 for a non-existent post ID. Logs the response status. ```typescript import E621 from "e621"; import { UnexpectedResponseError } from "e621"; const e621 = new E621(); try { await e621.iqdb.post({ post_id: 99999999 }); // 404 from the API } catch (err) { if (err instanceof UnexpectedResponseError) console.log(err.response?.status); // 404 } ``` -------------------------------- ### Error handling example Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/comments.md Demonstrates catching an `UnexpectedResponseError` when updating a non-existent comment, logging the 404 status. ```typescript import E621 from "e621"; import { UnexpectedResponseError } from "e621"; const e621 = new E621(); try { await e621.comments.update(999999999, { body: "x" }); // no such comment → 404 } catch (err) { if (err instanceof UnexpectedResponseError) { console.log(err.response?.status); // 404 } } ``` -------------------------------- ### Upload Error Handling Example Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/uploads.md Shows how to catch an UnexpectedResponseError when an upload request fails due to lack of authentication or missing parameters. ```typescript const e621 = new E621(); // unauthenticated try { await e621.uploads.create({ rating: "s", tag_string: "x" }); // 403 — no auth, and no file } catch (err) { console.log((err as Error).name); // "UnexpectedResponseError" } ``` -------------------------------- ### Comment creation and voting example Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/comments.md Shows how to create a comment, update it, and upvote it using the module methods. The comment creation returns a `Comment` with status 201. ```typescript import E621 from "e621"; const e621 = new E621({ authUser: "u", authKey: "k" }); const comment = await e621.comments.create({ post_id: 1234, body: "great art!" }); // Comment (201) await comment.update({ body: "even better art!" }); await comment.createVote(1); // upvote ``` -------------------------------- ### get — iqdb_queries#show Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/iqdb.md Searches for similar posts by providing an image URL or other query parameters. Returns an array of IqdbResult objects. ```APIDOC ## [GET] iqdb_queries#show ### Description Searches for similar posts by providing an image URL or other query parameters. Returns an array of IqdbResult objects. ### Method GET ### Endpoint /iqdb_queries.json ### Parameters #### Query Parameters - **url** (string) - Optional - The URL of the image to search for. - **tags** (string) - Optional - Tags to include in the search. - **score_cutoff** (number) - Optional - Minimum score cutoff for results. - **minimal_score** (number) - Optional - Minimal score for results. - **v2** (boolean) - Optional - If true, returns v2 format results. ### Request Example { "url": "https://example.com/image.png", "v2": true } ### Response #### Success Response (200) - **hash** (string) - The hash of the image. - **post_id** (number) - The ID of the post. - **score** (number) - The similarity score. - **post** (object) - The post data. If v2 is true, it is a BasicPost object; otherwise, it is an IQDBPost object. #### Response Example json [ { "hash": "abc123", "post_id": 1234, "score": 0.95, "post": {} } ] ### Error Handling Throws UnexpectedResponseError if the response status is not 200. ``` -------------------------------- ### constructor(options?: Options) Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/E621.md Creates a new E621 API client instance. It initializes the underlying fetch client, resolves options, and attaches all 90 module instances. ```APIDOC ## constructor(options?: Options) ### Description Creates a new E621 API client instance. It initializes the underlying fetch client, resolves options, and attaches all 90 module instances. ### Method constructor ### Signature constructor(options?: Options) ### Parameters - **options** (Options) - Optional - Constructor options. See client.md for the full table: authKey, authUser, baseURL, defaultPostFormat, requestTimeout, statusCheckURL, userAgent, userAgentInQuery. ### Behavior 1. Calls createE621Client(options) to build the generated Client (with auth-header injection, default user agent, request logging) and the resolved InstanceOptions. 2. Assigns this.client and this.options. 3. Calls apply(this, this.client, options?.defaultPostFormat ?? {}) which constructs all 90 module instances and Object.assigns them onto the instance keyed by their moduleKey. ### Instance Properties - **client** (Client) - The generated fetch client. Direct access is needed for advanced use (interceptors, custom requests). - **options** (InstanceOptions) - Resolved options. - **appeals, artists, ..., wikiPageVersions** (module instances) - All 90 modules from the Modules interface. ### Throws - **UnexpectedResponseError** - Propagated from any module method when the HTTP response is not the expected success status (or a 404 when the method opted into returning null). ``` -------------------------------- ### Options Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/client.md Constructor options object for creating an E621 client. Configure authentication, base URL, default post format, request timeout, status check URL, and user agent. ```APIDOC ## Options ### Description Constructor options object for the E621 client. Allows configuration of authentication, base URL, default post format, request timeout, status check URL, and user agent. ### Type TypeScript interface ### Properties - **authKey** (string) - Optional - The API key to authenticate with (Account → Manage API Access) - **authUser** (string) - Optional - The username of the user to authenticate with - **baseURL** (string) - Optional - Default: `https://e621.net` - The base URL for the API - **defaultPostFormat** (PF) - Optional - Default: legacy (`v2: false`) - The `v2`/`mode` format every post-returning method falls back to when called without explicit `v2`/`mode` options; per-call options take priority over it - **requestTimeout** (number) - Optional - Default: `30` - Seconds before a request times out (stored in `InstanceOptions`; not otherwise read by `lib/` — it is carried through for consumer use/`setConfig`) - **statusCheckURL** (string) - Optional - Default: `https://status.e621.church/json` - URL to use for status checks (stored in `InstanceOptions`) - **userAgent** (string) - Optional - Default: `E621/{VERSION} (+https://github.com/DonovanDMC/E621)`; with `authUser`: `E621/{VERSION} (+https://github.com/DonovanDMC/E621; "{authUser}")` - User agent to send - **userAgentInQuery** (boolean) - Optional - Default: `false` in Node.js, `true` in browsers - Send the user agent in the `_client` query parameter instead of the `User-Agent` header (browsers cannot set that header) ### Example ```typescript const options: Options = { authKey: 'your-api-key', authUser: 'your-username', baseURL: 'https://e621.net', defaultPostFormat: { v2: true }, requestTimeout: 30, statusCheckURL: 'https://status.e621.church/json', userAgent: 'MyApp/1.0', userAgentInQuery: false }; ``` ``` -------------------------------- ### Example: error handling for get Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/popular.md Demonstrates catching UnexpectedResponseError when the server returns a non-200 status. Missing required date/scale is a compile-time error, but invalid values like 'not-a-date' cause runtime failures. ```typescript import E621 from "e621"; import { UnexpectedResponseError } from "e621"; const e621 = new E621(); try { // missing required `date`/`scale` is a compile-time error for the options type; // server-side failure still surfaces at runtime: await e621.popular.get({ date: "not-a-date", scale: "day" }); } catch (err) { if (err instanceof UnexpectedResponseError) { console.log(err.response?.status); // 422 / 400 depending on the API } } ``` -------------------------------- ### Initialize E621 client and perform basic operations Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/README.md Demonstrates how to initialize the E621 client with or without authentication, fetch posts, and handle potential errors using the UnexpectedResponseError class. ```typescript import E621 from "e621"; const e621 = new E621(); // no options required // authenticated — API key from Account -> Manage API Access const authed = new E621({ authUser: "username", authKey: "api-key" }); const post = await e621.posts.get(1234); // Post | null (legacy format by default) console.log(post?.id, post?.file?.url); const posts = await e621.posts.search({ tags: "canis_lupus_familiaris order:score" }); await posts[0]?.favorite(); // calls e621.favorites.create(id) // errors surface as UnexpectedResponseError (see ../errors.md) try { await e621.posts.get(1); // nonexistent post -> null (get uses throwOnNotFound=false) await e621.posts.count(""); // invalid tags -> 400 -> throws } catch (err) { console.log(err.name); // "UnexpectedResponseError" } ``` -------------------------------- ### Set default post format to v2 extended Source: https://github.com/donovandmc/e621/blob/dev/README.md Shows how to set the defaultPostFormat option to use the v2 extended format for all post-returning methods. Per-call options override the default. The example demonstrates getting a post and updating it, with the post typed as ExtendedPost. ```typescript const e621 = new E621({ defaultPostFormat: { v2: true, mode: "extended" } }); const post = await e621.posts.get(123); // ExtendedPost, typed accurately - no cast needed await post?.update({ tags: "foo" }); // also resolves to ExtendedPost // a per-call option still overrides the default for that one call const legacy = await e621.posts.get(123, { v2: false }); ``` -------------------------------- ### Configure E621 client with options Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/configuration.md Creates an E621 client instance with authentication, base URL for e926 mirror, default post format, user agent, request timeout, userAgentInQuery for browser context, and status check URL. Logs the resolved options. ```typescript import E621 from "e621"; const e621 = new E621({ authUser: "u", authKey: "k", baseURL: "https://e926.net", // e926 mirror defaultPostFormat: { v2: true, mode: "extended" }, userAgent: "my-app/1.0", requestTimeout: 60, userAgentInQuery: true, // e.g. in a browser context statusCheckURL: "https://status.e621.church/json", }); console.log(e621.options); // InstanceOptions (all resolved) ``` -------------------------------- ### Artists get method Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/artists.md Gets an artist by ID or name. Returns `null` on 404 (`throwOnNotFound=false`). Success status is 200. ```typescript @OperationID("artists#show") async get(idOrName: number | string): Promise ``` -------------------------------- ### Client configuration interfaces Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/types.md Defines the options for client initialization and the resulting instance configuration. ```typescript export interface Options { authKey?: string; authUser?: string; baseURL?: string; defaultPostFormat?: PF; requestTimeout?: number; statusCheckURL?: string; userAgent?: string; userAgentInQuery?: boolean; } export interface InstanceOptions { authKey: string | null; authUser: string | null; baseURL: string; requestTimeout: number; statusCheckURL: string; userAgent: string; userAgentInQuery: boolean; } export interface E621ClientResult { client: Client; options: InstanceOptions; } ``` -------------------------------- ### Basic construction with createE621Client Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/client.md Basic construction of the E621 client with authentication credentials. Shows the resolved options, including the default baseURL, the userAgent string that includes the auth user, and that userAgentInQuery is false in Node. ```typescript import { createE621Client } from "e621/standalone"; const { client, options } = createE621Client({ authUser: "someone", authKey: "key", }); console.log(options.baseURL); // "https://e621.net" console.log(options.userAgent); // 'E621/3.1.0 (+https://github.com/DonovanDMC/E621; "someone")' console.log(options.userAgentInQuery); // false in Node ``` -------------------------------- ### Popular get method signature Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/popular.md Defines the get method for the popular#index operation. It accepts optional query options and returns a promise of an array of PostFormat. Throws UnexpectedResponseError on non-200 responses. ```typescript @OperationID("popular#index") async get(options?: O): Promise>> ``` -------------------------------- ### Popular get method body Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/popular.md The exact implementation of the get method. It resolves v2 and mode from options or defaultFormat, calls popular_index, handles the response, unwraps legacy posts, and wraps each post with wrapPosts. ```typescript const v2 = options?.v2 ?? this.defaultFormat.v2; const mode = options?.mode ?? this.defaultFormat.mode; return popular_index({ client: this.client, query: { ...options, v2, mode }, }).then((res) => { const data = this._handleResponse(res, 200, true); const raw = (v2 ? data : (data as { posts: Array }).posts) as Array; return wrapPosts(this.e621, raw, v2, mode) as Array>; }); ``` -------------------------------- ### Using convenience methods Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/base-model.md Shows how model instances provide convenience methods that interact with the owning client. ```typescript import E621 from "e621"; const e621 = new E621({ authUser: "u", authKey: "k" }); const post = await e621.posts.random(); await post.favorite(); // e621.favorites.create(this.id) await post.createVote(1); // e621.postVotes.create(this.id, 1) await post.update({ tags: "new_tags" }); // e621.posts.update(this.id, …) ``` -------------------------------- ### Basic Post Usage Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/post-actions.md Demonstrates initializing the E621 client and performing common actions like favoriting, voting, and editing a post. ```typescript import E621 from "e621"; const e621 = new E621({ authUser: "u", authKey: "k" }); const post = await e621.posts.get(1234); if (post) { await post.favorite(); // favorite it await post.createVote(1); // upvote (post_votes#create) await post.update({ tag_string: "new_tag" }); // edit console.log(post.tag_string); // model fields are assigned from payload } ``` -------------------------------- ### get method Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/posts.md Retrieves a post by ID with optional formatting parameters. ```typescript async get(id: number, options?: O): Promise | null> ``` -------------------------------- ### Direct SDK usage with Generated.SDK namespace Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/generated-sdk.md Demonstrates importing from the main package and the generated subpath, then calling posts_show with a client and casting the response to LegacyPost. ```typescript import { Generated } from "e621"; import { posts_count } from "e621/generated/sdk"; import { createE621Client } from "e621/standalone"; const { client } = createE621Client(); const res = await Generated.SDK.posts_show({ client, path: { id: 1234 } }); if (res.data) { const legacy = res.data as { post: import("e621/generated/types").LegacyPost }; console.log(legacy.post.id); } ``` -------------------------------- ### Create raw client with Generated.Client.createClient Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/configuration.md Creates a raw client using the Generated module, setting base URL, throwOnError, and responseStyle. Then configures parseAs to json. ```typescript import { Generated } from "e621"; const client = Generated.Client.createClient({ baseUrl: "https://e621.net", throwOnError: true, responseStyle: "data", }); client.setConfig({ parseAs: "json" }); ``` -------------------------------- ### GET /stats.json Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/endpoints.md Retrieves statistics. This endpoint returns overall statistics for the site. ```APIDOC ## GET /stats.json ### Description Retrieves statistics. ### Method GET ### Endpoint /stats.json ``` -------------------------------- ### Construct E621 instance with options Source: https://github.com/donovandmc/e621/blob/dev/README.md Shows how to import and instantiate the E621 class. Options are optional and can include authUser and authKey. All submodules are accessed from this main class. ```typescript import E621 from "e621"; // or const E621 = require("e621"); // no options are required, see https://js.e621.wiki/latest/interfaces/Options.html for the options const e621 = new E621(); // the options are all an object in the first parameter, e.g. const e621 = new E621({ authUser: "", authKey: "" }); // all of the available modules stem from this main class, // e.g. use e621.posts.METHOD(), e621.users.METHOD() ``` -------------------------------- ### GET /staff/wikis.json Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/endpoints.md Retrieves a list of staff wikis. This endpoint returns all wikis. ```APIDOC ## GET /staff/wikis.json ### Description Retrieves a list of staff wikis. ### Method GET ### Endpoint /staff/wikis.json ``` -------------------------------- ### uploads#show Method Signature Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/uploads.md The get method retrieves an upload by its ID. ```typescript @OperationID("uploads#show") async get(id: number): Promise ``` -------------------------------- ### E621 Constructor Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/E621.md Creates a new E621 client instance with the provided options. The type parameter PF is inferred from the defaultPostFormat option and threads through all post-returning methods. ```APIDOC ## E621 Constructor ### Description Creates a new E621 client instance. The constructor initializes the client and options, and applies the default post format to all modules. ### Method constructor ### Signature constructor(options?: Options) ### Parameters - **options** (Options) - Optional - Configuration options for the client, including defaultPostFormat. ### Example ```typescript const e621 = new E621({ defaultPostFormat: 'v2' }); ``` ``` -------------------------------- ### sequence Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/posts.md Gets the post at a given id in its upload sequence, including the sequence number. ```APIDOC ## sequence ### Description Gets the post at a given id in its upload sequence, including the sequence number. ### Method GET ### Endpoint /posts/{id}/show_seq.json ### Parameters #### Path Parameters - **id** (number) - Required - The post id. ### Response #### Success Response (200) - **post** (PostFormat) - The post with sequence information. #### Response Example { "post": {} } ``` -------------------------------- ### Create client with interceptors Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/generated-client.md Demonstrates creating a client with a custom base URL and adding a request interceptor to log outgoing requests. ```typescript import E621, { Generated } from "e621"; // the default generated client shares the module-level config const client = Generated.Client.createClient({ baseUrl: "https://e926.net" }); client.interceptors.request.use((request) => { console.log(">>", request.method, request.url); return request; }); // raw typed call — fields style, no throw const res = await client.get({ url: "/posts/1234.json" }); if (res.data) console.log(res.data); ``` -------------------------------- ### GET /tag_aliases.json Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/endpoints.md Retrieves a list of tag aliases. This endpoint returns all tag aliases. ```APIDOC ## GET /tag_aliases.json ### Description Retrieves a list of tag aliases. ### Method GET ### Endpoint /tag_aliases.json ``` -------------------------------- ### Posts Module Constructor Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/posts.md Creates a new Posts module instance. The constructor accepts an optional owning E621 client, a generated fetch client, and a default format for post-returning methods. ```APIDOC ## Posts Module Constructor ### Description Creates a new Posts module instance. The constructor accepts an optional owning E621 client, a generated fetch client, and a default format for post-returning methods. ### Method constructor ### Signature ```typescript constructor(e621: E621 | undefined, client: Client, defaultFormat: PF = {} as PF) ``` ### Parameters - `e621` (E621 | undefined) - Required - Owning client (`undefined` for standalone construction) - `client` (Client) - Required - Generated fetch client - `defaultFormat` (PF) - Optional - `v2`/`mode` fallback for methods called without explicit format options. Default: `{}` (legacy) ``` -------------------------------- ### GET /staff/post/disapprovals.json Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/endpoints.md Retrieves a list of staff post disapprovals. This endpoint returns all disapprovals. ```APIDOC ## GET /staff/post/disapprovals.json ### Description Retrieves a list of staff post disapprovals. ### Method GET ### Endpoint /staff/post/disapprovals.json ``` -------------------------------- ### recommendedByTags(options?) Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/post-actions.md Gets post recommendations by tags. Delegates to e621.postRecommendations.tags. Returns a RecommendedPostsResult. ```APIDOC ## recommendedByTags(options?) ### Description Gets post recommendations by tags. Delegates to `e621.postRecommendations.tags`. Returns a RecommendedPostsResult. ### Method GET ### Endpoint `e621.postRecommendations.tags` ### Parameters - **options** (`RecommendedPostsOptions`) - Optional - The recommendation options. ### Response Returns a `RecommendedPostsResult`. ``` -------------------------------- ### recommendedByArtist(options?) Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/post-actions.md Gets post recommendations by artist. Delegates to e621.postRecommendations.artist. Returns a RecommendedPostsResult. ```APIDOC ## recommendedByArtist(options?) ### Description Gets post recommendations by artist. Delegates to `e621.postRecommendations.artist`. Returns a RecommendedPostsResult. ### Method GET ### Endpoint `e621.postRecommendations.artist` ### Parameters - **options** (`RecommendedPostsOptions`) - Optional - The recommendation options. ### Response Returns a `RecommendedPostsResult`. ``` -------------------------------- ### previousOwners() Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/post-actions.md Gets the previous owners of the post. Delegates to e621.staff.posts.previousOwners. Returns an array of PostPreviousOwner. ```APIDOC ## previousOwners() ### Description Gets the previous owners of the post. Delegates to `e621.staff.posts.previousOwners`. Returns an array of PostPreviousOwner. ### Method GET ### Endpoint `e621.staff.posts.previousOwners` ### Parameters None. ### Response Returns an array of `PostPreviousOwner`. ``` -------------------------------- ### Practical usage with a client Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/generated-sdk.md Shows importing functions from the generated subpath and using posts_show with a client, noting that posts_search does not exist and posts_index should be used instead. ```typescript import { createE621Client } from "e621/standalone"; import { posts_show, posts_search /* does not exist; see posts_index */, posts_index } from "e621/generated"; const { client } = createE621Client(); const res = await posts_show({ client, path: { id: 1234 } }); // fields style result if (res.data) { const legacy = res.data as { post: import("e621/generated/types").LegacyPost }; console.log(legacy.post.id); } ``` -------------------------------- ### GET /staff/wiki_versions.json Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/endpoints.md Retrieves a list of staff wiki versions. This endpoint returns all wiki versions. ```APIDOC ## GET /staff/wiki_versions.json ### Description Retrieves a list of staff wiki versions. ### Method GET ### Endpoint /staff/wiki_versions.json ``` -------------------------------- ### Standalone Build Module Configuration Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/post-actions.md Illustrates how to create a standalone build with specific modules and the resulting error when a required module is missing. ```typescript import Posts from "e621/modules/Posts"; import { createStandalone } from "e621/standalone"; const e621 = createStandalone([Posts]); const post = await e621.posts.get(1234); try { await post?.favorite(); } catch (err) { console.log(err); // TypeError — e621.favorites is not defined } ``` -------------------------------- ### GET /staff/vote_trends.json Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/endpoints.md Retrieves staff vote trends. This endpoint returns the vote trends data. ```APIDOC ## GET /staff/vote_trends.json ### Description Retrieves staff vote trends. ### Method GET ### Endpoint /staff/vote_trends.json ``` -------------------------------- ### post method signature for iqdb_queries#show_post Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/iqdb.md Defines the post method that queries IQDB by post ID. Options include post_id and other spec body keys, plus optional v2 merged into the query. Returns an array of IqdbResult. ```typescript @OperationID("iqdb_queries#show_post") async post(options?: O): Promise>> ``` -------------------------------- ### GET /staff/user_alts.json Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/endpoints.md Retrieves staff user alts. This endpoint returns the alternate accounts for a user. ```APIDOC ## GET /staff/user_alts.json ### Description Retrieves staff user alts. ### Method GET ### Endpoint /staff/user_alts.json ``` -------------------------------- ### GET /staff_notes.json Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/endpoints.md Retrieves a list of staff notes. This endpoint returns all staff notes available. ```APIDOC ## GET /staff_notes.json ### Description Retrieves a list of staff notes. ### Method GET ### Endpoint /staff_notes.json ``` -------------------------------- ### PostsShowData request-shape type Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/types.md Example of a request-shape type definition used to map API paths and parameters. ```typescript export type PostsShowData = { body?: never; path: { id: number; }; query?: { v2?: boolean; mode?: 'basic' | 'extended' | 'thumbnail'; }; url: '/posts/{id}.json'; }; ``` -------------------------------- ### apply() Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/modules.md Attaches all 90 modules to an E621 instance. It is called by the E621 constructor and assigns each module to the instance via Object.assign. ```APIDOC ## apply() ### Description Constructs all 90 modules and attaches them to the E621 instance via Object.assign. Invoked by the E621 constructor; the standalone path instantiates modules directly instead. ### Signature ```typescript export function apply(e621: E621, client: Client, defaultPostFormat: PF = {} as PF): void ``` ### Parameters - `e621` (E621) - Required - Instance to attach modules to (must already have `client`/`options`) - `client` (Client) - Required - Generated fetch client - `defaultPostFormat` (PF) - Optional, default `{}` - Default `v2`/`mode` passed to the five format-aware module constructors ### Returns `void` ``` -------------------------------- ### Catching UnexpectedResponseError Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/errors.md Example of how to catch and inspect the UnexpectedResponseError, including accessing the response status and error body. ```typescript import E621, { UnexpectedResponseError } from "e621"; const e621 = new E621(); try { await e621.posts.count(""); // 400 -> throws } catch (err) { if (err instanceof UnexpectedResponseError) { const status = err.response?.status; // 400 const body = err.error; // parsed JSON payload console.log(err.message); } else { throw err; } } ``` -------------------------------- ### Build URLs with path and query parameters Source: https://github.com/donovandmc/e621/blob/dev/_autodocs/api-reference/generated-client.md Shows how to use the buildUrl method to construct API URLs with dynamic path segments and query strings. ```typescript import E621, { Generated } from "e621"; const client = Generated.Client.createClient(); const url = client.buildUrl({ url: "/posts/{id}.json", path: { id: 5 }, query: { limit: 10 } }); console.log(url); // https://e621.net/posts/5.json?limit=10 ```