# JSON API

{% hint style="info" %}
第一版的MAN已上綫並已開源，後續的部署和接口文檔請以Github上文件爲準:\
<https://github.com/metaid-developers/man-indexer>
{% endhint %}

## 基礎API

| 地址                                           | method | parameter                                    | 描述                                      |
| -------------------------------------------- | ------ | -------------------------------------------- | --------------------------------------- |
| /api/pin/{numberOrId}                        | GET    | PIN number 或 PIN id                          | 根據 PIN number 或 PIN id 獲取 PIN 詳情        |
| /api/address/pin/list/{addressType/{address} | GET    | address addressType ：creator（創建者），owner（擁有者） | 根據 address 獲取該地址創建或擁有的 PIN 列表           |
| /api/address/pin/root/{address}              | GET    | address                                      | 根據 address 獲取 PIN root                  |
| /api/node/child/{pinId}                      | GET    | pinId                                        | 根據 PIN id 獲取 child node                 |
| /api/node/parent/{pinId}                     | GET    | pinId                                        | 根據 PIN id 獲取 parent node                |
| /api/info/address/{address}                  | GET    | address                                      | 獲取 address 的 MetaID info                |
| /api/info/rootId/{rootId}                    | GET    | rootId                                       | 根據 rootId 獲取 MetaID info                |
| /api/pin/content/{numberOrId}                | GET    | PIN number 或 PIN id                          | 根據 PIN number 或 PIN id 獲取 PIN 的 content |
| /api/getAllPinByParentPath                   | GET    | page,limit,parentPath                        | 根據 parentPath 獲取所有 pin                  |

## generalQuery

protocols 數據通用查詢，支持 `get`, `count`, `sum` 方式獲取數據。

地址: /api/generalQuery

**method:** POST

```jsx
{
    "collection": "pins", // 查詢的集合名稱，必填
    "action": "sum", // 查詢操作，支持 get, count, sum
    "filterRelation": "or", // 查詢條件關係，支持 or, and，目前不支持混用
    "field": [
        "number" // 查詢的返回的字段，sum 時必填
    ],
    // 查詢條件
    "filter": [
        {
            "operator": "=", // 條件操作符號，支持 =, >, >=, <, <=
            "key": "number", // 條件字段
            "value": 1 // 查詢值
        },
        {
            "operator": "=",
            "key": "number",
            "value": 2
        }
    ],
    "cursor": 0, // 返回數據起始
    "limit": 1, // 返回數據條數
    "sort": [
        "number", // 排序字段
        "desc" // 順序，支持 asc, desc
    ]
}

```

**成功返回示例**

```jsx
{
    "code": 1, // 成功 1
    "message": "ok", // 返回消息
    "data": [ // 數據內容
        {
            "_id": "65e96a276bff93b007c02b16",
            "isLike": "1",
            "likeTo": "32c6d91b6fb3f6746258d83f1fe8fb32f19c2a3e0071847b6046f01c938ca20bi0",
            "pinAddress": "tb1pss8ce6tgupnhmfj8u9h4saue48upucu04c7549tzal6n67v8njyst7e0fx",
            "pinId": "3943f7fa4c8496ced9ff722ae5bbdd57ad7b84a383304890b41f21e12f11086bi0",
            "pinNumber": 69
        }
    ]
}
```

**失敗返回实例**

```jsx
{
    "code": -1, // 失敗
    "message": "Data not found", // 失敗原因
    "data": null
}
```
