> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hasdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Search Archive API

> Fetch the stored result of an earlier request by its request ID, free of charge, including Google links HasData resolved after the response.

HasData keeps a copy of the result of each API request. The Search Archive API returns that copy by its request ID, so you can read a result again without running the request again. Use it to:

* **Pick up Google links resolved after the response.** Some Google result links cannot be resolved before the response is sent. HasData keeps resolving them and updates the stored result. See [Google Links Resolved After the Response](#google-links-resolved-after-the-response).
* **Recover a response you did not receive**, for example after a client timeout or a dropped connection.

Archive requests are free. They use no API credits, do not count toward your concurrency limit, and work even when your plan is out of credits.

## Make a Request

Send a `GET` request to `https://api.hasdata.com/search/archive` with the ID of the earlier request. Authenticate with your API key in the `x-api-key` header, as for any other HasData API.

**requestId** `string` *required*

The ID of the earlier request, from `requestMetadata.id` in its response.

`requestId` is the only parameter. A request with any other query parameter is rejected with a `400` status.

```bash cURL theme={null}
curl --request GET -G \
  --url 'https://api.hasdata.com/search/archive' \
  --data-urlencode 'requestId=59208867-8c59-46d7-a883-5c2700b0e0df' \
  --header 'x-api-key: <your-api-key>'
```

```python Python theme={null}
import requests

response = requests.get(
    "https://api.hasdata.com/search/archive",
    params={"requestId": "59208867-8c59-46d7-a883-5c2700b0e0df"},
    headers={"x-api-key": "<your-api-key>"},
)

print(response.json())
```

```javascript Node.js theme={null}
const response = await fetch(
  'https://api.hasdata.com/search/archive?requestId=59208867-8c59-46d7-a883-5c2700b0e0df',
  { headers: { 'x-api-key': '<your-api-key>' } }
);

console.log(await response.json());
```

You can read the results of any request made in your workspace. The result is stored right after the original response is sent, so an archive request sent at the same moment can still return `404`.

## Response

The response has the same data as the original response, with a new `requestMetadata` object:

```json theme={null}
{
  "requestMetadata": {
    "id": "59208867-8c59-46d7-a883-5c2700b0e0df",
    "status": "ok",
    "linkResolutionStatus": "completed"
  },
  "searchInformation": { ... },
  "organicResults": [ ... ]
}
```

| Field | Description |
| - | - |
| `requestMetadata.id` | The request ID you asked for. |
| `requestMetadata.status` | Always `ok` in a `200` response. |
| `requestMetadata.linkResolutionStatus` | Google APIs only. Whether HasData is still resolving links in this result. See [Link Resolution Status](#link-resolution-status). |

The original `requestMetadata` fields such as `url`, `html` and `json` are not part of an archive response.

## Google Links Resolved After the Response

Links in Google results lead to their destinations through encrypted Google redirect links (`/goto?url=...`). HasData resolves these links, so the `link` fields in a response carry the destination URLs. Google limits how many of a page's links it resolves at once, so a response can be sent before every link is resolved. A link that is not resolved yet comes back as a Google redirect URL on the Google domain of your search:

```json theme={null}
{
  "position": 7,
  "title": "Coffee Roasting at Home",
  "link": "https://www.google.com/goto?url=CAES..."
}
```

HasData keeps resolving these links after the response and writes the destinations into the stored result. Fetch the result from the Search Archive to get them. You pay for the search once, because archive requests are free.

### Link Resolution Status

Responses from Google APIs carry `requestMetadata.linkResolutionStatus`, both in the original response and in the archive:

| Value | Meaning |
| - | - |
| `inProgress` | HasData is still resolving some links in this result. Fetch it from the archive later. |
| `completed` | No more links will be resolved, so this result will not change. |

Responses from other APIs have no `linkResolutionStatus`. If the field is missing, no links are being resolved, and the stored result does not change after the response.

A `completed` result can still contain a few Google redirect URLs: links that Google would not resolve stay as they are. Treat them as unresolved.

### Fetch the Resolved Links

1. Send your Google request as usual and check `requestMetadata.linkResolutionStatus`.
2. If it is `inProgress`, keep `requestMetadata.id`.
3. Fetch the result from the Search Archive later. Space out your retries, for example by doubling the wait each time, and stop when the status is `completed` or when you no longer need the links.

How long resolution takes depends on how many links are waiting, so there is no fixed time to wait. Until resolution finishes, the archive returns the result as it was first sent, with `inProgress`.

```python theme={null}
import time
import requests

HEADERS = {"x-api-key": "<your-api-key>"}
MAX_WAIT_SECONDS = 15 * 60  # how long you are willing to wait for the links

result = requests.get(
    "https://api.hasdata.com/scrape/google/serp",
    params={"q": "Coffee"},
    headers=HEADERS,
).json()
request_id = result["requestMetadata"]["id"]

delay, waited = 30, 0
while result["requestMetadata"].get("linkResolutionStatus") == "inProgress" and waited < MAX_WAIT_SECONDS:
    time.sleep(delay)
    waited += delay
    delay *= 2
    archived = requests.get(
        "https://api.hasdata.com/search/archive",
        params={"requestId": request_id},
        headers=HEADERS,
    )
    if archived.ok:
        result = archived.json()

print(result["organicResults"])
```

A request sent with [Zero Data Retention](https://docs.hasdata.com/basics/zero-data-retention.md) stores no result. Its links are not resolved after the response, so it always comes back with `completed`, and any link still unresolved stays a Google redirect URL.

## Errors

An error response carries a `message`:

```json theme={null}
{
  "status": "error",
  "message": "No stored result for this requestId"
}
```

| Status | `message` | What it means |
| - | - | - |
| `400` | `Only requestId is accepted, got: <parameters>` | The request had a query parameter other than `requestId`. |
| `400` | `Invalid requestId` | `requestId` is missing or is not a valid request ID. |
| `401` | | The API key is missing or invalid. |
| `404` | `No stored result for this requestId` | No result is stored for this ID: it is unknown, it belongs to another workspace, it was a [ZDR](https://docs.hasdata.com/basics/zero-data-retention.md) request, or the result is not stored yet. |
| `502` | `Stored result is unavailable right now` | The stored result could not be read. Retry the request later. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.