Skip to main content
POST
/
v1
/
agents
/
{agent_id}
/
workspace
/
file_write
Workspace: File Write
curl --request POST \
  --url https://api.xpander.ai/v1/agents/{agent_id}/workspace/file_write \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "path": "<string>",
  "content": "<string>",
  "create_dirs": true
}
'
import requests

url = "https://api.xpander.ai/v1/agents/{agent_id}/workspace/file_write"

payload = {
"path": "<string>",
"content": "<string>",
"create_dirs": True
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({path: '<string>', content: '<string>', create_dirs: true})
};

fetch('https://api.xpander.ai/v1/agents/{agent_id}/workspace/file_write', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.xpander.ai/v1/agents/{agent_id}/workspace/file_write",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'path' => '<string>',
'content' => '<string>',
'create_dirs' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.xpander.ai/v1/agents/{agent_id}/workspace/file_write"

payload := strings.NewReader("{\n \"path\": \"<string>\",\n \"content\": \"<string>\",\n \"create_dirs\": true\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.xpander.ai/v1/agents/{agent_id}/workspace/file_write")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"path\": \"<string>\",\n \"content\": \"<string>\",\n \"create_dirs\": true\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.xpander.ai/v1/agents/{agent_id}/workspace/file_write")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"path\": \"<string>\",\n \"content\": \"<string>\",\n \"create_dirs\": true\n}"

response = http.request(request)
puts response.read_body
{
  "path": "<string>",
  "bytes_written": 0,
  "created": false
}
{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}
Create or overwrite a file in the per-agent workspace filesystem. When create_dirs is true, any missing parent directories are created automatically.

Path Parameters

agent_id
string
required
Agent ID (UUID)

Request Body

path
string
required
Destination file path relative to the workspace root.
content
string
required
Full file content. Existing files are overwritten.
create_dirs
boolean
default:true
When true, missing parent directories are created automatically.

Response

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

Example Request

curl -X POST "https://api.xpander.ai/v1/agents/<agent-id>/workspace/file_write" \
  -H "Content-Type: application/json" \
  -H "x-api-key: <your-api-key>" \
  -d '{
    "path": "output/report.txt",
    "content": "Hello World\n",
    "create_dirs": true
  }'

Notes

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 where the file should be written. Creates or overwrites the file.

Example:

"output/report.txt"

content
string
required

Complete content to write to the file.

Example:

"Hello World\n"

create_dirs
boolean
default:true

If true, creates parent directories automatically if they don't exist.

Response

Successful Response

path
string
required

The path where the file was written

bytes_written
integer
default:0

Number of bytes written to the file

Example:

12

created
boolean
default:false

True if this was a new file, False if overwritten