File size: 2,881 Bytes
942a4ce
03cdf80
 
 
 
942a4ce
03cdf80
942a4ce
 
 
03cdf80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
title: Zone.ID Domain Registration API
emoji: 🌐
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
---

# Zone.ID Domain Registration API

A REST API for automating zone.id and nett.to domain registration with automatic account management.

## Features

- **Domain Registration**: Create subdomains on zone.id and nett.to
- **DNS Management**: Create, update, and delete A and CNAME records
- **Auto-Account Creation**: Automatically creates new accounts when domain limits are reached
- **Token Auto-Refresh**: Automatically refreshes tokens every 6 hours to prevent expiration

## API Endpoints

All endpoints require `X-API-Key` header for authentication.

### Health Check
- `GET /health` - Check API status
- `GET /docs` - Swagger API documentation

### Accounts (`/api/accounts`)
- `GET /` - List all accounts
- `POST /` - Create a new account
- `GET /:id` - Get account details
- `PATCH /:id` - Update account
- `DELETE /:id` - Delete account
- `POST /:id/refresh-token` - Manually refresh account token
- `POST /refresh-all-tokens` - Refresh tokens for all accounts

### Domains (`/api/domains`)
- `GET /` - List all domains
- `POST /` - Register a new domain
- `GET /:id` - Get domain details
- `DELETE /:id` - Delete domain

### DNS Records (`/api/dns`)
- `GET /:domainId/records` - List DNS records
- `POST /:domainId/records` - Create DNS record (A/CNAME)
- `PUT /:domainId/records/:recordId` - Update record
- `DELETE /:domainId/records/:recordId` - Delete record
- `POST /:domainId/sync` - Sync records from Zone.ID

## Environment Variables

Required:
- `DATABASE_URL` - PostgreSQL connection string

Optional:
- `PORT` - Server port (default: 7860)
- `HOST` - Server host (default: 0.0.0.0)

## Usage Example

```bash
# Create a domain
curl -X POST https://your-space.hf.space/api/domains \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"subdomain": "myapp", "suffix": "zone.id"}'

# Create an A record
curl -X POST https://your-space.hf.space/api/dns/{domainId}/records \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"type": "A", "hostname": "@", "content": "1.2.3.4"}'

# Create a CNAME record
curl -X POST https://your-space.hf.space/api/dns/{domainId}/records \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"type": "CNAME", "hostname": "www", "content": "example.com"}'
```

## Token Auto-Refresh

The API automatically refreshes Zone.ID tokens every 6 hours to prevent the 3-day expiration. You can also manually trigger a refresh:

```bash
# Refresh specific account token
curl -X POST https://your-space.hf.space/api/accounts/{accountId}/refresh-token \
  -H "X-API-Key: your-api-key"

# Refresh all account tokens
curl -X POST https://your-space.hf.space/api/accounts/refresh-all-tokens \
  -H "X-API-Key: your-api-key"
```