
# Command-line Interface

`fob-mdm` does from the terminal everything the [MDM API](/docs/api/authentication) does: define objects and fields, create and edit golden records, read their history, connect apps, and check and fix conformance. It prints tables for people and JSON for scripts and AI agents.

The same package is also a JavaScript client you can import in workers and agents. See [JavaScript Client](/docs/cli/client).

## Install

```bash
npm install -g @finopsbricks/fob-mdm
```

It needs Node.js 18 or later. The package is [`@finopsbricks/fob-mdm`](https://www.npmjs.com/package/@finopsbricks/fob-mdm) on npm, and the source is at [github.com/finopsbricks/fob-mdm](https://github.com/finopsbricks/fob-mdm).

Check it works:

```bash
fob-mdm --version
fob-mdm getting-started
```

## Set up a profile

The CLI uses an API key saved as a **profile**, one per organization. It doesn't read keys from environment variables or flags.

1. In the app, open **Settings → API Keys** and create a key. Choose **Full Access** if you'll change data; **Read Only** is enough to look.
2. Save it. You'll be asked for the key and the secret, and the key is checked before it's saved:

```bash
fob-mdm config profiles add acme
```

```
✔ API key (fob_mdm_…) fob_mdm_xxxxxxxxxxxxxxxxxx
✔ API secret ************************
Saved profile 'acme' (https://mdm.finopsbricks.com). The key works.
It is the current profile.
```

Every command now uses `acme`. If you have more than one organization, add a profile for each, then switch with `fob-mdm config profiles use <name>`, or pick one for a single command with `--profile <name>`:

```bash
fob-mdm records list --object vendor --profile acme-labs
```

Profiles are kept in `~/.fob/fob-mdm/config.yml`, readable only by you. See [config](/docs/cli/config).

## Command pattern

```
fob-mdm <resource> <action> [target] [options]
```

The action is always named: `fob-mdm objects` lists the actions for objects rather than guessing one. Every level has `--help`:

```bash
fob-mdm --help
fob-mdm records --help
fob-mdm records edit --help
```

| Resource | Actions | What it's for |
|---|---|---|
| [objects](/docs/cli/objects) | `list`, `show`, `create`, `edit`, `delete` | The kinds of record you keep, such as Vendor |
| [fields](/docs/cli/fields) | `list`, `show`, `create`, `edit`, `delete` | An object's attributes, such as Name or GSTIN |
| [records](/docs/cli/records) | `list`, `show`, `create`, `edit`, `delete`, `history` | Golden records, their values and their history |
| [integrations](/docs/cli/integrations) | `list`, `show`, `create`, `edit`, `delete`, `pull`, `lookups` | Connected apps, and the links between their records and yours |
| [contracts](/docs/cli/contracts) | `list`, `show`, `create`, `edit`, `delete` | Which fields an app's copy must match, and how drift is fixed |
| [conformance](/docs/cli/conformance) | `run`, `status`, `enforce`, `confirm`, `events` | Find where apps differ from golden, and fix it |
| [config](/docs/cli/config) | `profiles add`, `profiles list`, `profiles use`, `profiles remove` | Saved API keys |

Objects can be given by id or slug (`vendor`). Values are set by field key: `--set bank_ifsc=HDFC0005678`.

## A first session

```bash
fob-mdm objects list
fob-mdm fields list --object vendor
fob-mdm records list --object vendor --where gstin=29ABCDE1234F1Z5
fob-mdm records edit 100 --set bank_ifsc=HDFC0005678
fob-mdm records history 100
```

`100` stands for a record id: take a real one from `records list`.

To connect an app and check it matches, follow [Check and Fix Drift](/docs/guide/conformance-loop).

## JSON output

Every command that reads, creates or changes data takes `--json` and prints the API's response instead of text, ready for `jq` or an AI agent. (`delete` and the `config` commands don't.)

```bash
fob-mdm records show 100 --json | jq '.values.bank_ifsc'
```

A list prints one page (100 rows unless you pass `--limit`, up to 500) as `{ "data": [...], "page_context": {...} }`, the same as the [API](/docs/api/pagination). When there are more pages, a hint saying so goes to stderr. Add `--all` to fetch every page, up to 15,000 rows; with `--json` it then prints just the array of rows.

Data goes to stdout and hints, prompts and errors go to stderr, so piping the output never picks up anything else.

## Deleting

`delete` asks before it deletes. Without a terminal to ask on, such as in a script or an agent, it refuses and says to pass `--yes`:

```bash
fob-mdm records delete 100 --yes
```

Deleting a field retires it instead: its values and history stay.

## Errors

A failed command prints the error to stderr and exits with code `1`. A command that worked exits `0`. Errors from the API show their [code](/docs/api/errors) and the details that say what to fix:

```
$ fob-mdm records edit 100 --set ifsc=HDFC0005678
Error [VALIDATION_ERROR]: Unknown field: ifsc

  unknown:     ["ifsc"]
  fields:      ["name","gstin","bank_ifsc"]
```

Common ones:

| Error | What to do |
|---|---|
| `No profile set up. Run fob-mdm config profiles add <name>, then try again.` | Add a profile, as in [Set up a profile](#set-up-a-profile) |
| `Profile 'acme-labs' doesn't exist. Run fob-mdm config profiles add acme-labs.` | Check the name with `fob-mdm config profiles list`, or add the profile |
| `Error [NOT_FOUND]: Record not found` | The id or slug isn't in this profile's organization. Find it with `fob-mdm records list --object vendor` (or `objects list`, `fields list`) |
| `Error [UNAUTHORIZED]: Invalid API credentials` | The key was revoked or mistyped. Create a new one and run `fob-mdm config profiles add` again with the same name |
| `Error [FORBIDDEN]: API key lacks records:edit permission` | The key is Read Only. Create a Full Access key |
| `Error [FIELD_RETIRED]: Retired field: bank_ifsc` | The field was retired. List the live ones with `fob-mdm fields list --object vendor` |
| `error: required option '--object <object>' not specified` | Add the option. `--help` on the command lists them |

Set `FOB_DEBUG=1` to print the stack trace as well.

## Related

- [JavaScript Client](/docs/cli/client): the same calls from code
- [API Authentication](/docs/api/authentication): API keys and their permissions
- [Check and Fix Drift](/docs/guide/conformance-loop): the conformance loop, step by step
