> 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/receive.md).

# receive()

## Overview

Retrieves a message stored by `send()`. Internally, `receive()` calls `retrieve<MeshkitMessage>()`.

## Purpose

Use `receive()` to read a message CID that is expected to contain a `MeshkitMessage`.

## Endpoint / Method

```ts
async receive(cid: string): Promise<MeshkitMessage>
```

Gateway request:

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

## Parameters

| Name  | Type     | Required | Description               |
| ----- | -------- | -------- | ------------------------- |
| `cid` | `string` | Yes      | CID returned by `send()`. |

### Request schema table

| Field | Type     | Required | Notes                                      |
| ----- | -------- | -------- | ------------------------------------------ |
| `cid` | `string` | Yes      | Passed to `retrieve<MeshkitMessage>(cid)`. |

## Response

Returns `Promise<MeshkitMessage>`.

```ts
interface MeshkitMessage {
  recipientId: string;
  payload: string;
  timestamp: number;
}
```

### Response schema table

| Field         | Type     | Description                               |
| ------------- | -------- | ----------------------------------------- |
| `recipientId` | `string` | Application-defined recipient identifier. |
| `payload`     | `string` | Message string.                           |
| `timestamp`   | `number` | Timestamp created by `send()`.            |

## Examples

### Example request

```ts
const message = await meshkit.receive("bafybeimessageexamplecid");
```

### Example response

```ts
{
  recipientId: "user_123",
  payload: "Invoice INV-1001 is available.",
  timestamp: 1760000000000,
}
```

## 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                               | CID does not point to JSON content.            |

### 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 method does not verify that the message belongs to the current user.
* The method does not decrypt content.
* Validate the returned object before trusting it in application logic.

## Best Practices

* Use `receive()` only for CIDs expected to contain `MeshkitMessage`.
* Validate `recipientId`, `payload`, and `timestamp` after retrieval.
* Avoid storing sensitive messages without application-level encryption.

## Related APIs

* [send()](/meshkit-documentation/api/send.md)
* [retrieve()](/meshkit-documentation/api/retrieve.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/receive.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.
