|
| 1 | +# `slack api` |
| 2 | + |
| 3 | +Call any Slack API method |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +Call any Slack API method directly. |
| 8 | + |
| 9 | +The method argument is the Slack API method name (e.g., "chat.postMessage"). |
| 10 | +Parameters are passed as key=value pairs, a JSON body, or via flags. |
| 11 | + |
| 12 | +Body format is auto-detected from positional arguments: |
| 13 | + - Multiple key=value args: form-encoded (token in request body) |
| 14 | + - Single arg starting with { or [: JSON (Bearer token in header) |
| 15 | + - No args: token sent in Authorization header |
| 16 | + |
| 17 | +Use --json to explicitly send a JSON body, or --data for a form-encoded body string. |
| 18 | + |
| 19 | +Token resolution (in priority order): |
| 20 | + 1. --token flag Explicit token value |
| 21 | + 2. --app flag Install app and use bot token (in project) |
| 22 | + 3. SLACK_BOT_TOKEN env var Bot token (set during slack deploy) |
| 23 | + 4. SLACK_USER_TOKEN env var User token |
| 24 | + 5. App prompt (in project) Select installed app and use bot token |
| 25 | + |
| 26 | +See all methods at: https://docs.slack.dev/reference/methods |
| 27 | + |
| 28 | +``` |
| 29 | +slack api <method> [key=value ...] [flags] |
| 30 | +``` |
| 31 | + |
| 32 | +## Flags |
| 33 | + |
| 34 | +``` |
| 35 | + --data string form-encoded request body string (e.g. "key1=val1&key2=val2") |
| 36 | + -H, --header strings additional HTTP headers (format: "Key: Value") |
| 37 | + -h, --help help for api |
| 38 | + -i, --include include HTTP status code and response headers in output |
| 39 | + --json string JSON request body (uses Bearer token in Authorization header) |
| 40 | + -X, --method string HTTP method for the request (default "POST") |
| 41 | +``` |
| 42 | + |
| 43 | +## Global flags |
| 44 | + |
| 45 | +``` |
| 46 | + --accessible use accessible prompts for screen readers |
| 47 | + -a, --app string use a specific app ID or environment |
| 48 | + --config-dir string use a custom path for system config directory |
| 49 | + -e, --experiment strings use the experiment(s) in the command |
| 50 | + -f, --force ignore warnings and continue executing command |
| 51 | + --no-color remove styles and formatting from outputs |
| 52 | + -s, --skip-update skip checking for latest version of CLI |
| 53 | + -w, --team string select workspace or organization by team name or ID |
| 54 | + --token string set the access token associated with a team |
| 55 | + -v, --verbose print debug logging and additional info |
| 56 | +``` |
| 57 | + |
| 58 | +## Examples |
| 59 | + |
| 60 | +``` |
| 61 | +# Test your API connection |
| 62 | +$ slack api api.test |
| 63 | +
|
| 64 | +# Check authentication |
| 65 | +$ slack api auth.test |
| 66 | +
|
| 67 | +# Add a bookmark to a channel |
| 68 | +$ slack api bookmarks.add channel_id=C0123456 title=Docs link=https://example.com |
| 69 | +
|
| 70 | +# Send a message to a channel using form-encoded string |
| 71 | +$ slack api chat.postMessage channel=C0123456 text="Hello" |
| 72 | +
|
| 73 | +# Send a message to a channel using JSON |
| 74 | +$ slack api chat.postMessage --json '{"channel":"C0123456","text":"Hello"}' |
| 75 | +
|
| 76 | +# Update a message |
| 77 | +$ slack api chat.update channel=C0123456 ts=1234567890.123456 text="Updated" |
| 78 | +
|
| 79 | +# Create a channel |
| 80 | +$ slack api conversations.create name=new-channel |
| 81 | +
|
| 82 | +# Fetch messages from a channel |
| 83 | +$ slack api conversations.history channel=C0123456 |
| 84 | +
|
| 85 | +# Get channel details |
| 86 | +$ slack api conversations.info channel=C0123456 |
| 87 | +
|
| 88 | +# List channels |
| 89 | +$ slack api conversations.list |
| 90 | +
|
| 91 | +# List members in a channel |
| 92 | +$ slack api conversations.members channel=C0123456 |
| 93 | +
|
| 94 | +# Upload a file |
| 95 | +$ slack api files.upload channels=C0123456 filename=report.csv |
| 96 | +
|
| 97 | +# Pin a message |
| 98 | +$ slack api pins.add channel=C0123456 timestamp=1234567890.123456 |
| 99 | +
|
| 100 | +# Add an emoji reaction |
| 101 | +$ slack api reactions.add channel=C0123456 timestamp=1234567890.123456 name=thumbsup |
| 102 | +
|
| 103 | +# List reactions for a user |
| 104 | +$ slack api reactions.list user=U0123456 |
| 105 | +
|
| 106 | +# Get user details |
| 107 | +$ slack api users.info user=U0123456 |
| 108 | +
|
| 109 | +# List workspace members |
| 110 | +$ slack api users.list |
| 111 | +
|
| 112 | +# Get a user's profile |
| 113 | +$ slack api users.profile.get user=U0123456 |
| 114 | +
|
| 115 | +# Open a modal view |
| 116 | +$ slack api views.open trigger_id=T0123456 view={...} |
| 117 | +
|
| 118 | +# Update a modal view |
| 119 | +$ slack api views.update view_id=V0123456 view={...} |
| 120 | +``` |
| 121 | + |
| 122 | +## See also |
| 123 | + |
| 124 | +* [slack](slack) - Slack command-line tool |
| 125 | + |
0 commit comments