Skip to main content
POST
/
v1
/
agents
/
{agent_id}
/
workspace
/
file_edit
Workspace: File Edit
curl --request POST \
  --url https://api.xpander.ai/v1/agents/{agent_id}/workspace/file_edit \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "path": "<string>",
  "old_text": "<string>",
  "new_text": "<string>"
}
'
{
  "path": "<string>",
  "replacements_made": 0
}
Edit a file in the per-agent workspace by replacing an exact text occurrence. old_text must match the existing file content exactly, including whitespace and indentation.

Path Parameters

agent_id
string
required
Agent ID (UUID)

Request Body

path
string
required
Path to the file to edit, relative to the workspace root.
old_text
string
required
Exact text to find and replace. Must match existing file content, including whitespace.
new_text
string
required
Replacement text. Use an empty string to delete the matched content.

Response

status
string
Result status (e.g., ok).
path
string
Path of the file that was edited.

Example Request

curl -X POST "https://api.xpander.ai/v1/agents/<agent-id>/workspace/file_edit" \
  -H "Content-Type: application/json" \
  -H "x-api-key: <your-api-key>" \
  -d '{
    "path": "app.py",
    "old_text": "DEBUG = True",
    "new_text": "DEBUG = False"
  }'

Notes

  • The match is exact and case-sensitive. If old_text appears more than once in the file, the request fails — include additional surrounding context in old_text to make the match unique.
  • To apply several edits atomically, use Workspace: Multi Edit instead.

See Also

Authorizations

x-api-key
string
header
required

API Key for authentication

Path Parameters

agent_id
string
required

Body

application/json
path
string
required

Relative path to the file to edit.

Example:

"app.py"

old_text
string
required

The exact text to find and replace. Must match the file content exactly (whitespace-sensitive).

Example:

"DEBUG = True"

new_text
string
required

The replacement text that will substitute old_text.

Example:

"DEBUG = False"

Response

Successful Response

path
string
required

The path of the edited file

replacements_made
integer
default:0

Number of replacements made

Example:

1