# CLI: API Sequences

Use this section when you need to drive API sequence authoring from the
Cofactor CLI. The conceptual model lives in `api-sequences`; this section is
only command orientation. Prefer each command's `--help` output for the
current flag list.

## Common flow

1. Inspect the API catalog for candidate endpoints.

   ```bash
   cofactor api-catalog sources list
   cofactor api-catalog endpoints list --search <keyword>
   cofactor api-catalog endpoints get <apiRequestId>
   ```

2. Compose a sequence JSON file locally. Reference endpoints by
   `apiRequestId` and chain steps with `{{stepId.response.path}}`.

3. Create an API-only workflow from the sequence file.

   ```bash
   cofactor workflow create --api-only --name "smoke: create project" \
     --sequence-from-file seq.json
   ```

   The command returns the workflow, sequence, and node IDs.

   To attach a sequence to an existing workflow that has none, run
   `cofactor workflow api-sequence update <workflowId> --from-file seq.json`;
   it creates the sequence when absent and replaces the config otherwise.

4. Execute immediately to surface template warnings and API failures.

   ```bash
   cofactor workflow api-sequence execute <workflowId>
   ```

5. Inspect the run and iterate on the sequence file.

   ```bash
   cofactor workflow runs list <workflowId> --side api
   cofactor workflow runs get <workflowId> <runId>
   cofactor workflow runs get <workflowId> <runId> --step <runStepId> --api-call <apiStepId>
   ```

   Add `--json` for JSON; the flags print stored (capped) request/response bodies.
   Get `<runStepId>` from `runs get <workflowId> <runId> --json` (`steps[].id`).

   ```bash
   cofactor workflow api-sequence update <workflowId> --from-file seq.json
   ```

## Reference

- Command help: `cofactor workflow api-sequence --help`
- Workflow creation help: `cofactor workflow create --help`
- API catalog help: `cofactor api-catalog --help`
