# Read an ingestion result

Source: https://docs.recoupable.dev/api-reference/ingestion/read

Omit action to read a job or stage. Use action only for datasets, imports or records. All responses are private and uncached.

Read a job with `?job_id=<job_id>`. Add the original `organization_id` for an organization-scoped job. Omit the `action` parameter when reading a job or artifact. Responses are private and uncached.

| State | What you can read |
| --- | --- |
| `queued` | The job is awaiting completion. The original becomes available after capture. |
| `ready` | Validation passed. Read the row counts, controls, digests and normalized records. |
| `held` | Review the recorded issues and mapped data. Supply a new idempotency key to submit a corrected contract. |
| `rejected` | The reader or an input limit prevented processing. Inspect the recorded reason and original. |

A `stage` query selects the captured original (`bronze`), mapped source records (`silver`) or accepted output (`gold`). Monetary decimals and identifiers in gold stay strings so a client can preserve subcent precision and leading zeros. Gold is available for ready jobs.

For a completed version 2 workbook, retain `source_sha256`, `contract_sha256` and `engine_version` together. They identify which bytes, mapping and engine produced the result. A mapping edit changes the contract digest even if its author reuses the same version label.

## Browse organization datasets

| Query action | Required parameters | Cursor for the next page |
| --- | --- | --- |
| `datasets` | `organization_id` | Pass the returned `next_after` as `after`. |
| `imports` | `organization_id`, `dataset_id` | Pass `next_after` as `after`. |
| `records` | `organization_id`, `dataset_id`, `job_id` | Pass `next_after` as `after_row`. |

A null cursor marks the end. Records are tied to one import version. Reading different versions and combining their records can count the same underlying activity twice. See [process private data](https://docs.recoupable.dev/api-reference/ingestion/operate) for creation and explicit delivery.

## GET /api/ingestion

Full OpenAPI specification: https://docs.recoupable.dev/spec/ingestion.json

## Authentication

This operation requires one of the security alternatives in the specification below. Security scheme definitions are included where present in the published specification.

[Authentication guide](https://docs.recoupable.dev/authentication)

## Operation and referenced schemas

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Recoup API - Data ingestion",
    "version": "1.0.0",
    "description": "Private, versioned data ingestion."
  },
  "servers": [
    {
      "url": "https://api.recoupable.dev"
    }
  ],
  "paths": {
    "/api/ingestion": {
      "get": {
        "summary": "Read an ingestion result",
        "operationId": "readIngestion",
        "description": "Omit action to read a job or stage. Use action only for datasets, imports or records. All responses are private and uncached. The x-recoup-query-schema describes complete valid parameter combinations, including action-specific page sizes.",
        "security": [
          {
            "apiKeyAuth": []
          },
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "description": "Omit to read a job. The three named actions browse an organization dataset.",
            "schema": {
              "type": "string",
              "enum": [
                "datasets",
                "imports",
                "records"
              ]
            }
          },
          {
            "name": "organization_id",
            "in": "query",
            "description": "Required for dataset queries and jobs created in organization scope.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "job_id",
            "in": "query",
            "description": "Required for job/stage reads and records.",
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          },
          {
            "name": "stage",
            "in": "query",
            "description": "Omit for job status. Used only without action.",
            "schema": {
              "type": "string",
              "enum": [
                "bronze",
                "silver",
                "gold"
              ]
            }
          },
          {
            "name": "dataset_id",
            "in": "query",
            "description": "Required for imports and records.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum 50 for datasets/imports, 100 for records.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "after",
            "in": "query",
            "description": "Opaque UUID dataset cursor or 64-character import job cursor. Use the next_after returned by the preceding page.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "after_row",
            "in": "query",
            "description": "Record cursor from next_after.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Returns a job, requested stage or one organization catalog page.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Job"
                    },
                    {
                      "$ref": "#/components/schemas/ArtifactResult"
                    },
                    {
                      "$ref": "#/components/schemas/CatalogPage"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, query, or source encoding.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "A valid credential is required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access to the selected scope was denied.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "The scoped job or artifact could not be found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The selected version, idempotency key, or artifact conflicts with stored state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "The request, source, or record exceeds its size limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "The caller reached the operation rate limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "The operation or its configured infrastructure is unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "x-recoup-query-schema": {
          "examples": [
            {
              "job_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
            }
          ],
          "oneOf": [
            {
              "$ref": "#/components/schemas/JobQuery"
            },
            {
              "$ref": "#/components/schemas/Datasets"
            },
            {
              "$ref": "#/components/schemas/Imports"
            },
            {
              "$ref": "#/components/schemas/Records"
            }
          ]
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Job": {
        "type": "object",
        "required": [
          "job_id",
          "status"
        ],
        "properties": {
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "dataset_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "held",
              "ready",
              "rejected"
            ]
          },
          "engine_version": {
            "type": "string"
          },
          "source_sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "contract_sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$",
            "description": "SHA-256 of the validated, canonical contract including defaults. Version 2 workbook completion receipts include this field."
          },
          "silver_sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "gold_sha256": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-f0-9]{64}$"
          },
          "issue_count": {
            "type": "integer"
          },
          "issues_truncated": {
            "type": "integer"
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "code"
              ],
              "properties": {
                "code": {
                  "type": "string"
                },
                "row": {
                  "type": "integer"
                },
                "field": {
                  "type": "string"
                },
                "source_sheet": {
                  "type": "string"
                }
              }
            }
          },
          "controls": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "expected",
                "actual",
                "passed"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "expected": {
                  "type": "string"
                },
                "actual": {
                  "type": "string"
                },
                "passed": {
                  "type": "boolean"
                },
                "source_sheet": {
                  "type": "string"
                },
                "source_cell": {
                  "type": "string"
                }
              }
            }
          },
          "rows_read": {
            "type": "integer"
          },
          "rows_output": {
            "type": "integer"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "engine_version": {
                  "const": "2"
                },
                "status": {
                  "enum": [
                    "ready",
                    "held",
                    "rejected"
                  ]
                }
              },
              "required": [
                "engine_version",
                "status"
              ]
            },
            "then": {
              "required": [
                "contract_sha256"
              ]
            }
          }
        ]
      },
      "ArtifactResult": {
        "type": "object",
        "properties": {
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "stage": {
            "type": "string",
            "enum": [
              "bronze",
              "silver",
              "gold"
            ]
          },
          "artifact": {
            "type": "object",
            "description": "Bronze contains filename, format, source_sha256, and content_base64. Silver contains source-grain records. Gold contains the ready records and field types."
          }
        },
        "required": [
          "job_id",
          "stage",
          "artifact"
        ],
        "additionalProperties": false
      },
      "CatalogPage": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "datasets",
              "next_after"
            ],
            "properties": {
              "datasets": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "next_after": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          {
            "type": "object",
            "required": [
              "imports",
              "next_after"
            ],
            "properties": {
              "imports": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "next_after": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          {
            "type": "object",
            "required": [
              "records",
              "next_after"
            ],
            "properties": {
              "records": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "next_after": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          }
        ]
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "JobQuery": {
        "type": "object",
        "properties": {
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "stage": {
            "type": "string",
            "enum": [
              "bronze",
              "silver",
              "gold"
            ]
          }
        },
        "required": [
          "job_id"
        ],
        "additionalProperties": false
      },
      "Datasets": {
        "type": "object",
        "properties": {
          "action": {
            "const": "datasets"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 50
          },
          "after": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "action",
          "organization_id"
        ],
        "additionalProperties": false
      },
      "Imports": {
        "type": "object",
        "properties": {
          "action": {
            "const": "imports"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "dataset_id": {
            "type": "string",
            "format": "uuid"
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 50
          },
          "after": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        },
        "required": [
          "action",
          "organization_id",
          "dataset_id"
        ],
        "additionalProperties": false
      },
      "Records": {
        "type": "object",
        "properties": {
          "action": {
            "const": "records"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "dataset_id": {
            "type": "string",
            "format": "uuid"
          },
          "job_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100
          },
          "after_row": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000
          }
        },
        "required": [
          "action",
          "organization_id",
          "dataset_id",
          "job_id"
        ],
        "additionalProperties": false
      }
    },
    "securitySchemes": {
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      },
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  }
}
```
