> For the complete documentation index, see [llms.txt](https://bittu-1.gitbook.io/meshkit-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bittu-1.gitbook.io/meshkit-documentation/api/retrieve.md).

# retrieve()

## Overview

Retrieves JSON data from IPFS by CID using the configured gateway.

## Purpose

Use `retrieve()` to load JSON-compatible data that was previously stored by `store()` or another compatible IPFS JSON workflow.

## Endpoint / Method

```ts
async retrieve<T>(
  cid: string,
  options?: RetrieveOptions
): Promise<T>
```

Gateway request:

```http
GET {gatewayUrl}/{cid}
```

## Parameters

| Name              | Type              | Required | Description                                                                     |
| ----------------- | ----------------- | -------- | ------------------------------------------------------------------------------- |
| `cid`             | `string`          | Yes      | Raw CID or URL containing `/ipfs/`.                                             |
| `options`         | `RetrieveOptions` | No       | Accepted by the signature. Current implementation does not apply these options. |
| `options.decrypt` | `boolean`         | No       | Reserved. Not currently applied.                                                |

### Request schema table

| Field             | Type      | Required | Notes                               |
| ----------------- | --------- | -------- | ----------------------------------- |
| `cid`             | `string`  | Yes      | Raw CID or URL containing `/ipfs/`. |
| `options.decrypt` | `boolean` | No       | Accepted by type; not implemented.  |

## Response

Returns `Promise<T>` containing the parsed JSON response from the gateway.

### Response schema table

| Type | Description                                |
| ---- | ------------------------------------------ |
| `T`  | Parsed JSON returned by `response.json()`. |

## Examples

### Example request

```ts
type Invoice = {
  id: string;
  total: number;
  currency: string;
};

const invoice = await meshkit.retrieve<Invoice>("bafybeigdyrzt5examplecid");
```

### Example response

```ts
{
  id: "INV-1001",
  total: 2499,
  currency: "INR",
}
```

## Errors

| Error                                          | Cause                                          |
| ---------------------------------------------- | ---------------------------------------------- |
| `Invalid CID`                                  | CID is empty after trimming and normalization. |
| `Failed to fetch from gateway. HTTP error 404` | Gateway could not resolve the CID.             |
| JSON parse error                               | Gateway response is not valid JSON.            |
| Network error                                  | Runtime could not reach the gateway.           |

### Error schema table

| Field     | Type     | Description                                                                    |
| --------- | -------- | ------------------------------------------------------------------------------ |
| `name`    | `string` | Standard JavaScript error name.                                                |
| `message` | `string` | `Invalid CID`, gateway HTTP error, JSON parse error, or network error message. |

## Notes

* The provider removes query strings and trailing slashes.
* URLs containing `/ipfs/` are normalized to the CID segment.
* The method expects JSON content. Use `download()` for file/blob content.

## Best Practices

* Type the response with a TypeScript generic.
* Validate the shape of untrusted data after retrieval.
* Use a custom gateway when your application needs predictable availability.

## Related APIs

* [store()](/meshkit-documentation/api/store.md)
* [download()](/meshkit-documentation/api/download.md)
* [receive()](/meshkit-documentation/api/receive.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://bittu-1.gitbook.io/meshkit-documentation/api/retrieve.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
