# post

## Overview

This endpoint is used for initiating ReadSessions for tables, uploads, and query results. A ReadSession can consist of one or more read streams, which are subsequently consumed via the [getStream](https://docs.redivis.com/api/rest-api/readsessions/get) endpoint.

ReadSessions expire after 6 hours.

{% hint style="warning" %}
When creating a read session for an unreleased table, note that a stream will be returned for each upload on the table, as well as (potentially) for the previous version of the table.&#x20;

It is possible for these streams to have different schema, and it is the responsibility of the stream consumer(s) to handle accordingly.
{% endhint %}

## HTTP Request

```http
POST /tables/:tableReference/readSessions
POST /uploads/:uploadReference/readSessions
POST /queries/:queryId/readSessions
```

{% hint style="info" %}
This endpoint extends the [general API structure](https://docs.redivis.com/api/rest-api/general-structure)
{% endhint %}

## Request body

Provide a JSON object with information about the dataset.

<table><thead><tr><th width="238">Property name</th><th>Type</th><th width="341.3333333333333">Description</th></tr></thead><tbody><tr><td><strong>format</strong></td><td><strong>string</strong></td><td><strong>Optional, default "arrow".</strong> The format of the stream results. Must be one of <code>"arrow"</code>, <code>"jsonl"</code>, or <code>"csv"</code>. <br><br>If <strong>arrow</strong>, each stream will be encoded the Arrow IPC Stream binary specification.<br><br>If <strong>jsonl</strong>, each stream will be encoded as newline-delimited JSON, with each JSON record representing a single row.<br><br>If <strong>csv</strong>, each stream will be encoded as a CSV, including a header.</td></tr><tr><td><strong>maxResults</strong></td><td><strong>string</strong></td><td><strong>Optional</strong>. Maximum number of rows to return.</td></tr><tr><td><strong>selectedVariables</strong></td><td><strong>string[]</strong></td><td><p><strong>Optional</strong>. A comma separated list of the variables to return, case insensitive. The order of variables in this list will determine the order of values in the response.</p><p></p><p>If not specified, all variables belonging to the table will be returned.</p></td></tr><tr><td><strong>requestedStreamCount</strong></td><td><strong>integer</strong></td><td><strong>Optional, default 1.</strong> The requested number of streams to return. More streams may allow for higher throughput via parallelization.<br><br>There is no guarantee that the number of streams returned will be equivalent to the <code>requestedStreamCount</code>. If a table is unreleased, at minimum a stream will be returned for each upload on the unreleased table. For other tables, uploads, and query results, the requested stream count will be treated as a maximum, but in certain cases fewer streams may be returned than requested, particularly for smaller tables.</td></tr><tr><td><strong>allowAnonymousAccess</strong></td><td><strong>bool</strong></td><td><strong>Optional, default false.</strong> Whether to allow anonymous download to any client with the stream id. Useful for when an API consumer may want to return a stream to another client without that client possessing Redivis API credentials. <br><br>Extreme care must be taken when using this approach, to ensure that stream ids are not inadvertently leaked to inappropriate actors.</td></tr></tbody></table>

## Authorization

Data access to all tables referenced by the query is required. If a table's data is not public, your access token must have one of the following scopes:

* data.data
* data.edit

[Learn more about authorization.](https://docs.redivis.com/api/rest-api/authorization)

## Response body

```json
{
  "kind": "readSession",
  "streams": [
    {
      "kind": "readStream",
      "id": str,
      "format": str,     // One of "arrow", "csv", "jsonl"
      "expiresAt": int   // Expiration timestamp, in millisconds since the epoch
    }
  ]
}
```
