> 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/shi-jian/cli-examples.md).

# CLI 示例

本练习演示了如何在终端中使用内容 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/tree/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/tree/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/tree/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/tree/main/contributor/practice/pointers/README.md) 是个好主意。

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

让我们获取该实体的清单。记住， `entityId` 是 [文件标识符](https://github.com/decentraland/docs/tree/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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/contributor/contributor-zh/nei-rong/shi-jian/cli-examples.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
