Skip to content
Rigel docs
Open Rigel

Replace a document's whole text

documents.document.write

POST/api/v1/households/{household_id}/commands/documents.document.write

  • Command
  • Rigel runs it
  • Applies offline

Replaces the text of a Markdown or HTML document. Use it for rewrites and for HTML; for small changes to Markdown use documents.document.edit. Pass base_version, the content_version you last read, so you don't overwrite changes made since: if the document has changed, it is refused with document_changed and the current content_version, and you should read it again. Rigel's rewrites save the earlier text as a version, so it can be restored. Refused for uploaded files (document_is_file).

Parameters#

Replace a document's whole text: parameters
FieldDescription
household_idpathstringrequired

The household's ID.

Idempotency-Keyheaderstringoptional

The command's ID. Reuse it when retrying the same command.

Request body#

JSON, as application/json.

Replace a document's whole text: request body fields
FieldDescription
document_idstringrequired

A document ID, such as doc_01JC0000000000000000000000.

contentstringrequired

The new text, in the document's format. At most 2,000,000 characters.

base_versionintegeroptional

The content_version you read. If the document has changed since, nothing is written.

at least 0

Response#

200 The command was applied.

Replace a document's whole text: response fields
FieldDescription
resultobjectrequired

What the command returned, such as the IDs it created.

result.content_versionintegerrequired

The document's content_version after the change.

versionintegerrequired

The household version after the command.

Errors#

Every error has the same envelope: error.code, error.message, error.details, error.recovery and error.request_id.

Replace a document's whole text: errors
StatusCodeWhen
400validation_failedA field is missing, misspelled or out of range. details.fields lists each problem.
401unauthenticatedThe request has no valid session.
404document_not_foundA document that is gone.
404not_foundThe household doesn't exist, or you aren't a member of it.
409document_changedBase_version of an older version.
409document_is_fileAn uploaded file.
409idempotency_key_reusedThe Idempotency-Key was already used for a different command.

Examples#

These are real. Each scenario is one of the command's test cases, run on a household when this site was built, and the response is what the API returned.

A person replacing the text saves no version

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
  -d '{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "New text"
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01JC4N0000AAAAAAAAAAAAAAAA",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01JC0000000000000000000001",
    content: "New text",
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA

{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "New text"
}
Response, 200
HTTP/1.1 200 OK
Content-Type: application/json
X-Request-Id: req_01K9D9S2R0E16XA7Y0CCPP6B5S

{
  "result": {
    "content_version": 4
  },
  "version": 1
}

Base_version matching the current version

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
  -d '{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "New",
  "base_version": 3
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01JC4N0000AAAAAAAAAAAAAAAA",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01JC0000000000000000000001",
    content: "New",
    base_version: 3,
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA

{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "New",
  "base_version": 3
}
Response, 200
HTTP/1.1 200 OK
Content-Type: application/json
X-Request-Id: req_01K9D9S2R0T31J99SDQN2D6VDR

{
  "result": {
    "content_version": 4
  },
  "version": 1
}

Base_version of an older version

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
  -d '{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "New",
  "base_version": 2
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01JC4N0000AAAAAAAAAAAAAAAA",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01JC0000000000000000000001",
    content: "New",
    base_version: 2,
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA

{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "New",
  "base_version": 2
}
Response, 409
HTTP/1.1 409 Conflict
Content-Type: application/json
X-Request-Id: req_01K9D9S2R0ZQKP6H3YMAA95QNK

{
  "error": {
    "code": "document_changed",
    "message": "The document has changed since you read it. Read it again and redo the change. No changes were applied.",
    "details": {
      "content_version": 3
    },
    "recovery": "Read the current state, then send a command that fits it.",
    "request_id": "req_01K9D9S2R0ZQKP6H3YMAA95QNK"
  }
}

An uploaded file

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
  -d '{
  "document_id": "doc_01JC000000000000000000000F",
  "content": "x"
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01JC4N0000AAAAAAAAAAAAAAAA",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01JC000000000000000000000F",
    content: "x",
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA

{
  "document_id": "doc_01JC000000000000000000000F",
  "content": "x"
}
Response, 409
HTTP/1.1 409 Conflict
Content-Type: application/json
X-Request-Id: req_01K9D9S2R00Y3K6CQBCNCBHQBD

{
  "error": {
    "code": "document_is_file",
    "message": "That document is an uploaded file, so it has no text to write. Its extracted text can be saved with documents.document.save_text. No changes were applied.",
    "details": {
      "document_id": "doc_01JC000000000000000000000F"
    },
    "recovery": "Read the current state, then send a command that fits it.",
    "request_id": "req_01K9D9S2R00Y3K6CQBCNCBHQBD"
  }
}

A document that is gone

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
  -d '{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "x"
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01JC4N0000AAAAAAAAAAAAAAAA",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01JC0000000000000000000001",
    content: "x",
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.write HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA

{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "x"
}
Response, 404
HTTP/1.1 404 Not Found
Content-Type: application/json
X-Request-Id: req_01K9D9S2R0TAKQ7YST9V5FNZ4A

{
  "error": {
    "code": "document_not_found",
    "message": "That document isn't there any more. No changes were applied.",
    "details": {
      "document_id": "doc_01JC0000000000000000000001"
    },
    "recovery": "Read the current state, then send a command that fits it.",
    "request_id": "req_01K9D9S2R0TAKQ7YST9V5FNZ4A"
  }
}

Replace a document's whole text

Pass base_version to be sure nobody changed it since you read it.

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.write' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01M6V9CTAWFF5VS2TBM85NCE4S' \
  -d '{
  "document_id": "doc_01M6V9CTABNCYZEX66AV1YAYHY",
  "content": "<h1>Babysitter sheet</h1>\n<h2>Bedtimes</h2>\n<ul>\n  <li>Theo: 7:30 pm, one story</li>\n  <li>Nia: 8:30 pm, reading allowed until 9:00</li>\n</ul>\n<h2>Numbers</h2>\n<ul>\n  <li>Ada: 555-0161</li>\n  <li>Ben: 555-0162</li>\n</ul>\n<h2>Snacks</h2>\n<p>Fruit and crackers are fine.</p>\n"
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.write", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01M6V9CTAWFF5VS2TBM85NCE4S",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01M6V9CTABNCYZEX66AV1YAYHY",
    content: "<h1>Babysitter sheet</h1>\n<h2>Bedtimes</h2>\n<ul>\n  <li>Theo: 7:30 pm, one story</li>\n  <li>Nia: 8:30 pm, reading allowed until 9:00</li>\n</ul>\n<h2>Numbers</h2>\n<ul>\n  <li>Ada: 555-0161</li>\n  <li>Ben: 555-0162</li>\n</ul>\n<h2>Snacks</h2>\n<p>Fruit and crackers are fine.</p>\n",
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.write HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01M6V9CTAWFF5VS2TBM85NCE4S

{
  "document_id": "doc_01M6V9CTABNCYZEX66AV1YAYHY",
  "content": "<h1>Babysitter sheet</h1>\n<h2>Bedtimes</h2>\n<ul>\n  <li>Theo: 7:30 pm, one story</li>\n  <li>Nia: 8:30 pm, reading allowed until 9:00</li>\n</ul>\n<h2>Numbers</h2>\n<ul>\n  <li>Ada: 555-0161</li>\n  <li>Ben: 555-0162</li>\n</ul>\n<h2>Snacks</h2>\n<p>Fruit and crackers are fine.</p>\n"
}
Response, 200
HTTP/1.1 200 OK
Content-Type: application/json
X-Request-Id: req_01M6V9CTAWJWDD7BJGKR7Y3BZS

{
  "result": {
    "content_version": 2
  },
  "version": 310
}

Write over a document that changed

Refused with the current content_version, so the change can be made again on top of it.

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.write' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01M6V9CTAXX5TNSJV0RB2QEP9T' \
  -d '{
  "document_id": "doc_01M6V9CTA8APRK3KGY0M9RKB4W",
  "content": "# Playroom plan\n\nPaint and shelves before the holidays.\n\n## Walls\n\nNia is choosing the color. Ben paints once the shelves are ordered.\n\n## Shelves\n\nOak, built in along the east wall. The carpenter'\''s quote is due this week.\n",
  "base_version": 3
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.write", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01M6V9CTAXX5TNSJV0RB2QEP9T",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01M6V9CTA8APRK3KGY0M9RKB4W",
    content: "# Playroom plan\n\nPaint and shelves before the holidays.\n\n## Walls\n\nNia is choosing the color. Ben paints once the shelves are ordered.\n\n## Shelves\n\nOak, built in along the east wall. The carpenter's quote is due this week.\n",
    base_version: 3,
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.write HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01M6V9CTAXX5TNSJV0RB2QEP9T

{
  "document_id": "doc_01M6V9CTA8APRK3KGY0M9RKB4W",
  "content": "# Playroom plan\n\nPaint and shelves before the holidays.\n\n## Walls\n\nNia is choosing the color. Ben paints once the shelves are ordered.\n\n## Shelves\n\nOak, built in along the east wall. The carpenter's quote is due this week.\n",
  "base_version": 3
}
Response, 409
HTTP/1.1 409 Conflict
Content-Type: application/json
X-Request-Id: req_01M6V9CTAY0ZADHSYW3YQPYDH4

{
  "error": {
    "code": "document_changed",
    "message": "The document has changed since you read it. Read it again and redo the change. No changes were applied.",
    "details": {
      "content_version": 4
    },
    "recovery": "Read the current state, then send a command that fits it.",
    "request_id": "req_01M6V9CTAY0ZADHSYW3YQPYDH4"
  }
}

For Rigel#

Rigel's tool for this command is documents_document_write. Rigel runs this on its own, then says what it did. The agent guide has the rest.

Rigel is in early access, and sign-up is by invitation. Open Rigel