fleet/changes/21754-fleetctl-api-body-support
Dan Fuhry 60b3b514c2
[fleetctl] api command: support request body, including file uploads (#30806)
Add the capability to build a request body with `fleetctl api`,
including uploading files.

Example command to upload a software package:

```sh
fleetctl api --debug -X POST -F team_id=0 -F 'software=@./server/service/testdata/software-installers/ruby.deb' software/package
```

Unit tests are included for both simple POST requests and file uploads.

Closes #21754.

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.
- [x] Added/updated automated tests
- [x] Manual QA for all new/changed functionality
2025-07-29 08:15:23 -05:00

9 lines
1.2 KiB
Text

- `fleetctl api` now supports sending data in the body of non-GET requests using the `-F` flag.
- For methods other than `GET`, using the syntax `-F field=<path`, the file at "path" will be read and the field will be set to the file's contents.
- For methods other than `GET`, using the syntax `-F field=@path`, the file at "path" will be uploaded as a multipart upload.
- When no file uploads are present, the body is encoded as a JSON dictionary.
- To ensure JSON values can be passed correctly, it is no longer possible to set multiple values for a repeatable flag using a comma (`,`). You must now specify the flag multiple times.
- `fleetctl` will attempt to parse values as JSON. If successful, the value will be embedded in the JSON body. For example, `fleetctl api -F field=true endpoint` will encode as `{"field":true}`. To use the literal string "true", write `-F 'field="true"'`.
- If the value cannot be parsed as JSON, it is sent as a string.
- When `--debug` is specified, the body is written to standard error, unless it contains non-Unicode characters.
- To upload a software package, use `fleetctl api -X POST -F software=@/path/to/software.pkg -F team_id=0 -F install_script=... -F uninstall_script=... software/package`