Write File
curl --request PUT \
--url https://api.example.com/browser/sessions/{id}/fs/file \
--header 'Content-Type: application/json' \
--data '
{
"path": "<string>",
"content": "<string>",
"mode": 123
}
'import requests
url = "https://api.example.com/browser/sessions/{id}/fs/file"
payload = {
"path": "<string>",
"content": "<string>",
"mode": 123
}
headers = {"Content-Type": "application/json"}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({path: '<string>', content: '<string>', mode: 123})
};
fetch('https://api.example.com/browser/sessions/{id}/fs/file', 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.example.com/browser/sessions/{id}/fs/file",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'path' => '<string>',
'content' => '<string>',
'mode' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$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.example.com/browser/sessions/{id}/fs/file"
payload := strings.NewReader("{\n \"path\": \"<string>\",\n \"content\": \"<string>\",\n \"mode\": 123\n}")
req, _ := http.NewRequest("PUT", url, payload)
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.put("https://api.example.com/browser/sessions/{id}/fs/file")
.header("Content-Type", "application/json")
.body("{\n \"path\": \"<string>\",\n \"content\": \"<string>\",\n \"mode\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/browser/sessions/{id}/fs/file")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"path\": \"<string>\",\n \"content\": \"<string>\",\n \"mode\": 123\n}"
response = http.request(request)
puts response.read_body{
"path": "<string>",
"bytes": 123
}Filesystem
Write File
Write or create a file in the session workspace. Parents are created automatically.
PUT
/
browser
/
sessions
/
{id}
/
fs
/
file
Write File
curl --request PUT \
--url https://api.example.com/browser/sessions/{id}/fs/file \
--header 'Content-Type: application/json' \
--data '
{
"path": "<string>",
"content": "<string>",
"mode": 123
}
'import requests
url = "https://api.example.com/browser/sessions/{id}/fs/file"
payload = {
"path": "<string>",
"content": "<string>",
"mode": 123
}
headers = {"Content-Type": "application/json"}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({path: '<string>', content: '<string>', mode: 123})
};
fetch('https://api.example.com/browser/sessions/{id}/fs/file', 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.example.com/browser/sessions/{id}/fs/file",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'path' => '<string>',
'content' => '<string>',
'mode' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$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.example.com/browser/sessions/{id}/fs/file"
payload := strings.NewReader("{\n \"path\": \"<string>\",\n \"content\": \"<string>\",\n \"mode\": 123\n}")
req, _ := http.NewRequest("PUT", url, payload)
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.put("https://api.example.com/browser/sessions/{id}/fs/file")
.header("Content-Type", "application/json")
.body("{\n \"path\": \"<string>\",\n \"content\": \"<string>\",\n \"mode\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/browser/sessions/{id}/fs/file")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"path\": \"<string>\",\n \"content\": \"<string>\",\n \"mode\": 123\n}"
response = http.request(request)
puts response.read_body{
"path": "<string>",
"bytes": 123
}Overview
Creates or overwrites a file in the session’s workspace with base64-encoded content. Parent directories are created automatically. Paths must be relative to the workspace root (no leading/, no .., no NUL byte, up to 4096 bytes).
Path Parameters
string
required
Browser session ID (UUID).
Body
string
required
Workspace-relative path, e.g.
a/b/c.txt.string
required
Base64-encoded file content.
integer
default:"0644"
Unix mode (octal). Applied after write.
Example Request
curl -X PUT "https://api.scrapengine.io/api/v1/browser/sessions/baa3f390-fa6e-4a24-b84a-a575a5f3a9c7/fs/file" \
-H "Authorization: Bearer $SCRAPENGINE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"path": "notes/todo.txt",
"content": "SGVsbG8gV29ybGQ=",
"mode": 420
}'
const response = await fetch(
"https://api.scrapengine.io/api/v1/browser/sessions/baa3f390-fa6e-4a24-b84a-a575a5f3a9c7/fs/file",
{
method: "PUT",
headers: {
"Authorization": `Bearer ${process.env.SCRAPENGINE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
path: "notes/todo.txt",
content: Buffer.from("Hello World").toString("base64"),
}),
},
);
Response
Success Response (201)
string
The written workspace-relative path.
integer
Decoded byte length of the written content.
{
"path": "notes/todo.txt",
"bytes": 11
}
Error Responses
| Status | Description |
|---|---|
400 | Invalid body — bad path, non-base64 content, or unknown fields. |
401 | Unauthorized — invalid or missing API key. |
404 | Session not found. |
413 | Decoded content exceeds the maximum write size. |
Was this page helpful?
⌘I