> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/contributor/contributor-zh/nei-rong/lian-xi/cli-examples.md).

# CLI 示例

本练习演示如何在终端中使用 content API。我们将使用 Decentraland Foundation 的实例： `peer.decentraland.org`，而你只需要 `curl` 命令行工具。

{% hint style="info" %}
你可以使用 [`httpie`](https://github.com/httpie/httpie) 或者使用以下工具格式化响应： [`jq`](https://github.com/stedolan/jq) 来让每次请求返回的 JSON 更易读。在本指南中，为了清晰起见，我们会展示格式化后的文档。
{% endhint %}

我们将这样做：

1. 查询内容服务器的状态。
2. 查找并下载每日 [快照](https://github.com/decentraland/docs/blob/main/contributor/practice/snapshots/README.md) 其中包含一个实体列表。
3. 获取某个实体的清单。
4. 下载该实体的一个文件。

让我们先使用以下命令查询服务器状态： `/about`:

```bash
curl "https://peer.decentraland.org/about"
```

```js
{
  "healthy": true,
  "content": {
    "healthy": true,
    "version": "6.5.0",
  },
  // ... 更多服务器信息（功能标志、版本、路径等）
}
```

看起来服务器已正常启动并运行（`"healthy": true`），并且向我们提供了其为各个功能集实现的版本信息，以及该实例的一些配置选项。

我们想下载一些内容，所以让我们先看看可用的 [快照](https://github.com/decentraland/docs/blob/main/contributor/practice/snapshots/README.md) ，通过以下方式获取一些标识符： `/content/snapshots`.

```bash
curl "https://peer.decentraland.org/content/snapshots"
```

```js
[
  {
    "hash": "bafybeia6qoum64psaooiqo3f45i6hykfwx723uc236waub3gng2naof224",
    "timeRange": {
      "initTimestamp": 1689120000000,
      "endTimestamp": 1689206400000
    },
    "replacedSnapshotHashes": [],
    "numberOfEntities": 981,
    "generationTimestamp": 1689219353866
  },
  // ...更多快照文件
]
```

数组中的每一项都描述了一个 [快照](https://github.com/decentraland/docs/blob/main/contributor/practice/snapshots/README.md)。让我们获取一个 `hash` 并从以下位置下载该文件： `/content/contents` 端点为你提供所有已知收藏集的列表。

```bash
curl "https://peer.decentraland.org/content/contents/bafybeia6qoum64psaooiqo3f45i6hykfwx723uc236waub3gng2naof224" > snapshot
```

{% hint style="info" %}
你可以尝试更大的快照，就像在 [高级 Python 示例](https://github.com/decentraland/documentation/blob/main/content/contributor/content/practice/snapshots.py)。如果想交互式地试一试，你大概会想选择较小的快照之一。
{% endhint %}

我们可以通过查看第一行，确认下载的是我们熟悉格式的正确文件：

```bash
head -n1 snapshot
```

```
### Decentraland JSON 快照
```

太好了！现在我们已经有了该快照中捕获到的所有实体的本地摘要。让我们取列表中的第一个（文件中的第二行），一个 `个人资料`:

```bash
tail -n+2 snapshot | head -n1 
```

```js
{
  "entityId": "bafkreif7hjremkxlvixyxoxnoo7bdcnf7qqp245sjb2pag2nk3n6o6yc4c",
  "entityType": "profile",
  "pointers": [
    "0x271cdb3b1c792c336c4b2bdc52c4f415d0046b92"
  ],
  "authChain": [
    // 参见 https://docs.decentraland.org/contributor/auth/authchain/
  ],
  "entityTimestamp": 1689120135624
}
```

{% hint style="info" %}
由于快照会过期，实体也会被替换，本文中的标识符不会起作用。请在你的命令行中跟着操作，以获取真实、有效的文件 ID。
{% endhint %}

这些信息我们可以保存。我们将使用 `entityId` 来下载该实体的 JSON 清单，但保留列出的 [指针](https://github.com/decentraland/docs/blob/main/contributor/practice/pointers/README.md) 如果我们想在未来定位这个实体及其任何更新版本，这是个好主意。

我们还有 [认证链](https://github.com/decentraland/docs/blob/main/contributor/entities/README.md#ownership) 用于签署该实体的内容，我们也可以验证列出的签名，以确认我们下载的任何相关文件的真实性。

让我们拿到该实体的清单。记住， `entityId` 是 [文件标识符](https://github.com/decentraland/docs/blob/main/contributor/practice/\(filesystem/README.md#identifiers\)) 我们需要的内容，而我们可以使用 `/content/contents` 端点再次获取：

```bash
curl "https://peer.decentraland.org/content/contents/bafkreigcreq7rv6b2wf4zc4fsnif43ziwb4q46v4qhsewpf7gbsyxew3om"
```

```js
{
  "version": "v3",
  "type": "profile",
  "pointers": [
    "0x273cdb3b1c791c336c4b2bcc52c4f415d0046b91"
  ],
  "timestamp": 1689120135624,
  "content": [
    {
      "file": "body.png",
      "hash": "bafybeibzaqkirz7fk474xvyhurho5xviphs7anawaceb6gscuigia4x33u"
    },
    // ……更多文件
  ],
  "metadata": {
    // ...头像及其他信息
  }
}
```

这个 `个人资料` 实体包含 World Explorers 用来渲染和动画化玩家的全部信息。如果我们想获取其中一个打包文件，可以继续使用 `/content/contents` 端点为你提供所有已知收藏集的列表。

如果我们查看 `内容` 字段，我们就能看到 `hash` 内部名为以下文件的 `body.png`。让我们下载它：

```bash
curl "https://peer.decentraland.org/content/contents/bafybeibzaqkirz7fk474xvyhurho5xviphs7anawaceb6gscuigia4x33u" > body.png
```

我们可以打开这个 `png` 文件，用图片查看器或网页浏览器查看作者的作品。不错！


---

# 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://docs.decentraland.org/contributor/contributor-zh/nei-rong/lian-xi/cli-examples.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.
