socialapi-cli 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +279 -2
- package/SKILL.md +99 -0
- package/bin/socialapi.mjs +4 -0
- package/generated/commands.json +6891 -0
- package/package.json +41 -4
- package/src/auth/api.mjs +103 -0
- package/src/auth/config.mjs +62 -0
- package/src/auth/login.mjs +312 -0
- package/src/auth/logout.mjs +41 -0
- package/src/auth/whoami.mjs +13 -0
- package/src/builtins/commands.mjs +36 -0
- package/src/builtins/completion.mjs +106 -0
- package/src/builtins/help.mjs +17 -0
- package/src/builtins/index.mjs +18 -0
- package/src/builtins/skill.mjs +12 -0
- package/src/builtins/version.mjs +12 -0
- package/src/credentials.mjs +22 -0
- package/src/errors.mjs +46 -0
- package/src/flags.mjs +19 -0
- package/src/help.mjs +83 -0
- package/src/http.mjs +72 -0
- package/src/main.mjs +87 -0
- package/src/manifest.mjs +6 -0
- package/src/naming.mjs +15 -0
- package/src/operation.mjs +346 -0
- package/src/output.mjs +19 -0
- package/src/suggest.mjs +40 -0
- package/src/version.mjs +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SocialAPI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,280 @@
|
|
|
1
|
-
#
|
|
1
|
+
# socialapi-cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`socialapi` is the official command-line client for the [SocialAPI](https://social-api.ai) REST API. Every API operation is a command, generated from the API's OpenAPI spec, so the CLI always covers the whole API reference. Commands print JSON and use stable exit codes, which makes them easy to script and to hand to AI agents.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install -g socialapi-cli
|
|
7
|
+
socialapi login
|
|
8
|
+
socialapi list-accounts
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install -g socialapi-cli
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This installs the `socialapi` command. It needs Node.js 20 or later and has no other dependencies.
|
|
18
|
+
|
|
19
|
+
The version of `socialapi-cli` matches the API release it was generated from: API `v1.10.4` ships as `socialapi-cli@1.10.4`.
|
|
20
|
+
|
|
21
|
+
## Sign in
|
|
22
|
+
|
|
23
|
+
### In the browser
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
socialapi login
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`socialapi login` opens the SocialAPI sign-in page in your browser. After you approve access, the CLI creates an API key named `SocialAPI CLI (<hostname>)` for your account and stores it on this computer. The key shows up in the dashboard with the other API keys, where you can revoke it at any time. The sign-in itself is not kept: only the key is stored.
|
|
30
|
+
|
|
31
|
+
The CLI prints the sign-in URL on stderr too. When the browser does not open (for example on a remote machine over SSH), open that URL yourself. `--no-browser` only prints it:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
socialapi login --no-browser
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The browser hands the result back to the CLI on `http://127.0.0.1:<port>/callback`, so open the URL on the same computer that runs the CLI. The CLI waits 5 minutes for it.
|
|
38
|
+
|
|
39
|
+
On success, stdout holds `{"logged_in":true,"base_url":"...","user":{...}}` (the user is the `getCurrentUser` response). The key itself is never printed.
|
|
40
|
+
|
|
41
|
+
### With an existing API key
|
|
42
|
+
|
|
43
|
+
Create an API key in the SocialAPI dashboard, then:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
socialapi login --with-api-key < key.txt
|
|
47
|
+
echo "$SOCIALAPI_KEY" | socialapi login --with-api-key
|
|
48
|
+
socialapi login --with-api-key # on a terminal: asks for the key without echoing it
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The CLI checks the key with `getCurrentUser` and stores it only when the API accepts it. An invalid key prints the API's error and exits with code 1.
|
|
52
|
+
|
|
53
|
+
### Where the key is stored
|
|
54
|
+
|
|
55
|
+
| System | File |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| macOS, Linux | `$XDG_CONFIG_HOME/socialapi/config.json`, or `~/.config/socialapi/config.json` when `XDG_CONFIG_HOME` is not set |
|
|
58
|
+
| Windows | `%APPDATA%\socialapi\config.json` |
|
|
59
|
+
|
|
60
|
+
The directory is readable only by you (mode 0700) and the file too (mode 0600). It holds one key and the base URL it was created for. The stored key is sent only to that base URL: with another `--base-url` or `SOCIALAPI_BASE_URL`, the CLI acts as if no key were stored.
|
|
61
|
+
|
|
62
|
+
A new `socialapi login` replaces the stored key. When the previous key was created by `socialapi login`, the CLI then deletes it on the API. If that deletion does not go through, the login still succeeds and stderr says which key to delete in the dashboard.
|
|
63
|
+
|
|
64
|
+
### Which credential is used
|
|
65
|
+
|
|
66
|
+
The first one found wins:
|
|
67
|
+
|
|
68
|
+
1. The `--api-key <key>` flag.
|
|
69
|
+
2. The `SOCIALAPI_API_KEY` environment variable.
|
|
70
|
+
3. The key stored by `socialapi login`, for the same base URL.
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
export SOCIALAPI_API_KEY=sapi_key_...
|
|
74
|
+
socialapi list-accounts
|
|
75
|
+
socialapi list-accounts --api-key sapi_key_...
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The key is sent as `Authorization: Bearer <key>`, only to an `https://` base URL or to `localhost`, `127.0.0.1` or `[::1]`. Any other base URL stops with the error `insecure_base_url` before a request is made. `socialapi login` follows the same rule.
|
|
79
|
+
|
|
80
|
+
### Check who is signed in
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
socialapi whoami
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`socialapi whoami` calls `getCurrentUser` with the credential the CLI would use (flag, environment variable or stored key) and prints the response. Without a credential it exits with code 2 and the error `no_credential`.
|
|
87
|
+
|
|
88
|
+
### Sign out
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
socialapi logout
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`socialapi logout` removes the stored key from this computer. When `socialapi login` created the key in the browser, it also deletes the key on the API. A key stored with `--with-api-key` stays valid on the API: revoke it in the dashboard when you no longer need it.
|
|
95
|
+
|
|
96
|
+
| Result | stdout | Exit |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| Key removed | `{"logged_out":true,"base_url":"...","key_deleted":true}` (`false` for a key stored with `--with-api-key`) | 0 |
|
|
99
|
+
| Nothing stored | `{"logged_out":false,"message":"..."}` | 0 |
|
|
100
|
+
| Key removed locally, but deleting it on the API did not go through | nothing; stderr holds the error `key_not_deleted` with the key id to delete in the dashboard | 1 |
|
|
101
|
+
|
|
102
|
+
`login` and `whoami` take `--base-url`, `--timeout`, `--verbose` and `--pretty` like other commands, and `whoami` takes `--api-key` too. `logout` takes `--timeout`, `--verbose` and `--pretty`, and talks to the base URL stored with the key. `--verbose` never shows the key or the sign-in tokens.
|
|
103
|
+
|
|
104
|
+
## Base URL
|
|
105
|
+
|
|
106
|
+
The CLI calls `https://api.social-api.ai/v1` by default. To call another server, use `--base-url <url>` or the `SOCIALAPI_BASE_URL` environment variable (the flag wins).
|
|
107
|
+
|
|
108
|
+
## Commands
|
|
109
|
+
|
|
110
|
+
There is one command per API operation, named after the operation's `operationId` in kebab case: `listAccounts` is `socialapi list-accounts`, `replyToComment` is `socialapi reply-to-comment`. These are the same names as in the API reference and the MCP tools.
|
|
111
|
+
|
|
112
|
+
The kebab case rule: a hyphen goes before each capital letter that follows a lowercase letter or a digit, and before the last capital of a run of capitals that is followed by a lowercase letter, then everything is lowercased. Digits stay with the letters before them. So `getAPIKey` becomes `get-api-key` and `oauth2Token` becomes `oauth2-token`. An operation without an `operationId` is named from its method and path (`get /things/{id}` becomes `get-things-id`), and if two operations reach the same name, the later one gets a numeric suffix (`-2`).
|
|
113
|
+
|
|
114
|
+
Find commands and their usage:
|
|
115
|
+
|
|
116
|
+
```sh
|
|
117
|
+
socialapi --help # every command, grouped by API tag
|
|
118
|
+
socialapi commands webhook # commands whose name, tag or summary contains "webhook"
|
|
119
|
+
socialapi commands post --json # the same search as JSON
|
|
120
|
+
socialapi create-post --help # usage, description, arguments and flags of one command
|
|
121
|
+
socialapi help create-post # the same as create-post --help
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Built-in commands: `login [--with-api-key] [--no-browser]`, `logout`, `whoami` (see [Sign in](#sign-in)), `commands [text] [--json]`, `completion bash|zsh|fish`, `skill`, `help [command]` and `version`. `socialapi commands` lists the built-ins too, with the tag `Built-in`.
|
|
125
|
+
|
|
126
|
+
## Arguments and flags
|
|
127
|
+
|
|
128
|
+
How an operation maps to a command:
|
|
129
|
+
|
|
130
|
+
- Path parameters are positional arguments, in the order they appear in the path: `socialapi reply-to-comment <post_id>`.
|
|
131
|
+
- Query parameters, header parameters and top-level body fields are flags named in kebab case: `brand_id` is `--brand-id`. The request uses the original field names.
|
|
132
|
+
- A flag takes `--flag value` or `--flag=value`.
|
|
133
|
+
|
|
134
|
+
How a value is read, by field type:
|
|
135
|
+
|
|
136
|
+
| Field type | Example |
|
|
137
|
+
| --- | --- |
|
|
138
|
+
| string | `--text "Hello"` |
|
|
139
|
+
| integer, number | `--limit 25` |
|
|
140
|
+
| boolean | `--publish-now` for true, `--publish-now=false` for false |
|
|
141
|
+
| array of strings or numbers | `--media-ids m1,m2`, or `--media-ids m1 --media-ids m2`, or a JSON array `--media-ids '["m1","m2"]'` |
|
|
142
|
+
| array of objects | a JSON array: `--targets '[{"account_id":"acc_1"}]'` |
|
|
143
|
+
| object or free-form | a JSON object: `--platform-data '{"instagram":{"content_type":"feed"}}'` |
|
|
144
|
+
| file (multipart upload) | a file path: `--file ./photo.jpg` |
|
|
145
|
+
|
|
146
|
+
Enum values are listed in each command's `--help`.
|
|
147
|
+
|
|
148
|
+
### The whole body with --data
|
|
149
|
+
|
|
150
|
+
`--data` takes the whole JSON request body, in one of three forms:
|
|
151
|
+
|
|
152
|
+
```sh
|
|
153
|
+
socialapi reply-to-comment post_123 --data '{"text":"Thanks"}'
|
|
154
|
+
socialapi reply-to-comment post_123 --data @reply.json
|
|
155
|
+
cat reply.json | socialapi reply-to-comment post_123 --data -
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Individual flags override the top-level fields of `--data`:
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
socialapi create-post --data @post.json --text "A new caption"
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Before any request, the CLI checks the arguments and exits with code 2 for a missing positional argument, an unknown flag, a value of the wrong type or outside its enum, invalid JSON, or a missing required field (after merging `--data` and flags).
|
|
165
|
+
|
|
166
|
+
### Examples
|
|
167
|
+
|
|
168
|
+
```sh
|
|
169
|
+
socialapi list-accounts
|
|
170
|
+
socialapi create-post --text "Hi" --targets '[{"account_id":"acc_1"},{"account_id":"acc_2"}]'
|
|
171
|
+
socialapi reply-to-comment post_123 --text "Thanks"
|
|
172
|
+
socialapi upload-media --file ./photo.jpg
|
|
173
|
+
socialapi get-inbox-media med_123 --output attachment.jpg
|
|
174
|
+
socialapi list-posts --all
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Global flags
|
|
178
|
+
|
|
179
|
+
| Flag | Meaning |
|
|
180
|
+
| --- | --- |
|
|
181
|
+
| `--api-key <key>` | API key to send. Default: `SOCIALAPI_API_KEY`, then the key stored by `socialapi login`. |
|
|
182
|
+
| `--base-url <url>` | API base URL. Default: `SOCIALAPI_BASE_URL`, then `https://api.social-api.ai/v1`. |
|
|
183
|
+
| `--data <json>` | Whole JSON request body: inline, `@file`, or `-` for stdin. |
|
|
184
|
+
| `--output <file>` | Write the response body to a file instead of stdout. |
|
|
185
|
+
| `--pretty` | Print JSON indented, even when stdout is not a terminal. |
|
|
186
|
+
| `--timeout <seconds>` | Seconds to wait for each response. Default 60; `0` waits forever. |
|
|
187
|
+
| `--verbose` | Print the request line, the status and the request id on stderr. |
|
|
188
|
+
| `--help` | Show help for the command. |
|
|
189
|
+
| `--all` | On paginated commands: fetch every page and print one document. |
|
|
190
|
+
|
|
191
|
+
## Output
|
|
192
|
+
|
|
193
|
+
On success, stdout holds only the response JSON: indented with 2 spaces on a terminal, one compact line when piped, indented with `--pretty`. An empty response prints nothing.
|
|
194
|
+
|
|
195
|
+
Binary responses (such as `socialapi get-inbox-media`) go to the file named by `--output`, or to stdout when it is piped. On a terminal without `--output`, the command asks for `--output` and exits with code 2. `--output` works with JSON responses too and writes the response body as received.
|
|
196
|
+
|
|
197
|
+
`--verbose` adds lines starting with `socialapi:` on stderr: the request line, the status with the request id, and each retry. The API key never appears in them.
|
|
198
|
+
|
|
199
|
+
## Errors and exit codes
|
|
200
|
+
|
|
201
|
+
| Exit code | Meaning |
|
|
202
|
+
| --- | --- |
|
|
203
|
+
| 0 | Success. |
|
|
204
|
+
| 1 | The API returned an error. |
|
|
205
|
+
| 2 | Invalid usage, no API key, or the browser sign-in timed out. |
|
|
206
|
+
| 3 | The API could not be reached (network failure or timeout). |
|
|
207
|
+
|
|
208
|
+
Every error is one JSON document on stderr. When the API returns an error, stderr holds the API's error body as received:
|
|
209
|
+
|
|
210
|
+
```json
|
|
211
|
+
{"error":{"code":"account.not_found","message":"Account not found"},"request_id":"req_..."}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Errors raised by the CLI itself use the same shape, with one of these codes:
|
|
215
|
+
|
|
216
|
+
| Code | Exit | What to do |
|
|
217
|
+
| --- | --- | --- |
|
|
218
|
+
| `invalid_usage` | 2 | Fix the command as the message says; `socialapi <command> --help` shows the arguments and flags. |
|
|
219
|
+
| `no_credential` | 2 | Run `socialapi login`, set `SOCIALAPI_API_KEY` or pass `--api-key`. |
|
|
220
|
+
| `insecure_base_url` | 2 | Use an `https://` base URL (or localhost). |
|
|
221
|
+
| `network_error` | 3 | Check the network connection and the base URL. |
|
|
222
|
+
| `timeout` | 3 | Try again, or raise `--timeout`. |
|
|
223
|
+
|
|
224
|
+
Sign-in adds these codes:
|
|
225
|
+
|
|
226
|
+
| Code | Exit | What to do |
|
|
227
|
+
| --- | --- | --- |
|
|
228
|
+
| `login_timeout` | 2 | The browser sign-in did not finish within 5 minutes. Run `socialapi login` again. |
|
|
229
|
+
| `access_denied` and other OAuth error codes | 1 | The sign-in page did not grant access. Run `socialapi login` again and approve access. |
|
|
230
|
+
| `invalid_state` | 1 | The answer that came back to the CLI did not belong to this login. Run `socialapi login` again. |
|
|
231
|
+
| `invalid_authorization_server` | 1 | The sign-in server at the base URL did not describe its endpoints on the same origin. Check the base URL, or use `socialapi login --with-api-key`. |
|
|
232
|
+
| `invalid_response` | 1 | The server answered with something other than the expected JSON. Check the base URL. |
|
|
233
|
+
| `unsupported_api` | 2 | The API has no operation that sign-in needs. Install the latest `socialapi-cli`, or pass the key with `--api-key` or `SOCIALAPI_API_KEY`. |
|
|
234
|
+
| `key_not_deleted` | 1 | `socialapi logout` removed the key locally; delete the key named in the message in the dashboard. |
|
|
235
|
+
|
|
236
|
+
## Rate limits and retries
|
|
237
|
+
|
|
238
|
+
When the API answers `429`, the CLI waits for the time in the `Retry-After` header (seconds or an HTTP date, at most 60 seconds per wait, 1 second when the header is absent) and tries again, up to 3 times. If the last try is still a `429`, the API's error is printed and the exit code is 1. Other errors are returned at once.
|
|
239
|
+
|
|
240
|
+
## Pagination
|
|
241
|
+
|
|
242
|
+
A command is paginated when its operation takes a `cursor` query parameter and its response holds `next_cursor` (at the top level, or inside a top-level object such as `pagination`) and exactly one top-level list. Those commands accept `--all`: the CLI follows `next_cursor` until it is absent and prints one document shaped like a single page, whose list holds every item in order and which has no `next_cursor`. The other fields come from the last page. Without `--all`, pass `--cursor` yourself to fetch the next page.
|
|
243
|
+
|
|
244
|
+
## Flag name collisions
|
|
245
|
+
|
|
246
|
+
Inside one command, two fields can map to the same flag name, or a field can match a global flag. One fixed rule settles it, in this order of precedence: global flags, then query parameters, then header parameters, then body fields. The field that loses is renamed `--<location>-<name>` (`--query-limit`, `--header-limit`, `--body-limit`), and if that name is taken too it gets a numeric suffix (`--body-limit-2`, `--body-limit-3`). The request still uses the original field name, and `--help` shows each renamed flag with the field it sends.
|
|
247
|
+
|
|
248
|
+
## Shell completion
|
|
249
|
+
|
|
250
|
+
Completion covers command names and each command's flags.
|
|
251
|
+
|
|
252
|
+
```sh
|
|
253
|
+
# bash: add to ~/.bashrc
|
|
254
|
+
source <(socialapi completion bash)
|
|
255
|
+
|
|
256
|
+
# zsh: add to ~/.zshrc, after compinit
|
|
257
|
+
source <(socialapi completion zsh)
|
|
258
|
+
|
|
259
|
+
# fish: add to ~/.config/fish/config.fish
|
|
260
|
+
socialapi completion fish | source
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## AI agents
|
|
264
|
+
|
|
265
|
+
`socialapi skill` prints [SKILL.md](SKILL.md), a guide for AI agents that use the CLI: how to authenticate, find commands, read the JSON output and exit codes.
|
|
266
|
+
|
|
267
|
+
## Development
|
|
268
|
+
|
|
269
|
+
```sh
|
|
270
|
+
npm ci
|
|
271
|
+
npm run generate # openapi.json to generated/commands.json
|
|
272
|
+
npm run typecheck
|
|
273
|
+
npm test
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
`openapi.json` is updated automatically on every API release. The generator, `scripts/generate.mjs`, reduces it to the command manifest `generated/commands.json`, and the runtime in `src/` interprets that manifest: no code is written per operation. Tests run against a local fake API server.
|
|
277
|
+
|
|
278
|
+
## License
|
|
279
|
+
|
|
280
|
+
[MIT](LICENSE)
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: socialapi
|
|
3
|
+
description: Call the SocialAPI REST API from a shell with the socialapi CLI to list connected social accounts, create and schedule posts, read and reply to comments, DMs, reviews and mentions, manage webhooks and more. Every API operation is a command with JSON output and stable exit codes.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# socialapi
|
|
7
|
+
|
|
8
|
+
`socialapi` is the command-line client for the SocialAPI REST API. Each API operation is one command, named after its `operationId` in kebab case (`listAccounts` is `socialapi list-accounts`). Commands print JSON on stdout, errors as JSON on stderr, and exit with a code you can branch on.
|
|
9
|
+
|
|
10
|
+
Install it with `npm install -g socialapi-cli` (Node.js 20 or later).
|
|
11
|
+
|
|
12
|
+
## Authenticate
|
|
13
|
+
|
|
14
|
+
The first credential found wins: the `--api-key` flag, then the `SOCIALAPI_API_KEY` environment variable, then the key stored by `socialapi login`.
|
|
15
|
+
|
|
16
|
+
In a non-interactive session (CI, a sandbox, an agent without a browser), use the environment variable, or store a key the person gives you:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
export SOCIALAPI_API_KEY=sapi_key_...
|
|
20
|
+
socialapi login --with-api-key < key.txt
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
When a person is at the computer, `socialapi login` signs in through their browser and stores a new API key. It prints the sign-in URL on stderr; with `--no-browser` it only prints it, so you can hand the URL to the person. It waits up to 5 minutes for them to approve access, then prints `{"logged_in":true,"base_url":"...","user":{...}}`.
|
|
24
|
+
|
|
25
|
+
Check which account the credential belongs to before acting:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
socialapi whoami
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Without a credential, commands exit with code 2 and the error code `no_credential`: ask the person to run `socialapi login`, or to provide an API key. The stored key is used only for the base URL it was saved for. `socialapi logout` removes it (and deletes it on the API when `socialapi login` created it). Keys never appear in the output, not even with `--verbose`.
|
|
32
|
+
|
|
33
|
+
## Discover commands
|
|
34
|
+
|
|
35
|
+
Search the commands by words from their name, API tag or summary, as JSON:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
socialapi commands comment --json
|
|
39
|
+
socialapi commands webhook --json
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Each result has `name`, `tag`, `summary`, `method`, `path` and `arguments`. Then read the full usage of one command:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
socialapi reply-to-comment --help
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Help shows the positional arguments (the path parameters, in order), every flag with its type, whether it is required, its allowed values and its description, and the global flags.
|
|
49
|
+
|
|
50
|
+
## Pass arguments
|
|
51
|
+
|
|
52
|
+
- Positional arguments are the path parameters: `socialapi reply-to-comment <post_id>`.
|
|
53
|
+
- Query parameters and top-level body fields are `--kebab-case` flags: `brand_id` is `--brand-id`.
|
|
54
|
+
- Booleans: `--publish-now` for true, `--publish-now=false` for false.
|
|
55
|
+
- Arrays of strings: `--media-ids m1,m2` or repeat the flag.
|
|
56
|
+
- Objects and arrays of objects: a JSON string, `--targets '[{"account_id":"acc_1"}]'`.
|
|
57
|
+
- Files for uploads: a path, `--file ./photo.jpg`.
|
|
58
|
+
- The whole JSON body: `--data '{...}'`, `--data @body.json`, or `--data -` to read stdin. Individual flags override the same top-level fields of `--data`.
|
|
59
|
+
|
|
60
|
+
## Read the output
|
|
61
|
+
|
|
62
|
+
- Success: stdout holds the response JSON only (one compact line when piped). Parse it directly.
|
|
63
|
+
- API error: exit code 1, and stderr holds the API's error body: `{"error":{"code":"...","message":"...","meta":{...}},"request_id":"..."}`. Read `error.code` to decide what to do, and quote `request_id` when asking for support.
|
|
64
|
+
- CLI error: stderr holds `{"error":{"code":"...","message":"..."}}`; the message says what happened and what to do.
|
|
65
|
+
|
|
66
|
+
| Exit code | Meaning | Next step |
|
|
67
|
+
| --- | --- | --- |
|
|
68
|
+
| 0 | Success | Use stdout. |
|
|
69
|
+
| 1 | The API returned an error | Read `error.code` and `error.message` on stderr. |
|
|
70
|
+
| 2 | Invalid usage (`invalid_usage`), no API key (`no_credential`), a base URL that is not https (`insecure_base_url`) or a browser sign-in that was not finished in time (`login_timeout`) | Fix the command; check `socialapi <command> --help`. For `no_credential`, sign in first. |
|
|
71
|
+
| 3 | The API could not be reached (`network_error`, `timeout`) | Retry later, or raise `--timeout`. |
|
|
72
|
+
|
|
73
|
+
The CLI already retries a `429` response up to 3 times, waiting for `Retry-After`.
|
|
74
|
+
|
|
75
|
+
## Pages
|
|
76
|
+
|
|
77
|
+
List commands that return `next_cursor` accept `--all`, which fetches every page and prints one document with all items. Without it, pass `--cursor <next_cursor>` to read the next page.
|
|
78
|
+
|
|
79
|
+
## Examples
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
# Connected accounts, to find the account IDs other commands take
|
|
83
|
+
socialapi list-accounts
|
|
84
|
+
|
|
85
|
+
# Create a post for two accounts and publish it now
|
|
86
|
+
socialapi create-post --text "Hi" --targets '[{"account_id":"acc_1"},{"account_id":"acc_2"}]' --publish-now
|
|
87
|
+
|
|
88
|
+
# Reply to a comment on a post
|
|
89
|
+
socialapi reply-to-comment post_123 --text "Thanks" --comment-id comment_456 --account-id acc_1
|
|
90
|
+
|
|
91
|
+
# Every post, across all pages
|
|
92
|
+
socialapi list-posts --all
|
|
93
|
+
|
|
94
|
+
# Upload a file, then download an inbox attachment
|
|
95
|
+
socialapi upload-media --file ./photo.jpg
|
|
96
|
+
socialapi get-inbox-media med_123 --output attachment.jpg
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Use `jq` to pick fields from the output, for example `socialapi list-accounts | jq -r '.data[].id'`.
|