1

Post status

by
Published Aug 10, 2022

Create a new toot. A required parameter are a `mastodon` resource with an accessToken and "status" (text content). Optional parameters are an array of media files (base64 encoded), a boolean flag "sensitive", a string "spoiler_text", a string "inReplyToId", an ENUM["public","unlisted","private","direct"] "visibility", an ISO 8601 datetime "scheduledAt" and an ISO 639 language code "language". It should return the JSON object that the API responds.

Script mastodon Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 14 days ago
1
//native
2

3
export async function main(
4
  baseUrl: string,
5
  accessToken: string,
6
  status: string,
7
  inReplyToId?: string,
8
  sensitive = false,
9
  spoilerText?: string,
10
  visibility: "public" | "unlisted" | "private" | "direct" = "public",
11
  language?: string,
12
) {
13
  const resp = await fetch(`${baseUrl}/api/v1/statuses`, {
14
    method: "POST",
15
    headers: {
16
      Authorization: `Bearer ${accessToken}`,
17
      "Content-Type": "application/json",
18
    },
19
    body: JSON.stringify({
20
      sensitive,
21
      status,
22
      visibility,
23
      ...(inReplyToId && {
24
        in_reply_to_id: inReplyToId,
25
      }),
26
      ...(spoilerText && {
27
        spoiler_text: spoilerText,
28
      }),
29
      ...(language && {
30
        language,
31
      }),
32
    }),
33
  });
34

35
  if (!resp.ok) {
36
    throw Error(`Failed to post status: Error HTTP${resp.status}`);
37
  }
38

39
  return await resp.json();
40
}
41

Other submissions
  • Submitted by tessoudalio367 Deno
    Created 1166 days ago
    1
    // import * as wmill from 'https://deno.land/x/windmill/index.ts'
    2
    
    
    3
    export async function main(x: string) {
    4
      return x
    5
    }
  • Submitted by tessoudalio367 Deno
    Created 1166 days ago
    1
    // import * as wmill from 'https://deno.land/x/windmill/index.ts'
    2
    
    
    3
    export async function main(x: string) {
    4
      return x
    5
    }
  • Submitted by jaller94 Deno
    Created 406 days ago
    1
    export async function main(
    2
      baseUrl: string,
    3
      accessToken: string,
    4
      status: string,
    5
      inReplyToId?: string,
    6
      sensitive = false,
    7
      spoilerText?: string,
    8
      visibility: "public" | "unlisted" | "private" | "direct" = "public",
    9
      language?: string,
    10
    ) {
    11
      const resp = await fetch(`${baseUrl}/api/v1/statuses`, {
    12
        method: "POST",
    13
        headers: {
    14
          Authorization: `Bearer ${accessToken}`,
    15
          "Content-Type": "application/json",
    16
        },
    17
        body: JSON.stringify({
    18
          sensitive,
    19
          status,
    20
          visibility,
    21
          ...(inReplyToId && {
    22
            in_reply_to_id: inReplyToId,
    23
          }),
    24
          ...(spoilerText && {
    25
            spoiler_text: spoilerText,
    26
          }),
    27
          ...(language && {
    28
            language,
    29
          }),
    30
        }),
    31
      });
    32
    
    
    33
      if (!resp.ok) {
    34
        throw Error(`Failed to post status: Error HTTP${resp.status}`);
    35
      }
    36
    
    
    37
      return await resp.json();
    38
    }
    39