### Installation Source: https://tumblr.github.io/tumblr.js/index Install the tumblr.js package from npm. ```APIDOC ## Installation Install this package from npm: ```bash npm install --save tumblr.js ``` ``` -------------------------------- ### Install tumblr.js using npm Source: https://tumblr.github.io/tumblr.js/index This command installs the tumblr.js library as a dependency for your project using npm. Ensure you have Node.js and npm installed on your system. ```bash npm install --save tumblr.js ``` -------------------------------- ### Example Usage Source: https://tumblr.github.io/tumblr.js/index A simple example demonstrating how to fetch and log the names of a user's blogs. ```APIDOC ## Example ```javascript // Show user's blog names client.userInfo(function (err, data) { data.user.blogs.forEach(function (blog) { console.log(blog.name); }); }); ``` ``` -------------------------------- ### Supported Methods Overview Source: https://tumblr.github.io/tumblr.js/index Explains how to use supported methods with optional parameters and provides an example of fetching photo posts. ```APIDOC ## Supported Methods Below is a list of available methods and their purpose. Available options are documented in the API Docs and are specified as a JavaScript object. ```javascript const response = await client.blogPosts('blogName', { type: 'photo', tag: ['multiple', 'tags', 'likethis'], }); ``` In most cases, since options are optional (heh) they are also an optional argument, so there is no need to pass an empty object when supplying no options, like: ```javascript const response = await client.blogPosts('blogName'); ``` ``` -------------------------------- ### GET /v2/user/following Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Retrieves the blogs that the authenticating user follows. Supports optional query parameters for pagination. ```APIDOC ## GET /v2/user/following ### Description Retrieves the blogs that the authenticating user follows. Supports optional query parameters for pagination. ### Method GET ### Endpoint /v2/user/following ### Parameters #### Query Parameters - **paramsOrCallback** (TumblrClientCallback | { limit?: number; offset?: number }) - Optional - Query parameters for pagination (e.g., `limit`, `offset`). - **callback** (TumblrClientCallback) - Optional - Callback function (Deprecated, use promises instead). ### Request Example ```json { "paramsOrCallback": { "limit": 10, "offset": 0 } } ``` ### Response #### Success Response (200) - **any** - A list of blogs the user is following. #### Response Example ```json { "response": { "blogs": [ { "name": "followed-blog.tumblr.com", "url": "https://followed-blog.tumblr.com/" } ] } } ``` ``` -------------------------------- ### Usage in Node.js Source: https://tumblr.github.io/tumblr.js/index Provides examples of how to create a client instance in Node.js using either the `createClient` function or the `Client` constructor. ```APIDOC ## Usage in Node.js ```javascript const tumblr = require('tumblr.js'); // Using createClient const client = tumblr.createClient({ consumer_key: '', consumer_secret: '', token: '', token_secret: '', }); // Using the Client constructor const client = new tumblr.Client({ // ... }); ``` The request methods will return promises. The callback form is considered deprecated and should not be used. ``` -------------------------------- ### Perform GET Request - JavaScript Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Performs a generic GET request to a specified API path. It can include query parameters. It returns a Promise if no callback is provided. ```javascript /** * Performs a GET request * @param {string} apiPath - URL path for the request * @param {Record | TumblrClientCallback} paramsOrCallback - query parameters * @param {function} callback - Deprecated. Omit the callback and use the promise form * @returns {Promise | undefined} */ getRequest(apiPath, paramsOrCallback, callback) ``` -------------------------------- ### Media Object Type Example Source: https://tumblr.github.io/tumblr.js/interfaces/types.MediaObject An example of the 'type' property within a MediaObject, specifying the MIME type of the media asset. This helps in identifying the format of the linked media. ```json "image/jpg" ``` -------------------------------- ### PaywallBlock Properties Example (TypeScript) Source: https://tumblr.github.io/tumblr.js/interfaces/types.PaywallBlock Illustrates the properties of the PaywallBlock interface, specifically highlighting the 'type' property which is fixed to the string literal 'paywall'. This demonstrates how to define and access this property. ```typescript ### Properties type ## Properties ### type type: "paywall" ``` -------------------------------- ### Get Request API Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Performs a generic GET request to a specified API path. Useful for endpoints not directly exposed by the client. ```APIDOC ## GET /{apiPath} ### Description Performs a GET request. ### Method GET ### Endpoint /{apiPath} ### Parameters #### Path Parameters - **apiPath** (string) - Required - URL path for the request. #### Query Parameters - **paramsOrCallback** (Record) - Optional - Query parameters for the request. ### Response #### Success Response (200) - **data** (any) - The response data from the API. #### Response Example { "example": "{ ... API response data ... }" } ``` -------------------------------- ### Get Blog Information (JavaScript) Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Fetches general information about a specific blog. Requires a blog identifier and can accept query parameters, such as fields to include. Returns a Promise or undefined. ```javascript client.blogInfo('example-blog.tumblr.com', { 'fields[blogs]': 'title,posts' }).then(response => { console.log(response.blog); }); ``` -------------------------------- ### Get Blogs Authenticating User Follows Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Fetches a list of blogs that the authenticated user is following. It supports optional query parameters like limit and offset, and an optional callback. Promises are preferred. ```typescript /** * Gets the blogs the authenticating user follows. * @param paramsOrCallback Optional query parameters or callback. * @param callback Optional callback function (deprecated). * @returns Promise | undefined - A Promise if no callback is provided. */ userFollowing(paramsOrCallback?: TumblrClientCallback | { limit?: number; offset?: number }, callback?: TumblrClientCallback): Promise | undefined; ``` -------------------------------- ### Get Authenticating User's Information Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Retrieves information about the authenticated user and their associated blogs. It accepts an optional callback, but Promises are the recommended way to handle the response. ```typescript /** * Gets information about the authenticating user and their blogs. * @param callback Optional callback function (deprecated). * @returns Promise | undefined - A Promise if no callback is provided. */ userInfo(callback?: TumblrClientCallback): Promise | undefined; ``` -------------------------------- ### GET /v2/user/info Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Retrieves information about the authenticating user and their blogs. This endpoint does not require any parameters. ```APIDOC ## GET /v2/user/info ### Description Retrieves information about the authenticating user and their blogs. This endpoint does not require any parameters. ### Method GET ### Endpoint /v2/user/info ### Parameters #### Query Parameters - **callback** (TumblrClientCallback) - Optional - Callback function (Deprecated, use promises instead). ### Request Example ```json { "callback": null } ``` ### Response #### Success Response (200) - **any** - User information including name, email, and blog details. #### Response Example ```json { "response": { "user": { "name": "authenticated_user", "blogs": [ { "name": "user-blog.tumblr.com", "title": "User's Blog" } ] } } } ``` ``` -------------------------------- ### GET /v2/user/likes Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Retrieves the likes made by the authenticating user. Supports optional query parameters for pagination. ```APIDOC ## GET /v2/user/likes ### Description Retrieves the likes made by the authenticating user. Supports optional query parameters for pagination. ### Method GET ### Endpoint /v2/user/likes ### Parameters #### Query Parameters - **paramsOrCallback** (TumblrClientCallback | { after?: number; before?: number; limit?: number; offset?: number }) - Optional - Query parameters for pagination and filtering (e.g., `limit`, `offset`, `before`, `after`). - **callback** (TumblrClientCallback) - Optional - Callback function (Deprecated, use promises instead). ### Request Example ```json { "paramsOrCallback": { "limit": 10, "offset": 0 } } ``` ### Response #### Success Response (200) - **any** - A list of posts liked by the user. #### Response Example ```json { "response": { "liked_posts": [ { "type": "photo", "blog_name": "liked-post-blog.tumblr.com" } ] } } ``` ``` -------------------------------- ### Get Blog Queue (JavaScript) Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Fetches posts currently in a blog's queue. Requires a blog identifier and can accept parameters for filtering and pagination. Returns a Promise or undefined. ```javascript client.blogQueue('example-blog.tumblr.com', { filter: 'raw' }).then(response => { console.log(response.posts); }); ``` -------------------------------- ### Get Blog Likes (JavaScript) Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Retrieves the posts that a blog has liked. Requires a blog identifier and supports optional parameters for pagination and filtering by date. Returns a Promise or undefined. ```javascript client.blogLikes('example-blog.tumblr.com', { limit: 5 }).then(response => { console.log(response.liked_posts); }); ``` -------------------------------- ### Get Blog Followers (JavaScript) Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Retrieves a list of followers for a specified blog. Accepts a blog identifier and optional pagination parameters (`limit`, `offset`). Returns a Promise or undefined. ```javascript client.blogFollowers('example-blog.tumblr.com', { limit: 10 }).then(response => { console.log(response.users); }); ``` -------------------------------- ### Post Methods Source: https://tumblr.github.io/tumblr.js/index Covers methods for creating, editing, and deleting posts, including an example of creating a post with image media. ```APIDOC ### Post Methods #### Create a post with `createPost` ```javascript await client.createPost(blogName, options); ``` To upload media with a created post, provide a `ReadStream` as the block media: ```javascript await client.createPost(blogName, { content: [ { type: 'image', // Node's fs module, e.g. `import fs from 'node:fs';` media: fs.createReadStream(new URL('./image.jpg', import.meta.url)), alt_text: '…', }, ], }); ``` #### Edit a post with `editPost` ```javascript await client.editPost(blogName, postId, options); ``` #### Delete a post with `deletePost` ```javascript await client.deletePost(blogName, postId); ``` ``` -------------------------------- ### GET /v2/user/dashboard Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Retrieves the dashboard posts for the authenticating user. Supports optional query parameters. ```APIDOC ## GET /v2/user/dashboard ### Description Retrieves the dashboard posts for the authenticating user. Supports optional query parameters. ### Method GET ### Endpoint /v2/user/dashboard ### Parameters #### Query Parameters - **paramsOrCallback** (Record | TumblrClientCallback) - Optional - Query parameters for filtering and pagination. - **callback** (TumblrClientCallback) - Optional - Callback function (Deprecated, use promises instead). ### Request Example ```json { "paramsOrCallback": { "limit": 20, "offset": 0 } } ``` ### Response #### Success Response (200) - **any** - A list of posts from the user's dashboard. #### Response Example ```json { "response": { "posts": [ { "type": "text", "blog_name": "friend.tumblr.com" } ] } } ``` ``` -------------------------------- ### Fetch user's blog names using tumblr.js Source: https://tumblr.github.io/tumblr.js/index An example of how to fetch and display the names of blogs associated with the authenticated user using the tumblr.js client. This method returns a promise that resolves with user data. ```javascript // Show user's blog names client.userInfo(function (err, data) { data.user.blogs.forEach(function (blog) { console.log(blog.name); }); }); ``` -------------------------------- ### Get Blog Drafts (JavaScript) Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Fetches the drafts for a given blog. Requires a blog identifier and can accept optional parameters like `before_id` or `filter`. Returns a Promise or undefined. ```javascript client.blogDrafts('example-blog.tumblr.com', { filter: 'text' }).then(response => { console.log(response.posts); }); ``` -------------------------------- ### GET /v2/tagged Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Retrieves posts tagged with a specific tag. Supports optional query parameters for filtering and pagination. ```APIDOC ## GET /v2/tagged ### Description Retrieves posts tagged with a specific tag. Supports optional query parameters for filtering and pagination. ### Method GET ### Endpoint /v2/tagged ### Parameters #### Query Parameters - **tag** (string) - Required - The tag on the posts you'd like to retrieve. - **paramsOrCallback** (Record | TumblrClientCallback) - Optional - Query parameters for filtering and pagination (e.g., `limit`, `before`, `after`). - **callback** (TumblrClientCallback) - Optional - Callback function (Deprecated, use promises instead). ### Request Example ```json { "tag": "javascript", "paramsOrCallback": { "limit": 10, "before": 1678886400 } } ``` ### Response #### Success Response (200) - **any** - A list of posts matching the specified tag. #### Response Example ```json { "response": { "posts": [ { "type": "photo", "tags": ["javascript", "webdev"] } ] } } ``` ``` -------------------------------- ### Get Blog Submissions - JavaScript Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Retrieves submissions for a given blog. It accepts a blog identifier and optional parameters for filtering or pagination. It returns a Promise if no callback is provided. ```javascript /** * Gets the submissions for a blog * @param {string} blogIdentifier - blog name or URL * @param {object | TumblrClientCallback} paramsOrCallback - optional data sent with the request * @param {function} callback - Deprecated. Omit the callback and use the promise form * @returns {Promise | undefined} */ blogSubmissions(blogIdentifier, paramsOrCallback, callback) ``` -------------------------------- ### Get Authenticating User's Dashboard Posts Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Retrieves the dashboard posts for the authenticated user. It accepts optional query parameters and a callback. Using Promises is the recommended approach. ```typescript /** * Gets the dashboard posts for the authenticating user. * @param paramsOrCallback Optional query parameters or callback. * @param callback Optional callback function (deprecated). * @returns Promise | undefined - A Promise if no callback is provided. */ userDashboard(paramsOrCallback?: Record | TumblrClientCallback, callback?: TumblrClientCallback): Promise | undefined; ``` -------------------------------- ### Arbitrary Request Methods Source: https://tumblr.github.io/tumblr.js/index Allows making arbitrary GET, POST, and PUT requests to the API. ```APIDOC ## GET /{apiPath} ### Description Makes an arbitrary GET request to the specified API path. ### Method GET ### Endpoint /{apiPath} ### Parameters #### Path Parameters - **apiPath** (string) - Required - The API path to make the GET request to. #### Query Parameters - **params** (object) - Optional - Parameters to include in the GET request. ### Request Example ```json { "example": "client.getRequest(apiPath, params);" } ``` ### Response #### Success Response (200) - **data** (any) - The response data from the API. #### Response Example ```json { "example": "Response data from GET request." } ``` ## POST /{apiPath} ### Description Makes an arbitrary POST request to the specified API path. ### Method POST ### Endpoint /{apiPath} ### Parameters #### Path Parameters - **apiPath** (string) - Required - The API path to make the POST request to. #### Query Parameters - **params** (object) - Optional - Parameters to include in the POST request. ### Request Example ```json { "example": "client.postRequest(apiPath, params);" } ``` ### Response #### Success Response (200) - **data** (any) - The response data from the API. #### Response Example ```json { "example": "Response data from POST request." } ``` ## PUT /{apiPath} ### Description Makes an arbitrary PUT request to the specified API path. ### Method PUT ### Endpoint /{apiPath} ### Parameters #### Path Parameters - **apiPath** (string) - Required - The API path to make the PUT request to. #### Query Parameters - **params** (object) - Optional - Parameters to include in the PUT request. ### Request Example ```json { "example": "client.putRequest(apiPath, params);" } ``` ### Response #### Success Response (200) - **data** (any) - The response data from the API. #### Response Example ```json { "example": "Response data from PUT request." } ``` ``` -------------------------------- ### Get Authenticating User's Likes Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Fetches the posts that the authenticated user has liked. It supports optional query parameters for pagination and an optional callback. Promises are the preferred method for handling results. ```typescript /** * Gets the likes for the authenticating user. * @param paramsOrCallback Optional query parameters or callback. * @param callback Optional callback function (deprecated). * @returns Promise | undefined - A Promise if no callback is provided. */ userLikes(paramsOrCallback?: TumblrClientCallback | { after?: number; before?: number; limit?: number; offset?: number }, callback?: TumblrClientCallback): Promise | undefined; ``` -------------------------------- ### Tumblr API User Methods in Node.js Source: https://tumblr.github.io/tumblr.js/index Provides examples of various user-related operations using the tumblr.js client in Node.js. These include fetching user info, dashboard, likes, followings, and managing follows/likes. All methods return promises. ```javascript // Get information about the authenticating user & their blogs const userInfo = await client.userInfo(); // Get dashboard for authenticating user const userDashboard = await client.userDashboard(options); // Get likes for authenticating user const userLikes = await client.userLikes(options); // Get followings for authenticating user const userFollowing = await client.userFollowing(options); // Follow or unfollow a given blog await client.followBlog(blogURL); await client.unfollowBlog(blogURL); // Like or unlike a given post await client.likePost(postId, reblogKey); await client.unlikePost(postId, reblogKey); ``` -------------------------------- ### Tumblr API Post Management in Node.js Source: https://tumblr.github.io/tumblr.js/index Provides examples for managing posts on Tumblr using the tumblr.js client in Node.js. This includes creating, editing, and deleting posts. These operations return promises. ```javascript await client.createPost(blogName, options); await client.editPost(blogName, postId, options); await client.deletePost(blogName, postId); ``` -------------------------------- ### Get Blog Avatar URL (JavaScript) Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Retrieves the avatar URL for a specified blog. Accepts a blog identifier (name or URL) and an optional size or callback. Returns a Promise or undefined. ```javascript client.blogAvatar('example-blog.tumblr.com', 128).then(response => { console.log(response.avatar_url); }); ``` -------------------------------- ### Tumblr JS API - Get Blog Posts Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client This method retrieves posts from a Tumblr blog. It supports various query parameters for filtering and pagination. It can be used with either a callback function or as a Promise. ```APIDOC ## GET /blog/{blog-name}/posts ### Description Retrieves posts from a specified Tumblr blog. Supports filtering and pagination via query parameters. Can be used with a callback or as a Promise. ### Method GET ### Endpoint /blog/{blog-name}/posts ### Parameters #### Query Parameters - **after** (number) - Optional - Returns posts published after this date (Unix timestamp). - **before** (number) - Optional - Returns posts published before this date (Unix timestamp). - **limit** (number) - Optional - The number of posts to return. - **offset** (number) - Optional - The note offset to retrieve. ### Request Example ``` // Using Promises client.get('/blog/example-blog/posts', { limit: 5 }) .then(response => { console.log(response.posts); }) .catch(error => { console.error(error); }); // Using callbacks (Deprecated) client.get('/blog/example-blog/posts', { limit: 5 }, (error, response) => { if (error) { console.error(error); } else { console.log(response.posts); } }); ``` ### Response #### Success Response (200) - **posts** (array) - An array of post objects. - **total_posts** (number) - The total number of posts available for the blog. #### Response Example ```json { "posts": [ { "type": "text", "title": "My First Post", "body": "This is the body of my first post." } ], "total_posts": 100 } ``` ``` -------------------------------- ### Initialize Tumblr API Client (JavaScript) Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Creates a new instance of the Tumblr API client. Requires an options object for configuration. This is the entry point for all API interactions. ```javascript import Client from 'tumblr.js'; const client = new Client({ consumerKey: 'YOUR_CONSUMER_KEY', consumerSecret: 'YOUR_CONSUMER_SECRET', accessToken: 'YOUR_ACCESS_TOKEN', accessSecret: 'YOUR_ACCESS_SECRET' }); ``` -------------------------------- ### Create Tumblr Client with tumblr.js Source: https://tumblr.github.io/tumblr.js/functions/tumblr.createClient Instantiates a Tumblr client using the `createClient` function from the tumblr.js library. This function accepts an optional configuration object for client options and returns a Client instance. ```javascript import tumblr from 'tumblr.js'; const client = tumblr.createClient({ consumerKey: 'YOUR_CONSUMER_KEY', consumerSecret: 'YOUR_CONSUMER_SECRET', accessToken: 'YOUR_ACCESS_TOKEN', accessTokenSecret: 'YOUR_ACCESS_TOKEN_SECRET' }); ``` -------------------------------- ### Follow Blog - JavaScript Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Allows the authenticating user to follow a blog. It accepts parameters specifying the blog's URL or email. It returns a Promise if no callback is provided. ```javascript /** * Follows a blog as the authenticating user * @param {{ url: string } | { email: string }} params - parameters sent with the request * @param {function} callback - Deprecated. Omit the callback and use the promise form * @returns {Promise | undefined} */ followBlog(params, callback) ``` -------------------------------- ### Blog Methods Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Methods for retrieving information and content related to a specific blog. ```APIDOC ## Methods ### blogAvatar #### Description Gets the avatar URL for a blog. #### Method `GET` #### Endpoint `/blog/{blogIdentifier}/avatar` #### Parameters ##### Path Parameters * **blogIdentifier** (string) - Required - Blog name or URL. ##### Query Parameters * **sizeOrCallback** (TumblrClientCallback | 16 | 24 | 30 | 40 | 48 | 64 | 96 | 128 | 512) - Optional - Optional data sent with the request. * **maybeCallback** (TumblrClientCallback) - Optional - Invoked when the request completes. #### Returns * `Promise | undefined` - Promise if no callback is provided. ### blogDrafts #### Description Gets the drafts for a blog. #### Method `GET` #### Endpoint `/blog/{blogIdentifier}/drafts` #### Parameters ##### Path Parameters * **blogIdentifier** (string) - Required - Blog name or URL. ##### Query Parameters * **paramsOrCallback** (TumblrClientCallback | { before_id?: number; filter?: PostFormatFilter }) - Optional - Optional data sent with the request. * **callback** (TumblrClientCallback) - Optional - Deprecated. Omit the callback and use the promise form. #### Returns * `Promise | undefined` - Promise if no callback is provided. ### blogFollowers #### Description Gets the followers for a blog. #### Method `GET` #### Endpoint `/blog/{blogIdentifier}/followers` #### Parameters ##### Path Parameters * **blogIdentifier** (string) - Required - Blog name or URL. ##### Query Parameters * **paramsOrCallback** (TumblrClientCallback | { limit?: number; offset?: number }) - Optional - Optional data sent with the request. * **callback** (TumblrClientCallback) - Optional - Deprecated. Omit the callback and use the promise form. #### Returns * `Promise | undefined` - Promise if no callback is provided. ### blogInfo #### Description Gets information about a given blog. #### Method `GET` #### Endpoint `/blog/{blogIdentifier}/info` #### Parameters ##### Path Parameters * **blogIdentifier** (string) - Required - Blog name or URL. ##### Query Parameters * **paramsOrCallback** (TumblrClientCallback | { "fields[blogs]"?: string }) - Optional - Query parameters. * **callback** (TumblrClientCallback) - Optional - Deprecated. Omit the callback and use the promise form. #### Returns * `Promise | undefined` - Promise if no callback is provided. ### blogLikes #### Description Gets the likes for a blog. #### Method `GET` #### Endpoint `/blog/{blogIdentifier}/likes` #### Parameters ##### Path Parameters * **blogIdentifier** (string) - Required - Blog name or URL. ##### Query Parameters * **paramsOrCallback** (TumblrClientCallback | { after?: number; before?: number; limit?: number; offset?: number }) - Optional - Optional data sent with the request. * **callback** (TumblrClientCallback) - Optional - Deprecated. Omit the callback and use the promise form. #### Returns * `Promise | undefined` - Promise if no callback is provided. ### blogQueue #### Description Gets the queue for a blog. #### Method `GET` #### Endpoint `/blog/{blogIdentifier}/posts` (for queue items) #### Parameters ##### Path Parameters * **blogIdentifier** (string) - Required - Blog name or URL. ##### Query Parameters * **paramsOrCallback** (TumblrClientCallback | { filter?: "text" | "raw"; limit?: number; offset?: number }) - Optional - Optional data sent with the request. * **callback** (TumblrClientCallback) - Optional - Deprecated. Omit the callback and use the promise form. #### Returns * `Promise | undefined` - Promise if no callback is provided. ``` -------------------------------- ### Create Post API Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Creates or reblogs a Next-Platform-First (NPF) post. This is the recommended method for creating posts. ```APIDOC ## POST /posts ### Description Create or reblog an NPF post. ### Method POST ### Endpoint /posts ### Parameters #### Path Parameters - **blogIdentifier** (string) - Required - blog name or URL #### Request Body - **params** (NpfPostParams | NpfReblogParams) - Required - Parameters for creating or reblogging the post. ### Request Example ```json { "example": "{\n \"content\": [\n {\n \"type\": \"image\",\n \"media\": \"fs.createReadStream(...) \", // Node's fs module required\n \"alt_text\": \"An example image\"\n }\n ]\n}" } ``` ### Response #### Success Response (200) - **post** (object) - Details of the created or reblogged post. #### Response Example { "example": "{ \"id\": \"post_id\", ... }" } #### See API Docs ``` -------------------------------- ### createClient Function Source: https://tumblr.github.io/tumblr.js/functions/tumblr.createClient The createClient function is used to create an instance of the Tumblr client. It accepts an optional 'options' object for configuration. ```APIDOC ## Function createClient ### Description Creates a Tumblr Client instance. ### Method N/A (Function Signature) ### Endpoint N/A (Client Instantiation) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters #### `options` (Options) - Optional An object containing client configuration options. ### Returns Client - A new instance of the Tumblr Client. ### See Client ### Request Example ```javascript const client = tumblr.createClient({ consumerKey: 'YOUR_CONSUMER_KEY', consumerSecret: 'YOUR_CONSUMER_SECRET', accessToken: 'YOUR_ACCESS_TOKEN', accessTokenSecret: 'YOUR_ACCESS_TOKEN_SECRET' }); ``` ### Response #### Success Response (Client Instance) - **client** (Client) - An authenticated Tumblr client object. #### Response Example ```javascript // Assuming the client is successfully created and authenticated console.log(client); // Outputs the client object ``` ``` -------------------------------- ### Usage in the Browser Source: https://tumblr.github.io/tumblr.js/index Notes that due to CORS restrictions, this library is not intended for in-browser use, although GET endpoints support JSONP. ```APIDOC ## Usage in the Browser Due to CORS restrictions, you're going to have a really hard time using this library in the browser. Although GET endpoints on the Tumblr API support JSONP, this library is not intended for in-browser use. Sorry! ``` -------------------------------- ### Create Legacy Post - JavaScript Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Creates a legacy post on a given blog. This method is deprecated and users are advised to use NPF methods instead. It returns a Promise if no callback is provided. ```javascript /** * Creates a post on the given blog. * @param {string} blogIdentifier - blog name or URL * @param {Record} params - Post parameters * @param {function} callback - Deprecated. Omit the callback and use the promise form * @returns {Promise | undefined} */ createLegacyPost(blogIdentifier, params, callback) ``` -------------------------------- ### Create Legacy Post API Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Creates a legacy post on the given blog. Note: This method is deprecated and NPF methods should be used instead. ```APIDOC ## POST /posts ### Description Creates a post on the given blog. This is a legacy method. ### Method POST ### Endpoint /posts ### Parameters #### Path Parameters - **blogIdentifier** (string) - Required - blog name or URL #### Request Body - **params** (Record) - Required - Parameters for creating the post. ### Response #### Success Response (200) - **post** (object) - Details of the created post. #### Response Example { "example": "{ \"id\": \"post_id\", ... }" } #### Deprecated Legacy post creation methods are deprecated. Use NPF methods. ``` -------------------------------- ### Client Class Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client The Client class is the main entry point for interacting with the Tumblr API. It can be instantiated with options and provides methods for various API calls. ```APIDOC ## Class Client ### Description The Client class provides methods to interact with the Tumblr API. ### Constructor ```typescript new Client(options?: Options): Client ``` Creates a Tumblr API client using the given options. #### Parameters * `options` (Options) - Optional - Client options. #### Returns * `Client` - An instance of the Client class. ``` -------------------------------- ### Run Project Tests (Shell) Source: https://tumblr.github.io/tumblr.js/index Commands for executing tests, linting, and type checking within the project. These are standard npm scripts used for maintaining code quality and ensuring functionality. They are executed from the project's root directory. ```shell # Run tests npm run test # Lint npm run lint # Typecheck npm run typecheck ``` -------------------------------- ### Create a post with media using tumblr.js Source: https://tumblr.github.io/tumblr.js/index Demonstrates creating a new post on Tumblr using the `createPost` method, including uploading media like an image. This requires providing a `ReadStream` for the media content. The method returns a promise. ```javascript await client.createPost(blogName, { content: [ { type: 'image', // Node's fs module, e.g. `import fs from 'node:fs';` media: fs.createReadStream(new URL('./image.jpg', import.meta.url)), alt_text: '…', }, ], }); ``` -------------------------------- ### POST /api/request Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Performs a POST request to the specified API path. It supports optional parameters and a callback function, though using promises is recommended. ```APIDOC ## POST /api/request ### Description Performs a POST request to the specified API path. It supports optional parameters and a callback function, though using promises is recommended. ### Method POST ### Endpoint /api/request ### Parameters #### Path Parameters - **apiPath** (string) - Required - URL path for the request #### Query Parameters - **paramsOrCallback** (Record | TumblrClientCallback) - Optional - Parameters for the request or a callback function. - **callback** (TumblrClientCallback) - Optional - Callback function (Deprecated, use promises instead). ### Request Example ```json { "apiPath": "/v2/blog/example.tumblr.com/posts", "paramsOrCallback": { "api_key": "YOUR_API_KEY", "limit": 5 } } ``` ### Response #### Success Response (200) - **any** - The response from the API request. #### Response Example ```json { "response": { "blog": { "title": "Example Blog", "posts": [ { "type": "text", "title": "Example Post" } ] } } } ``` ``` -------------------------------- ### Follow Blog API Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Follows a blog as the authenticating user. You can specify the blog by its URL or email. ```APIDOC ## POST /user/follow ### Description Follows a blog as the authenticating user. ### Method POST ### Endpoint /user/follow ### Parameters #### Request Body - **params** ({ url: string } | { email: string }) - Required - Parameters specifying the blog to follow (either URL or email). ### Response #### Success Response (200) - **message** (string) - Confirmation message of following the blog. #### Response Example { "example": "Blog followed successfully." } ``` -------------------------------- ### Fetch blog posts without options using tumblr.js Source: https://tumblr.github.io/tumblr.js/index Demonstrates fetching all posts from a blog without applying any filters. This simplifies the call to `blogPosts` when no specific options are needed. The method returns a promise. ```javascript const response = await client.blogPosts('blogName'); ``` -------------------------------- ### Like Post API Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Likes a post as the authenticating user. Requires the post ID and its reblog key. ```APIDOC ## POST /user/like ### Description Likes a post as the authenticating user. ### Method POST ### Endpoint /user/like ### Parameters #### Request Body - **postId** (string) - Required - ID of post to like. - **reblogKey** (string) - Required - Reblog key of post to like. ### Response #### Success Response (200) - **message** (string) - Confirmation message of liking the post. #### Response Example { "example": "Post liked successfully." } ``` -------------------------------- ### Make Arbitrary HTTP Requests (JavaScript) Source: https://tumblr.github.io/tumblr.js/index Allows for making custom GET, POST, and PUT requests to the Tumblr API. This is useful for accessing endpoints not directly supported by the client library. It requires the API path and parameters as input. ```javascript client.getRequest(apiPath, params); client.postRequest(apiPath, params); client.putRequest(apiPath, params); ``` -------------------------------- ### Authenticate tumblr.js client in Node.js Source: https://tumblr.github.io/tumblr.js/index Demonstrates two ways to create an authenticated client instance for the tumblr.js library in a Node.js environment. This requires consumer keys and tokens obtained from the Tumblr API. ```javascript const tumblr = require('tumblr.js'); const client = tumblr.createClient({ consumer_key: '', consumer_secret: '', token: '', token_secret: '', }); ``` ```javascript const tumblr = require('tumblr.js'); const client = new tumblr.Client({ // ... }); ``` -------------------------------- ### Like Post - JavaScript Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Likes a post as the authenticating user. This function requires the post ID and its reblog key. It returns a Promise if no callback is provided. ```javascript /** * Likes a post as the authenticating user * @param {string} postId - ID of post to like * @param {string} reblogKey - Reblog key of post to like * @param {function} callback - Deprecated. Omit the callback and use the promise form * @returns {Promise | undefined} */ likePost(postId, reblogKey, callback) ``` -------------------------------- ### Create NPF Post - JavaScript Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Creates or reblogs a new NPF (New Post Format) post. This function requires a blog identifier and post parameters, supporting various content types like images. It returns a Promise if no callback is provided. ```javascript /** * Create or reblog an NPF post * @param {string} blogIdentifier - blog name or URL * @param {NpfPostParams | NpfReblogParams} params - Post parameters * @param {function} callback - Deprecated. Omit the callback and use the promise form * @returns {Promise | undefined} */ createPost(blogIdentifier, params, callback) // Example usage: await client.createPost(blogName, { content: [ { type: 'image', // Node's fs module, e.g. `import fs from 'node:fs';` media: fs.createReadStream(new URL('./image.jpg', import.meta.url)), alt_text: '…', }, ], }); ``` -------------------------------- ### Tumblr.js Interface Options (TypeScript) Source: https://tumblr.github.io/tumblr.js/interfaces/types.Options Defines the TypeScript interface for configuring Tumblr.js options. This includes optional parameters for base URL, OAuth credentials (consumer key/secret, token/secret), and promise return behavior. ```typescript interface Options { baseUrl?: string; consumer_key?: string; consumer_secret?: string; returnPromises?: boolean; token?: string; token_secret?: string; } ``` -------------------------------- ### BlogPostsParams Interface Source: https://tumblr.github.io/tumblr.js/interfaces/types.BlogPostsParams This section describes the parameters available for fetching blog posts using the tumblr.js library. These parameters allow for filtering by ID, limit, tags, post type, and inclusion of additional information like notes and reblog details. ```APIDOC ## BlogPostsParams ### Description Parameters for fetching blog posts. ### Method Not Applicable (Interface Definition) ### Endpoint Not Applicable (Interface Definition) ### Parameters #### Query Parameters - **id** (string) - Optional - A specific post ID. Returns the single post specified or (if not found) a 404 error. - **limit** (number) - Optional - The number of posts to return: 1–20, inclusive. - **notes_info** (boolean) - Optional - Indicates whether to return notes information (specify true or false). Returns note count and note metadata. - **npf** (boolean) - Optional - Returns posts' content in NPF format instead of the legacy format. See NPF documentation. - **offset** (number) - Optional - Offset post number (0 to start from first post). - **reblog_info** (boolean) - Optional - Indicates whether to return reblog information (specify true or false). Returns the various reblogged_ fields. - **tag** (string | string[]) - Optional - Limits the response to posts with the specified tags. When multiple tags are provided, posts will be returned that have _all_ of the provided tags. A maximum of four tags can be provided. - **type** (PostType) - Optional - The type of post to return. ### Request Example ```json { "id": "1234567890", "limit": 10, "notes_info": true, "npf": true, "offset": 0, "reblog_info": false, "tag": ["photography", "nature"], "type": "photo" } ``` ### Response #### Success Response (200) - **posts** (array) - An array of post objects matching the query parameters. #### Response Example ```json { "posts": [ { "type": "photo", "blog_name": "example", "post_url": "http://example.tumblr.com/post/1234567890/example-post", "timestamp": 1678886400, "format": "html", "tags": ["photography", "nature"], "highlighted": [], "note_count": 5, "title": "Example Photo Post", "body": "

This is an example photo post.

", "photos": [ { "caption": "A beautiful landscape.", "alt_sizes": [ { "width": 250, "height": 167, "url": "http://example.tumblr.com/tumblr_photo_250.jpg" } ], "original_size": { "width": 500, "height": 333, "url": "http://example.tumblr.com/tumblr_photo_500.jpg" } } ] } ] } ``` ``` -------------------------------- ### Blog Methods Source: https://tumblr.github.io/tumblr.js/index Details blog-related methods for retrieving blog information, posts, avatars, likes, followers, and managing queue, drafts, and submissions. ```APIDOC ### Blog Methods ```javascript // Get information about a given blog const blogInfo = await client.blogInfo(blogName); // Get a list of posts for a blog (with optional filtering) const blogPosts = await client.blogPosts(blogName, options); // Get the avatar URL for a blog const blogAvatar = await client.blogAvatar(blogName); // Get the likes for a blog const blogLikes = await client.blogLikes(blogName, options); // Get the followers for a blog const blogFollowers = await client.blogFollowers(blogName, options); // Get the queue for a blog const blogQueue = await client.blogQueue(blogName, options); // Get the drafts for a blog const blogDrafts = await client.blogDrafts(blogName, options); // Get the submissions for a blog const blogSubmissions = await client.blogSubmissions(blogName, options); ``` ``` -------------------------------- ### Perform POST Request with Tumblr API Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Executes a POST request to a specified API path. It accepts optional parameters and a callback function. It's recommended to omit the callback and use the returned Promise for asynchronous operations. ```typescript /** * Performs a POST request. * @param apiPath URL path for the request. * @param paramsOrCallback Optional parameters or callback. * @param callback Optional callback function. * @returns Promise | undefined - A Promise if no callback is provided. */ postRequest(apiPath: string, paramsOrCallback?: Record | TumblrClientCallback, callback?: TumblrClientCallback): Promise | undefined; ``` -------------------------------- ### Perform PUT Request with Tumblr API Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Executes a PUT request to a specified API path. It accepts optional parameters and a callback function. The Promise-based approach is preferred over callbacks. ```typescript /** * Performs a PUT request. * @param apiPath URL path for the request. * @param paramsOrCallback Optional parameters or callback. * @param callback Optional callback function. * @returns Promise | undefined - A Promise if no callback is provided. */ putRequest(apiPath: string, paramsOrCallback?: Record | TumblrClientCallback, callback?: TumblrClientCallback): Promise | undefined; ``` -------------------------------- ### PUT /api/request Source: https://tumblr.github.io/tumblr.js/classes/tumblr.Client Performs a PUT request to the specified API path. It supports optional parameters and a callback function, though using promises is recommended. ```APIDOC ## PUT /api/request ### Description Performs a PUT request to the specified API path. It supports optional parameters and a callback function, though using promises is recommended. ### Method PUT ### Endpoint /api/request ### Parameters #### Path Parameters - **apiPath** (string) - Required - URL path for the request #### Query Parameters - **paramsOrCallback** (Record | TumblrClientCallback) - Optional - Parameters for the request or a callback function. - **callback** (TumblrClientCallback) - Optional - Callback function (Deprecated, use promises instead). ### Request Example ```json { "apiPath": "/v2/blog/example.tumblr.com/posts/edit", "paramsOrCallback": { "id": 12345, "state": "published" } } ``` ### Response #### Success Response (200) - **any** - The response from the API request. #### Response Example ```json { "response": { "id": 12345, "state": "published" } } ``` ``` -------------------------------- ### Tumblr API Blog Methods in Node.js Source: https://tumblr.github.io/tumblr.js/index Illustrates common blog-related operations using the tumblr.js client in Node.js. This covers fetching blog info, posts, avatars, likes, followers, and managing queues, drafts, and submissions. All methods return promises. ```javascript // Get information about a given blog const blogInfo = await client.blogInfo(blogName); // Get a list of posts for a blog (with optional filtering) const blogPosts = await client.blogPosts(blogName, options); // Get the avatar URL for a blog const blogAvatar = await client.blogAvatar(blogName); // Get the likes for a blog const blogLikes = await client.blogLikes(blogName, options); // Get the followers for a blog const blogFollowers = await client.blogFollowers(blogName, options); // Get the queue for a blog const blogQueue = await client.blogQueue(blogName, options); // Get the drafts for a blog const blogDrafts = await client.blogDrafts(blogName, options); // Get the submissions for a blog const blogSubmissions = await client.blogSubmissions(blogName, options); ```