Threads API for developers for programmatic access

Threads, An Instagram app is all the rage now. Threads is an alternative to Twitter and everyone’s hoping on the new platform now. If you’re a developer and looking for Threads API then continue reading.

Threads API

Threads API

There is no official developer API for Threads yet but a developer reverse-engineered the Threads API requests and created an unofficial API client.

The API client is an unofficial, Reverse-Engineered Node.js/TypeScript client for Meta’sĀ Threads.

šŸ“¦ Installation

yarn add threads-api
# or with npm
npm install threads-api
# or with pnpm
pnpm install threads-api

// or in Deno šŸ¦–
import ThreadsAPI from 'npm:threads-api';

const threadsAPI = new ThreadsAPI.ThreadsAPI({});

Threads API Usage

It is as simple as importing the API client and using the client’s methods. If you want to access public data then you can directly use the API but if you want to access private methods such as publishing a thread or following someone then you should initialize the API with username and password

Checkout the examples below:

How to fetch threads user profile from API

import APIClient from "threads-api";

const main = async () => {
  const threadsAPI = new APIClient.ThreadsAPI();

  const username = "codingislove";

  // šŸ‘¤ Details for a specific user
  const userID = await threadsAPI.getUserIDfromUsername(username);
  if (!userID) {
    return;
  }
  const user = await threadsAPI.getUserProfile(username, userID);
  console.log(JSON.stringify(user));
};

main();

Response:

{
  "is_private": false,
  "profile_pic_url": "https://scontent.cdninstagram.com/v/t51.2885-19/358193075_291108399947602_86677529474390528_n.jpg?stp=dst-jpg_s150x150&_nc_ht=scontent.cdninstagram.com&_nc_cat=110&_nc_ohc=qa3mujfMuOMAX_hdows&edm=APs17CUBAAAA&ccb=7-5&oh=00_AfBjrANoN_vgzct9EOFSe3NZACDpJijVQbwXnUsgUIkDuQ&oe=64B34485&_nc_sid=10d13b",
  "username": "codingislove",
  "hd_profile_pic_versions": null,
  "is_verified": false,
  "biography": "If you're a developer, you should follow this account šŸ¤–",
  "biography_with_entities": null,
  "follower_count": 4,
  "profile_context_facepile_users": null,
  "bio_links": [{ "url": "https://codingislove.com/" }],
  "pk": "5635301639",
  "full_name": "Coding is Love",
  "id": null
}

āœØ How to publish a thread using API

import APIClient from "threads-api";

const publishThread = async () => {
  const threadsAPI = new APIClient.ThreadsAPI({
    username: '_junhoyeo', // Your username
    password: 'PASSWORD', // Your password
  });

  await threadsAPI.publish({
    text: 'šŸ¤– Hello World',
  });
};

publishThread();

āœØ Threads with Image

await threadsAPI.publish({
  text: 'šŸ¤– Threads with Image',
  image: 'https://github.com/junhoyeo/threads-api/raw/main/.github/cover.jpg',
});

āœØ Threads with Link Attachment

await threadsAPI.publish({
  text: 'šŸ¤– Threads with Link Attachment',
  url: 'https://github.com/junhoyeo/threads-api',
});

āœØ Reply to Other Threads

const parentURL = 'https://www.threads.net/t/CugF-EjhQ3r';
const parentPostID = await threadsAPI.getPostIDfromURL(parentURL); // or use `getPostIDfromThreadID`

await threadsAPI.publish({
  text: 'šŸ¤– Beep',
  link: 'https://github.com/junhoyeo/threads-api',
  parentPostID: parentPostID,
});

āœØ Like/Unlike a Thread

const threadURL = 'https://www.threads.net/t/CugK35fh6u2';
const postIDToLike = await threadsAPI.getPostIDfromURL(threadURL); // or use `getPostIDfromThreadID`

// šŸ’” Uses current credentials
await threadsAPI.like(postIDToLike);
await threadsAPI.unlike(postIDToLike);

āœØ Follow/Unfollow a User

const userIDToFollow = await threadsAPI.getUserIDfromUsername('junhoyeo');

// šŸ’” Uses current credentials
await threadsAPI.follow(userIDToFollow);
await threadsAPI.unfollow(userIDToFollow);

ā¤ļøā€šŸ”„ Delete a Post

const postID = await threadsAPI.publish({
  text: 'šŸ¤– This message will self-destruct in 5 seconds.',
});

await new Promise((resolve) => setTimeout(resolve, 5_000));
await threadsAPI.delete(postID);

Supported features

  • āœ… Read public data
    •  āœ… Fetch UserID(314216) via username(zuck)
    •  āœ… Read User Profile Info
    •  āœ… Read the list of User Threads
    •  āœ… Read the list of User Replies
    •  āœ… Fetch PostID(3140957200974444958) via PostID(CuW6-7KyXme) or PostURL(https://www.threads.net/t/CuW6-7KyXme)
    •  āœ… Read Threads via PostID
    •  āœ… Read Likers in Thread via PostID
    •  šŸš§ Read User Followers
    •  šŸš§ Read User Followings
  •  šŸš§ Read private data
  • āœ… Write data (i.e. write automated Threads)
    • āœ… Create a new Thread with text
      •  āœ… Make link previews to get shown
    •  āœ… Create a new Thread with a single image
    •  šŸš§ Create a new Thread with multiple images
    •  āœ… Reply to existing Thread
    •  āœ… Delete Thread
  • āœ… Friendships
    •  āœ… Follow User
    •  āœ… Unfollow User
  • āœ… Interactions
    •  āœ… Like Thread
    •  āœ… Unlike Thread

Conclusion

Checkout the official repo for more options and updates

Also, read How to Send SMS from API or Backend šŸ“²

5 2 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments