> ## Documentation Index
> Fetch the complete documentation index at: https://docs.heyhumm.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Manage Commands via API

> Create, update, and verify reusable Humm commands through the Analyst API.

Use this workflow when you want to manage reusable prompts outside the Humm UI.

## Before You Begin

You will need:

* Your organization ID
* A Humm API token
* The Analyst API base URL, usually `https://analyst.heyhumm.ai`

<Note>
  The public resource is called a command. If you see older internal references to "slash commands" or "slashies," use the Commands API instead.
</Note>

## Recommended Flow

1. List existing commands
2. Fetch the command you want to update
3. Draft the revised content locally
4. Review the diff
5. Apply the `PUT`
6. Re-fetch the command and inspect version history
7. Restore an earlier version if you need to roll back the change

## 1. List Commands

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request GET \
  --url "https://analyst.heyhumm.ai/commands?organization_id=$ORG_ID" \
  --header "Authorization: Bearer $HUMM_PAT"
```

## 2. Fetch the Current Command

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request GET \
  --url "https://analyst.heyhumm.ai/commands/$COMMAND_ID?organization_id=$ORG_ID" \
  --header "Authorization: Bearer $HUMM_PAT"
```

## 3. Apply the Update

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request PUT \
  --url "https://analyst.heyhumm.ai/commands/$COMMAND_ID?organization_id=$ORG_ID" \
  --header "Authorization: Bearer $HUMM_PAT" \
  --header "Content-Type: application/json" \
  --data '{
    "description": "Prepare a QBR with product usage, support risk, and NPS context.",
    "content": "Prepare a QBR summary for {{account_name}} including:\n- Health score trends over the last 6 months\n- Product usage highlights\n- Open support tickets\n- NPS trends\n- Expansion opportunities"
  }'
```

## Python Example

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import difflib
import os
import requests

base_url = "https://analyst.heyhumm.ai"
headers = {"Authorization": f"Bearer {os.environ['HUMM_PAT']}"}
org_id = os.environ["ORG_ID"]
command_id = os.environ["COMMAND_ID"]

current = requests.get(
    f"{base_url}/commands/{command_id}",
    params={"organization_id": org_id},
    headers=headers,
    timeout=30,
)
current.raise_for_status()
command = current.json()

old_content = command["content"]
new_content = old_content + "\n- NPS trends\n"

print("\n".join(difflib.unified_diff(
    old_content.splitlines(),
    new_content.splitlines(),
    fromfile="before.md",
    tofile="after.md",
    lineterm="",
)))

approved = input("Apply command update? [y/N] ").strip().lower() == "y"
if approved:
    updated = requests.put(
        f"{base_url}/commands/{command_id}",
        params={"organization_id": org_id},
        headers={**headers, "Content-Type": "application/json"},
        json={
            "description": command.get("description"),
            "content": new_content,
        },
        timeout=30,
    )
    updated.raise_for_status()
    print(updated.json()["updated_at"])
```

## TypeScript Example

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
const baseUrl = "https://analyst.heyhumm.ai";

async function updateCommand(orgId: string, commandId: string, token: string) {
  const current = await fetch(
    `${baseUrl}/commands/${commandId}?organization_id=${orgId}`,
    { headers: { Authorization: `Bearer ${token}` } },
  );

  if (!current.ok) throw new Error(`Fetch failed: ${current.status}`);
  const command = await current.json();

  const newContent = `${String(command.content)}\n- NPS trends\n`;

  console.log("Preview only:");
  console.log({ before: command.content, after: newContent });

  const res = await fetch(
    `${baseUrl}/commands/${commandId}?organization_id=${orgId}`,
    {
      method: "PUT",
      headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        description: command.description,
        content: newContent,
      }),
    },
  );

  if (!res.ok) throw new Error(`Update failed: ${res.status}`);
  return res.json();
}
```

## Prompt Your Assistant

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
Use the Humm Analyst API to update one of our commands.

Organization:
- Use this organization ID: $ORG_ID

Change request:
- Update the command to reflect the change I describe

Workflow:
1. List commands for the organization
2. If I did not give an exact command name or ID, show likely matches and wait for me to choose
3. Fetch the full selected command
4. Save the current command content locally as a backup
5. Review the command before editing:
   - name
   - description
   - content
   - placeholders like {{account_name}}
6. Draft the updated command locally
7. Keep the edit surgical:
   - preserve sections that already work
   - preserve placeholders unless I explicitly want them changed
   - preserve the command name unless renaming is part of the request
8. Show me:
   - the full before/after diff
   - a short summary of the behavior change
   - any recommended description update
9. Wait for explicit approval before calling PUT
10. After the update succeeds, re-fetch the command
11. Also fetch command history and confirm:
   - the content matches the approved version
   - the description is correct
   - updated_at changed
   - the new version appears in history

Constraints:
- Do not call PUT until I approve the diff
- Do not hardcode values that should remain parameterized
- If the requested change would require a new command instead of editing the current one, say so before writing
```

## Verification

Fetch the command again:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request GET \
  --url "https://analyst.heyhumm.ai/commands/$COMMAND_ID?organization_id=$ORG_ID" \
  --header "Authorization: Bearer $HUMM_PAT"
```

You can also inspect version history:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request GET \
  --url "https://analyst.heyhumm.ai/commands/$COMMAND_ID/history?organization_id=$ORG_ID" \
  --header "Authorization: Bearer $HUMM_PAT"
```

Confirm:

* The prompt content matches the approved version
* The description is still accurate
* The command history reflects the update

## Restore a Previous Version

If a revision did not work out, restore a prior snapshot instead of rebuilding the command from scratch.

1. List command history and choose the version you want to restore
2. Call the restore endpoint for that snapshot
3. Fetch the command again and confirm the restored content is live
4. Re-check history to confirm the restore was recorded

### Restore with curl

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request POST \
  --url "https://analyst.heyhumm.ai/commands/$COMMAND_ID/history/$VERSION_ID/restore?organization_id=$ORG_ID" \
  --header "Authorization: Bearer $HUMM_PAT"
```

### Verify the restore

Fetch the command again:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request GET \
  --url "https://analyst.heyhumm.ai/commands/$COMMAND_ID?organization_id=$ORG_ID" \
  --header "Authorization: Bearer $HUMM_PAT"
```

Then fetch history again:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request GET \
  --url "https://analyst.heyhumm.ai/commands/$COMMAND_ID/history?organization_id=$ORG_ID" \
  --header "Authorization: Bearer $HUMM_PAT"
```

Confirm:

* The live command now matches the restored snapshot
* `updated_at` changed
* History includes a new restore event

## Notes

* Keep command names stable unless you are intentionally renaming them.
* Use descriptive placeholders like `{{account_name}}` instead of vague variables.
* If a command is widely used, review the content carefully before updating it for the whole team.
