> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js NPM

> Integrate the Ayrshare API into your Node app with the Social API NPM Package

## Overview

Ayrshare's [Social API NPM Package](https://www.npmjs.com/package/social-media-api) allows you to integrate the Ayrshare API into your Node.js app.

### Installation

Install the Social API NPM Package if you use Node on the server-side.
The package simplifies the calls by wrapping the RESTful calls.

```bash theme={"system"}
npm i social-media-api
```

> [!NOTE]
>
> Obtain your secret API Key in the [Ayrshare Dashboard](https://app.ayrshare.com/).

### General Usage

Examples of Post, History, and Delete:

> [!NOTE]
>
> **Posting to X/Twitter?** As of March 31, 2026, X/Twitter operations through Ayrshare require your own X Developer App credentials — Ayrshare enforces this on every X-bound call. Add the 2 BYO headers to your request. See the [setup guide](https://www.ayrshare.com/docs/dashboard/connect-social-accounts/x-twitter-byo-keys.md) for details.

As of v1.3.0 the SDK includes a `setTwitterByo(apiKey, apiSecret)` helper that attaches the two required `X-Twitter-OAuth1-*` headers to every subsequent request:

```javascript theme={"system"}
const SocialPost = require("social-media-api");
const social = new SocialPost(API_KEY)
  .setTwitterByo(MY_X_API_KEY, MY_X_API_SECRET);

await social.post({
  post: "Hello from BYO",
  platforms: ["twitter"]
});
```

Use `clearTwitterByo()` to drop the headers — useful when reusing one SDK instance across tenants:

```javascript theme={"system"}
social.clearTwitterByo().setTwitterByo(nextTenant.key, nextTenant.secret);
```

```javascript theme={"system"}
const SocialPost = require("social-media-api");
const API_KEY = "API KEY"; // get an API Key at ayrshare.com
const social = new SocialPost(API_KEY);

const run = async () => {
  /** post */
  const post = await social
    .post({
      post: "One more time",
      platforms: ["twitter", "facebook", "linkedin"],
      profileKey: "DJKJDK-SKDJKDJF" // used with a User Profile
    })
    .catch(console.error);
  console.log(post);

  /** history */
  const history = await social.history().catch(console.error);
  console.log(history);

  /** delete */
  const deletePost = await social.delete({ id: post.id }).catch(console.error);
  console.log(deletePost);
};

run();
```

### Video Overview of the Social Media API NPM Package

[Social Media API NPM Package](https://www.youtube.com/embed/OMtj2h6sW6U)

Post to Social Media via an API

### Profile Key

You may specify the Profile Key for User Profile in the body of a POST or query of a GET with the `profileKey` field.

### Social API Demo

For a sample Node.js integration (using the RESTful API calls), see the GitHub repository:

> [card] [Social API Demo Code](https://github.com/ayrshare/social-api-demo)
>
> The Social API Demo is a web application that allows users to compose, schedule, and post content
> to multiple social media platforms simultaneously.

### More Information and Documentation

<ul>
  <li>[NPM Package](https://www.npmjs.com/package/social-media-api)</li>
  <li>[Github Repository](https://github.com/ayrshare/social-media-api)</li>
  <li>[Issue Discussion](https://github.com/ayrshare/social-media-api/issues)</li>
</ul>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.