Arkar Myat

Integrating with Next.js application

Feb 8, 2023Arkar

A easy and simple codesnippet for integrating with Next.js application

import Mastodon from "mastodon-api";
const accountId = process.env.NEXT_PUBLIC_MASTO_ACCOUNT_ID as string;

interface MastodonAccount {
  username: string;
  url: string;
  avator: string;
  emojis: string[];
  display_name: string;

export interface MastodonMedia {
  preview_url: string;
  url: string;
  id: string;

export interface MastodonPost {
  id: string;
  created_at: string;
  url: string;
  content: string;
  account: MastodonAccount;
  media_attachments: MastodonMedia[];
export const M = new Mastodon({
    access_token: process.env.NEXT_PUBLIC_MASTO_ACCESS_TOKEN as string,
    timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests.
    api_url: "", // optional, defaults to

async function getPosts(limit:number): Promise<MastodonPost[]> {
  return M.get(`/accounts/${accountId}/statuses?limit=${limit}`, {}).then(
    (res: any) =>
export { getPosts };