Official Node.js SDK for the Blog2Social API v1.0.
The SDK provides a typed, Promise-based interface for authentication, network connections, publishing, user apps, network properties, and video uploads.
npm install @adenion/blog2social-api-node-js-sdk- Node.js 18 or higher
- npm
- A Blog2Social
service_token - An
access_tokenfor user-specific endpoints
┌──────────────────────────────┐
│ Your Node.js Application │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ Blog2Social Node.js SDK │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ Blog2Social API │
└──────────────┬───────────────┘
│
┌───────────┼───────────┐
▼ ▼ ▼
Facebook LinkedIn Instagram
▼ ▼ ▼
Threads Pinterest TikTok
... additional supported networks ...
import { Blog2SocialClient } from '@adenion/blog2social-api-node-js-sdk';
const client = new Blog2SocialClient({
serviceToken: process.env.BLOG2SOCIAL_SERVICE_TOKEN,
accessToken: process.env.BLOG2SOCIAL_ACCESS_TOKEN,
});Do not commit API tokens. Use environment variables or a secrets manager in production.
const response = await client.authentication.authenticateUser();
console.log(response.access_token);authenticateUser() automatically stores the returned access token on the client instance.
This service-level endpoint requires only the service_token.
const users = await client.user.listUsers();
console.log(users);const networks = await client.network.listNetwork();
console.log(networks);Network properties describe supported content, limits, media formats, instant sharing, and video requirements.
const properties = await client.network.listProperties();
console.log(properties);For video publishing, inspect video_support and video_upload_type for the matching network_id and network_type.
A video token is generated only when video_upload_type is 1:
0: publish with a public video URL1: request a video token and upload the local file in chunks2: publish with a public video URL; no video token is generated
const response = await client.connection.addNetwork(
1,
1,
'en',
);
console.log(decodeURIComponent(response.auth_link));Network type values:
0 = Profile
1 = Page
2 = Group
Some networks may require a user app. Register the app credentials first with client.userApps.add() and follow the API documentation for the selected network.
const connections = await client.user.listUserAuthentications();
console.log(connections);The returned client_user_network_id identifies the connected destination used for publishing.
const clientUserNetworkId = 123456;
const response = await client.share.createPost(clientUserNetworkId, [
{
client_user_network_id: clientUserNetworkId,
title: 'My first API post',
message: 'Hello from the Blog2Social Node.js SDK.',
postFormat: 0,
customUrl: 'https://example.com',
},
]);
console.log(response);Post formats:
0 = Link
1 = Image
2 = Video
const response = await client.share.createPost(clientUserNetworkId, [
{
client_user_network_id: clientUserNetworkId,
title: 'Image Post',
message: 'This is an image post.',
postFormat: 1,
mediaObjects: [
{
type: 'IMAGE',
url: 'https://example.com/image.jpg',
},
],
},
]);Use this workflow when the matching network property has video_upload_type equal to 0 or 2.
const response = await client.share.createPost(clientUserNetworkId, [
{
client_user_network_id: clientUserNetworkId,
title: 'Video Post',
message: 'This is a video post.',
postFormat: 2,
mediaObjects: [
{
type: 'VIDEO',
url: 'https://example.com/video.mp4',
},
],
},
]);Use this workflow only when the matching network property has video_upload_type = 1.
- Request a video token with
client.video.createVideoPost(). - Upload the file in chunks with
client.videoUpload.uploadChunk(). - Check the result with
client.videoStatus.check().
A complete implementation is available in examples/uploadVideoAndPost.mjs.
const userApp = await client.userApps.add(
6,
'YOUR_APP_KEY',
'YOUR_APP_SECRET',
'My Pinterest App',
);
console.log(userApp);Available methods:
client.userApps.add();
client.userApps.list();
client.userApps.modify();
client.userApps.delete();client.authentication;
client.network;
client.connection;
client.categories;
client.user;
client.share;
client.video;
client.videoUpload;
client.videoStatus;
client.app;
client.userApps;API errors are thrown as Blog2SocialApiError and include the HTTP status and parsed response body.
import {
Blog2SocialApiError,
} from '@adenion/blog2social-api-node-js-sdk';
try {
await client.network.listNetwork();
} catch (error) {
if (error instanceof Blog2SocialApiError) {
console.error(error.status);
console.error(error.responseBody);
}
throw error;
}Ready-to-use examples are available in the examples/ directory.
Copy the example configuration before running them:
cp examples/config.example.mjs examples/config.mjsThen add your test tokens and IDs to examples/config.mjs.
Run an example:
node examples/listNetwork.mjsInstall dependencies:
npm installBuild the SDK:
npm run buildInspect the npm package contents:
npm pack --dry-runMIT