Save the text read from a file
documents.document.save_text
POST/api/v1/households/{household_id}/commands/documents.document.save_text
- Command
- Rigel runs it
- Applies offline
Records the text of an uploaded file: a PDF's text layer, or what you read from a scan or photo. Replaces any earlier text and sets how it was read (text_source). Optionally also sets a better title and the summary. Only for documents that are files; refused with document_not_file for Markdown and HTML.
Parameters#
| Field | Description |
|---|---|
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.
| Field | Description |
|---|---|
document_idstringrequired | A document ID, such as doc_01JC0000000000000000000000. |
contentstringrequired | The file's text. At most 2,000,000 characters. |
text_sourceone of: text_layer, none, rigelrequired | How the text was read: text_layer (a PDF's own text, read without a model), none (read, but there was no text, as in a scan or photo), or rigel (Rigel read it with a model). |
titlestringoptional | A better title, when the file name is unhelpful. |
summarystringoptional | What the file is and the facts people will look for. |
Response#
200 The command was applied.
| Field | Description |
|---|---|
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.
| Status | Code | When |
|---|---|---|
400 | validation_failed | A field is missing, misspelled or out of range. details.fields lists each problem. |
401 | unauthenticated | The request has no valid session. |
404 | document_not_found | A document that is gone. |
404 | not_found | The household doesn't exist, or you aren't a member of it. |
409 | document_not_file | A Markdown document. |
409 | idempotency_key_reused | The 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 PDF's text layer
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text' \
-H "Cookie: rigel_session=$RIGEL_SESSION" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
-d '{
"document_id": "doc_01JC000000000000000000000F",
"content": "Policy H-2231",
"text_source": "text_layer"
}'const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text", {
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: "Policy H-2231",
text_source: "text_layer",
}),
});
const data = await response.json();POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA
{
"document_id": "doc_01JC000000000000000000000F",
"content": "Policy H-2231",
"text_source": "text_layer"
}HTTP/1.1 200 OK
Content-Type: application/json
X-Request-Id: req_01K9D9S2R0KK8MQ31V60TNHZPV
{
"result": {
"content_version": 2
},
"version": 1
}A scan with no text, and a better title and summary
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text' \
-H "Cookie: rigel_session=$RIGEL_SESSION" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
-d '{
"document_id": "doc_01JC000000000000000000000F",
"content": "",
"text_source": "none",
"title": "Car insurance card",
"summary": "Expires 2027-03-01"
}'const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text", {
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: "",
text_source: "none",
title: "Car insurance card",
summary: "Expires 2027-03-01",
}),
});
const data = await response.json();POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA
{
"document_id": "doc_01JC000000000000000000000F",
"content": "",
"text_source": "none",
"title": "Car insurance card",
"summary": "Expires 2027-03-01"
}HTTP/1.1 200 OK
Content-Type: application/json
X-Request-Id: req_01K9D9S2R0ZQZ8PT7WT46Q72DZ
{
"result": {
"content_version": 2
},
"version": 1
}A Markdown document
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text' \
-H "Cookie: rigel_session=$RIGEL_SESSION" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
-d '{
"document_id": "doc_01JC0000000000000000000001",
"content": "y",
"text_source": "rigel"
}'const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text", {
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: "y",
text_source: "rigel",
}),
});
const data = await response.json();POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA
{
"document_id": "doc_01JC0000000000000000000001",
"content": "y",
"text_source": "rigel"
}HTTP/1.1 409 Conflict
Content-Type: application/json
X-Request-Id: req_01K9D9S2R01WAH3MWCE7AFSVDV
{
"error": {
"code": "document_not_file",
"message": "That document isn't an uploaded file. Use write or edit for its text. No changes were applied.",
"details": {
"document_id": "doc_01JC0000000000000000000001"
},
"recovery": "Read the current state, then send a command that fits it.",
"request_id": "req_01K9D9S2R01WAH3MWCE7AFSVDV"
}
}A document that is gone
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text' \
-H "Cookie: rigel_session=$RIGEL_SESSION" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
-d '{
"document_id": "doc_01JC0000000000000000000001",
"content": "y",
"text_source": "rigel"
}'const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text", {
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: "y",
text_source: "rigel",
}),
});
const data = await response.json();POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA
{
"document_id": "doc_01JC0000000000000000000001",
"content": "y",
"text_source": "rigel"
}HTTP/1.1 404 Not Found
Content-Type: application/json
X-Request-Id: req_01K9D9S2R0JKNGNZY8VA9P98S2
{
"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_01K9D9S2R0JKNGNZY8VA9P98S2"
}
}Save the text Rigel read from a photo
So the next question about the photo doesn't need it read again.
curl -X POST 'https://rigel.house/api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.save_text' \
-H "Cookie: rigel_session=$RIGEL_SESSION" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: cmd_01M6V9CTAEX6W9FTTAXW3E0YVS' \
-d '{
"document_id": "doc_01M6V9CTAC5Y4Z9FTG59AEDPTH",
"content": "The pantry'\''s middle shelf. A bag of flour on the left, then three cans of black beans, a box of orzo and a bottle of olive oil.",
"text_source": "rigel",
"summary": "A photo of the pantry'\''s middle shelf."
}'const response = await fetch("https://rigel.house/api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.save_text", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Idempotency-Key": "cmd_01M6V9CTAEX6W9FTTAXW3E0YVS",
Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
},
body: JSON.stringify({
document_id: "doc_01M6V9CTAC5Y4Z9FTG59AEDPTH",
content: "The pantry's middle shelf. A bag of flour on the left, then three cans of black beans, a box of orzo and a bottle of olive oil.",
text_source: "rigel",
summary: "A photo of the pantry's middle shelf.",
}),
});
const data = await response.json();POST /api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.save_text HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01M6V9CTAEX6W9FTTAXW3E0YVS
{
"document_id": "doc_01M6V9CTAC5Y4Z9FTG59AEDPTH",
"content": "The pantry's middle shelf. A bag of flour on the left, then three cans of black beans, a box of orzo and a bottle of olive oil.",
"text_source": "rigel",
"summary": "A photo of the pantry's middle shelf."
}HTTP/1.1 200 OK
Content-Type: application/json
X-Request-Id: req_01M6V9CTAEBTH2BF9CBHVQVT3A
{
"result": {
"content_version": 2
},
"version": 304
}For Rigel#
Rigel's tool for this command is documents_document_save_text. Rigel runs this on its own, then says what it did. The agent guide has the rest.