Add a public key¶
POST /api/v5/user/keys
Call this endpoint to add a public key.
Supported access tokens¶
- AtomGit user access token (AtomGit user access tokens)
Anonymous access¶
This endpoint does not allow anonymous access.
Request parameters¶
| Parameter | Location | Type | Required | Description |
|---|---|---|---|---|
access_token |
query | string | Yes | User authorization code |
Request Body:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"key": {
"description": "Public key content",
"type": "string"
},
"title": {
"description": "Public key name",
"type": "string"
}
},
"required": ["key", "title"]
}
Response parameters¶
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
id |
integer | Yes | — | Public key ID |
title |
string | Yes | — | Public key name |
key |
string | Yes | — | Public key content |
created_at |
string | Yes | — | Public key creation time |
url |
string | Yes | — | Public key URL |
Error response¶
400 Invalid parameters
401 Unauthenticated
The actual error field names returned by the backend take precedence.
HTTP status codes¶
| Status code | Description |
|---|---|
200 |
Success (OK) |
304 |
Not modified |
401 |
Requires authentication |
403 |
Forbidden |
Request example¶
Parameter notes¶
The placeholders in the example:
<token>— Replace with your AtomGit user access token;<title>— Replace with the public key name;<key>— replace with the public key content (such asssh-ed25519 AAAA... user@host).
cURL¶
curl -X POST 'https://api.atomgit.com/api/v5/user/keys?access_token=<token>' \
-H 'Content-Type: application/json' \
-d '{
"title": "<title>",
"key": "<key>"
}'
JavaScript¶
// Native fetch (Node.js 18+ / browser)
const response = await fetch("https://api.atomgit.com/api/v5/user/keys?access_token=<token>", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify({
title: "<title>",
key: "<key>",
}),
});
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.post(
"https://api.atomgit.com/api/v5/user/keys",
params={"access_token": "<token>"},
json={"title": "<title>", "key": "<key>"},
headers={"Accept": "application/json"},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
Response example¶
Status code: 200
{
"id": 311915,
"title": "555555",
"key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIa6IyTGuI8V5wrhANDFyezQqL73dY9ctLGHgpOggp7E Gitee",
"created_at": "2024-11-14T03:34:40.318+00:00",
"url": "https://api.atomgit.com/v5/user/keys/311915"
}
Error codes¶
| Error code | Description |
|---|---|
401 |
Unauthenticated or invalid credentials (missing or invalid access token) |
400 |
Invalid parameters or unparseable request |
404 |
Request path does not exist |
405 |
Request method not supported |
429 |
Too many requests; rate limit triggered |
500 |
Internal system error |
Markdown source: View on AtomGit·Content from the open-source project gitcode-dev/atomgit-api-doc