# fetchall

### Overview

The `fetchall` RPC method allows you to retrieve multiple files from the Lynx blockchain in reverse chronological order (newest first). This command is useful for backing up or migrating data, as it can download either a specific number of the most recent files or all files stored on the blockchain for the authenticated tenant. Authentication is required to execute this function.

### Syntax

```
fetchall <count> <path>
```

### Description

When you invoke the `fetchall` method, the Lynx daemon searches the blockchain for the most recent files and downloads them to your designated location. The files are retrieved in reverse chronological order, meaning the newest files are fetched first. This method requires authentication and is designed for bulk retrieval operations.

### Parameters

<table><thead><tr><th width="134.2734375">Parameter</th><th width="159.03515625">Type</th><th width="124.90625">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>count</code></td><td>string/integer</td><td>Yes</td><td>The number of most recent assets to fetch. Enter <code>0</code> to retrieve all assets stored on the blockchain.</td></tr><tr><td><code>path</code></td><td>string</td><td>Yes</td><td>The full filesystem path where the retrieved files should be stored (e.g., <code>/home/username/downloads</code>). This path must exist before calling the method.</td></tr></tbody></table>

### Returns

The method returns an array containing a single object with the following fields:

<table><thead><tr><th width="152.83203125">Field</th><th width="123.2734375">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>result</code></td><td>string</td><td>Indicates whether the operation succeeded (<code>success</code>) or failed (<code>failure</code>).</td></tr><tr><td><code>message</code></td><td>string</td><td>Provides additional information about the result. For successful operations, shows the number of assets fetched (e.g., <code>Number of assets fetched: 5</code>). For failures, indicates the reason (e.g., <code>Invalid path: /path/to/directory.</code>, <code>Not authenticated.</code>, <code>Invalid count: abc.</code>).</td></tr></tbody></table>

### Authentication Requirements

The `fetchall` command requires authentication:

* You must authenticate using the `auth` command before using `fetchall`
* If not authenticated, the method will return a "Not authenticated" error

### Examples

#### Retrieve the 5 most recent files

```
lynx-cli fetchall 5 /home/username/downloads
```

Output:

```
[
  {
    "result": "success",
    "message": "Number of assets fetched: 5"
  }
]
```

#### Retrieve all files stored on the blockchain

```
lynx-cli fetchall 0 /home/username/downloads
```

Using JSON-RPC:

```
curl --user username --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "fetchall", "params": ["5", "/home/username/downloads"]}' -H 'content-type: text/plain;' http://127.0.0.1:9332/
```

### Error Handling

The method will return a failure result in the following scenarios:

* The user is not authenticated
* The specified path doesn't exist on the filesystem
* The count parameter is not a valid integer

### Implementation Notes

* There is a 2-second pause between each file retrieval to prevent overwhelming the system
* The count parameter is converted to an integer with input validation to prevent errors
