# API

## API文档

Harbor提供了REST-API，可以复制[swagger.yaml](https://github.com/vmware/harbor/blob/release-0.5.0/docs/swagger.yaml)的内容到[editor.swagger.io](https://github.com/pshizhsysu/harbor/tree/2c8b9c3d0d1b677f44848411165560f122e759c3/editor.swagger.io)中进行查看。

## 访问API

在访问API时，需要在Header中携带认证信息（即用户信息）。Harbor使用的是base认证，即在Header中，需要添加一个key-value参数：

```
"Authorization" : "Basic encodedStr"
```

key为`Authoriztion`，value为`Basic encodedStr`。其中`encodedStr`是用base64加密算法对字符串 `username:password` 加密后的字符串。

Linux下用base64算法对字符串进行加密的命令为：

```
$ echo -n "admin:Harbor12345" | base64
YWRtaW46SGFyYm9yMTIzNDU=
```

比如我们用admin用户去查询harbor中的所有用户，则请求为

```
curl -H "Authorization: Basic YWRtaW46SGFyYm9yMTIzNDU=" http://ip:port/api/users
```


---

# Agent Instructions: 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:

```
GET https://pshizhsysu.gitbook.io/harbor/shi-yong.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
