Skip to navigation

Archive and restore an agent

Summary

This guide archives an agent, finds it in the archived list and restores it before it is deleted. It covers archiveAgent, the archive window and unarchiveAgent. It does not cover phone number assignment after a restore; see Route phone calls.

Facts

ItemValue
OperationsarchiveAgent, listAgents, unarchiveAgent
PathsPOST /agents/{agent_id}/archive, GET /agents?state=archived, POST /agents/{agent_id}/unarchive
Capabilityagents.write for archive and unarchive; config.read for listAgents
Required headersAuthorization on every request; Idempotency-Key on archive and unarchive
Request bodyNone
Answer200 with the Agent
Archive window14 days: archive_deadline is archived_at plus exactly 14 days
Archived agent fieldsstate: archived, archived_at and archive_deadline set; both are null for an agent that is not archived
ETagArchive and unarchive do not change the agent’s ETag
EnvironmentRASEN_API_BASE (the base URL, ending in /v1), RASEN_API_KEY, AGENT_ID
Python3.10 or later, with the httpx package
TypeScriptNode.js 22 or later (built-in fetch)

Steps

Set AGENT_ID to the id of the agent, from listAgents or from the answer of createAgent.

1. Archive the agent

curl -sS -X POST "$RASEN_API_BASE/agents/$AGENT_ID/archive" \
-H "Authorization: Bearer $RASEN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)"

The answer is the agent with state: archived, archived_at and archive_deadline. From this moment:

  • The agent takes no new calls.
  • Its phone numbers are released. They keep their history and you can assign them to another agent.
  • Draft edits, publication and rollback answer 409 agent_archived.
  • listAgents leaves the agent out unless you ask for state=archived. getAgent still reads it by ID.

2. Find archived agents

curl -sS "$RASEN_API_BASE/agents?state=archived" \
-H "Authorization: Bearer $RASEN_API_KEY"

Each item shows its archive_deadline. From that time, the agent and its configuration are deleted for good. Call evidence is kept, hidden. After the deletion, the agent reads as 404 not_found.

3. Restore the agent

curl -sS -X POST "$RASEN_API_BASE/agents/$AGENT_ID/unarchive" \
-H "Authorization: Bearer $RASEN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)"

The agent returns to its state before the archive: draft, live or paused. A live agent takes calls again at once. archived_at and archive_deadline are null again. The released phone numbers are not assigned again: assign them with the phone number operations.

Rules

  • MUST let running work end before you archive. While a call, a campaign or another job of the agent runs, archive answers 409 archive_blocked.
  • MUST send a new Idempotency-Key after archive_blocked, because the first attempt had no effect.
  • MUST unarchive before the deletion starts. Unarchive works until then, also after archive_deadline while a running call, campaign or legal hold delays the deletion.
  • MUST NOT expect archive to keep the agent’s phone numbers. Assign them again after a restore.
  • Any key or member of the workspace can unarchive an agent, whoever archived it.

Verify

curl -sS "$RASEN_API_BASE/agents/$AGENT_ID" \
-H "Authorization: Bearer $RASEN_API_KEY"

Expected output after step 3: the agent with its earlier state and no archive dates.

{"id": "agent_01j00000000000000000000000", "state": "live", "archived_at": null, "archive_deadline": null}

Errors

CodeCauseFix
archive_blocked (details.reason: active_calls)A call of the agent is live.Wait for the call to end, then archive with a new Idempotency-Key.
archive_blocked (details.reason: active_campaigns)A campaign of the agent is planned, admitted, dialing, paused or stalled.Cancel the campaign or let it finish, then archive with a new Idempotency-Key.
archive_blocked (details.reason: active_jobs)Other work of the agent is running.Wait for the work to end, then archive with a new Idempotency-Key.
archive_blocked (details.reason: account_calls)An inbound number of the agent is on a carrier account that has a live call.Wait for that call to end, then archive with a new Idempotency-Key.
agent_archivedThe agent is already archived, or you edited, published or rolled back an archived agent.Read the agent. Unarchive it first if you need to change it.
conflict (details.reason: not_archived)You sent unarchive for an agent that is not archived.Nothing to restore. Read the agent for its state.
agent_deletingThe permanent deletion of the agent has started.The agent cannot be restored. Create a new agent.
not_foundThe agent does not exist, or its deletion has finished.Check AGENT_ID. A deleted agent cannot be restored.

details.reason of archive_blocked is an open vocabulary: treat an unknown value like the ones above and retry after the work ends.