Low-level HTTP request methods for direct API access and custom endpoints not covered by higher-level methods.
Performs HTTP GET requests to Tumblr API endpoints.
/**
* Performs a GET request
* @param apiPath - URL path for the request (e.g., '/v2/blog/myblog/info')
* @param params - Query parameters as object
* @returns Promise resolving to API response
*/
getRequest(apiPath: string, params?: Record<string, any>): Promise<any>;Usage Examples:
// Get blog info with parameters
const blogInfo = await client.getRequest('/v2/blog/staff/info', {
'fields[blogs]': 'name,title,description'
});
// Get posts with query parameters
const posts = await client.getRequest('/v2/blog/staff/posts', {
type: 'photo',
limit: 10,
offset: 0
});
// Array parameters are automatically formatted
const taggedPosts = await client.getRequest('/v2/tagged', {
tag: ['cats', 'funny'] // Becomes tag[0]=cats&tag[1]=funny
});Performs HTTP POST requests to Tumblr API endpoints.
/**
* Performs a POST request
* @param apiPath - URL path for the request
* @param params - Request body parameters
* @returns Promise resolving to API response
*/
postRequest(apiPath: string, params?: Record<string, any>): Promise<any>;Usage Examples:
// Create a legacy post
const newPost = await client.postRequest('/v2/blog/myblog/post', {
type: 'text',
title: 'Hello World',
body: 'This is my first post!'
});
// Like a post
await client.postRequest('/v2/user/like', {
id: '12345',
reblog_key: 'abc123'
});
// Follow a blog
await client.postRequest('/v2/user/follow', {
url: 'example.tumblr.com'
});Performs HTTP PUT requests to Tumblr API endpoints.
/**
* Performs a PUT request
* @param apiPath - URL path for the request
* @param params - Request body parameters
* @returns Promise resolving to API response
*/
putRequest(apiPath: string, params?: Record<string, any>): Promise<any>;Usage Examples:
// Edit a post
await client.putRequest('/v2/blog/myblog/posts/12345', {
content: [
{
type: 'text',
text: 'Updated post content'
}
]
});Different parameter handling based on request method and content type:
GET Requests:
param[0]=value1¶m[1]=value2POST/PUT Requests:
The client automatically determines content type based on parameters:
// JSON content-type (application/json)
await client.postRequest('/v2/blog/myblog/post', {
type: 'text',
title: 'Simple post'
});
// Multipart content-type (multipart/form-data)
await client.postRequest('/v2/blog/myblog/posts', {
json: JSON.stringify({ content: [...] }),
0: fs.createReadStream('image.jpg') // Media upload
});HTTP methods automatically apply authentication based on client configuration:
// API key authentication (query parameter)
const apiKeyClient = tumblr.createClient({ consumer_key: 'key' });
await apiKeyClient.getRequest('/v2/blog/staff/info');
// Requests: GET /v2/blog/staff/info?api_key=key
// OAuth authentication (Authorization header)
const oauthClient = tumblr.createClient({
consumer_key: 'key',
consumer_secret: 'secret',
token: 'token',
token_secret: 'token_secret'
});
await oauthClient.postRequest('/v2/user/info');
// Includes: Authorization: OAuth oauth_consumer_key="key", oauth_signature="...", ...All requests include standard headers:
{
'User-Agent': 'tumblr.js/5.0.1',
'Accept': 'application/json',
'Content-Type': 'application/json' | 'multipart/form-data' // Based on content
}Arrays are automatically formatted for Tumblr API expectations:
// Input
await client.getRequest('/v2/tagged', {
tag: ['cats', 'funny', 'gifs']
});
// Query string
// ?tag[0]=cats&tag[1]=funny&tag[2]=gifs
// Post body arrays
await client.postRequest('/v2/blog/myblog/posts', {
tags: ['technology', 'programming']
});
// Form data
// tags[0]=technology
// tags[1]=programmingHTTP methods handle various error conditions:
try {
const result = await client.getRequest('/v2/blog/nonexistent/info');
} catch (error) {
// API errors
console.log(error.message); // "API error: 404 Not Found"
}
try {
const result = await client.postRequest('/v2/invalid-endpoint');
} catch (error) {
// Network errors, parsing errors, etc.
console.log(error.message);
}API paths are automatically combined with the client's base URL:
const client = tumblr.createClient({
baseUrl: 'https://api.tumblr.com' // Default
});
// apiPath: '/v2/blog/staff/info'
// Full URL: https://api.tumblr.com/v2/blog/staff/info
await client.getRequest('/v2/blog/staff/info');POST and PUT requests support media uploads via Node.js streams:
const fs = require('fs');
await client.postRequest('/v2/blog/myblog/posts', {
json: JSON.stringify({
content: [
{
type: 'image',
media: { identifier: '0' },
alt_text: 'My photo'
}
]
}),
0: fs.createReadStream('./photo.jpg') // Stream mapped to identifier
});All HTTP methods support legacy callback patterns (deprecated):
// Promise (recommended)
const result = await client.getRequest('/v2/blog/staff/info');
// Callback (deprecated)
client.getRequest('/v2/blog/staff/info', (err, result) => {
if (err) {
console.error(err);
} else {
console.log(result);
}
});
// Callback with parameters (deprecated)
client.getRequest('/v2/blog/staff/posts', { limit: 5 }, (err, result) => {
// Handle response
});