Javascript SDK

Installation and Setup

  • Node.js: Download and install from nodejs.org.

  • Install the SDK:

    npm install posto-sdk
  • Importing the SDK:

    import { PostoSDK } from 'posto-sdk';

Initializing the SDK

Create an instance using your authentication token:

import { PostoSDK } from 'posto-sdk';

const posto = PostoSDK.fromToken("YourBase64EncodedAuthToken");

Parameter: token — Your authentication token.


Posting Messages

The post method lets you publish text messages, with or without media, and even schedule posts.

Basic Post

await posto.post("Hello World!", { to: 2 });
  • Parameter: to — A channel ID, an array of IDs, or a channel name.

Post with Media and Scheduling

await posto.post("Check out this photo!", {
  to: [2, 3],
  media: "path/to/image.jpg",   // Local file path or URL
  when: "1h"                    // Post scheduled for 1 hour later
});
  • Parameters:

    • media: Specifies the media file.

    • when: Can be a relative time (e.g., "30m", "2h"), a Date object, a Unix timestamp, or a human-readable string.


Scheduling Posts and Campaigns

Scheduling a Single Post

Schedule a post for a specific future time:

const futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 2); // 2 days from now

await posto.post("Scheduled post", {
  to: [2, 3],
  when: futureDate
});

Creating a Campaign

Schedule a series of posts (a campaign) over time:

const messages = [
  "Campaign Post 1: Launch Day!",
  "Campaign Post 2: Feature Spotlight!",
  "Campaign Post 3: Customer Testimonials!"
];

const campaignOptions = {
  platforms: ["twitter", "facebook"],
  startTime: "tomorrow",   // When the campaign should start
  hoursBetweenPosts: 24,   // Time gap between posts
  style: "announcement",
  settings: {
    twitter: { postText: "Twitter Campaign!" }
  }
};

manager.createCampaign(messages, campaignOptions);

Quick Campaign

For a simplified campaign setup:

manager.createQuickCampaign(
  ["Quick Post 1", "Quick Post 2", "Quick Post 3"],
  "1d",        // Interval between posts (1 day)
  "tomorrow"   // Start time for the first post
);

Default Settings and Saved Styles

Setting Default Configurations

  • Network-wide Defaults:

    manager.setNetworkDefaults("tiktok", {
      postText: "✨ {post_title} #fyp",
      uploadMedia: true,
      cutPostText: true
    });
  • Channel-specific Defaults:

    manager.setChannelDefaults("my_business_instagram", {
      postText: "{post_title}\n...\n#business #updates",
      uploadMedia: true
    });

Saved Styles

  • Saving a Style:

    manager.saveStyle("my_announcement", {
      twitter: { postText: "🎯 {post_title}", cutPostText: true },
      facebook: { postText: "📢 Important Update:\n\n{post_title}", attachLink: true }
    });
  • Retrieving a Style:

    const style = manager.getStyle("my_announcement");
    console.log(style);
  • Listing All Styles:

    const styles = manager.listStyles();
    console.log(styles);

Channel and Network Management

  • Fetching Channels:

    const twitterChannels = await manager.getChannels("twitter");
    const allChannels = await manager.getChannels();
  • Network Settings: Retrieve and update settings for a specific network:

    const currentSettings = await settingsManager.getNetworkSettings('twitter');
    settingsManager.saveNetworkSettings('twitter', {
      post_text: "Updated news for Twitter!",
      upload_media: true
    });

Schedule Management

Manage your scheduled posts with these methods:

  • List Schedules:

    scheduleManager.list('success')
      .then(response => console.log("Schedules:", response));
  • Retry Schedules:

    scheduleManager.retry(123)
      .then(response => console.log("Retry Response:", response));
  • Delete Schedules:

    scheduleManager.delete(null, null, 'draft', null, true)
      .then(success => console.log("Draft schedules deleted!"));

Proxies should be used on all accounts that are using cookies to connect the accounts. If connecting via apps then proxies are not needed.

import { PostoSDK } from 'posto-sdk';

// Get channel proxy
const proxy = await sdk.channelManager.getChannelProxy(123);
if (proxy) {
  console.log(`Channel uses proxy: ${proxy}`);
}

// Set channel proxy
const success = await sdk.channelManager.setChannelProxy(
  123, 
  'http://myproxy:8080'
);

// Remove proxy
const success = await sdk.channelManager.setChannelProxy(
  123, 
  null
);

// Get all channel settings including proxy
const settings = await sdk.channelManager.getChannelSettings(123);

Last updated