Restful API
SwarmCloud’s API follows the REST principles. It has predictable resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.
BASE URL
- European cluster
https://cgi.cdnbye.com/v1
- Hongkong cluster
https://cgi.swarmcloud.net/v1
- American cluster
https://cgi.hdtvcloud.com/v1
Rate limiting: 2000 requests per minute
Get Token
You can use this API to get the token with your account
POST /user/token
POST Body
Name | Type | Description | Required |
---|---|---|---|
string | User email | Yes | |
passwd | string | The sha256 encrypted string of raw password | Yes |
Response
Status: 200
{
"ret": 0,
"name": "token",
"data":
{
"id": 001,
"token": "xxxxxx"
}
}
Name | Type | Description | |
---|---|---|---|
id | int | User ID | |
token | string | User token, will expire in 14days |
Get Domain List
You can use this API to get all domain/APP list of a user
GET /user/user_id/{user_id}/domain
HTTP Header
Name | Type | Description | Required |
---|---|---|---|
MyToken | string | The token of user | Yes |
Query
Name | Type | Description | Required |
---|---|---|---|
page | int | The specific page number | Yes |
page_size | int | The specific page size | Yes |
Response
Status: 200
{
"ret": 0,
"name": "domain"
"data":
[
{
"id": 001,
"domain": "xxx.com",
"uid": 001,
"native": false,
"isValid": false
}
]
}
Name | Type | Description | |
---|---|---|---|
id | int | Domain/APP ID | |
domain | string | Domain name or AppId | |
uid | int | User ID | |
native | bool | Is native application | |
isValid | bool | Is domain verified |
Set TimeZone
You can use this API to set the timezone
GET /user/user_id/{user_id}/timezone
HTTP Header
Name | Type | Description | Required |
---|---|---|---|
MyToken | string | The token of user | Yes |
Path Parameters
Name | Type | Description | Required |
---|---|---|---|
user_id | string | User ID | Yes |
POST Body
Name | Type | Description | Required |
---|---|---|---|
utc | int | The UTC offset of your timezone | Yes |
Get Realtime Information
You can use this API to get realtime information of a specific or all domain/APP
GET /user/user_id/{user_id}/domain/domain_id/{domain_id}
HTTP Header
Name | Type | Description | Required |
---|---|---|---|
MyToken | string | The token of user | Yes |
Path Parameters
Name | Type | Description | Required |
---|---|---|---|
user_id | string | User ID | Yes |
domain_id | string | Domain ID("0" means to get the summary data of all domain/APP) | Yes |
Response
Status: 200
{
"ret": 0,
"name": "domain",
"data":
{
"num_rt": 456,
"num_max": 892,
"traffic_p2p_day": 1022794195,
"traffic_http_day": 1022794195,
"api_frequency_day": 14805,
}
}
Name | Type | Description | |
---|---|---|---|
num_rt | int | Current Online Viewers | |
num_max | int | Peak Concurrent Viewers | |
traffic_p2p_day | int | P2P Traffic Today (KB) | |
api_frequency_day | int | Playback Sessions Today |
Get Historical P2P Traffic
You can use this API to get historical p2p traffic for a specific time period
GET /user/user_id/{user_id}/domain/domain_id/{domain_id}/p2p
HTTP Header
Name | Type | Description | Required |
---|---|---|---|
MyToken | string | The token of user | Yes |
Path Parameters
Name | Type | Description | Required |
---|---|---|---|
user_id | string | User ID | Yes |
domain_id | string | Domain ID("0" means to get the summary data of all domain/APP) | Yes |
Query
Name | Type | Description | Required |
---|---|---|---|
start_ts | int | The start timestamp(UTC+8) | Yes |
end_ts | int | The end timestamp(UTC+8) | Yes |
gran | int | Always equal to 1440 | Yes |
Response
Status: 200
{
"ret": 0,
"name": "statistic",
"data":
{
"max":
{
"ts": 1591372800,
"value": 541188637412
},
"list":
[
{"ts":1590854400,"value":1591200000},
{"ts":1590940800,"value":194511284034},
{"ts":1591027200,"value":541188637412}
]
}
}
Name | Type | Description | |
---|---|---|---|
max | object | The max value of all data | |
list | array | The array of all data | |
ts | int | Timestamp | |
value | int | P2P traffic(KB) |
Get Historical Online Viewers
You can use this API to get historical online viewers for a specific time period
GET /user/user_id/{user_id}/domain/domain_id/{domain_id}/num
HTTP Header
Name | Type | Description | Required |
---|---|---|---|
MyToken | string | The token of user | Yes |
Path Parameters
Name | Type | Description | Required |
---|---|---|---|
user_id | string | User ID | Yes |
domain_id | string | Domain ID("0" means to get the summary data of all domain/APP) | Yes |
Query
Name | Type | Description | Required |
---|---|---|---|
start_ts | int | The start timestamp(UTC+8) | Yes |
end_ts | int | The end timestamp(UTC+8) | Yes |
gran | int | Must be an integer multiple of 5 minutes | Yes |
Response
Status: 200
{
"ret": 0,
"name": "statistic",
"data":
{
"max":
{
"ts": 1591372800,
"value": 109566
},
"list":
[
{"ts":1590854400,"value":66504},
{"ts":1590940800,"value":72373},
{"ts":1591027200,"value":78300}
]
}
}
Name | Type | Description | |
---|---|---|---|
max | object | The max value of all data | |
list | array | The array of all data | |
ts | int | Timestamp | |
value | int | Online viewers |
Enable/Disable P2P
If you bind multiple domain names/APPID in one account, those which open P2P services share traffic packets together. You can save on packet consumption by shutting down P2P services of one or several domain names.
POST /user/user_id/{user_id}/domain/domain_id/{domain_id}/control
HTTP Header
Name | Type | Description | Required |
---|---|---|---|
MyToken | string | The token of user | Yes |
Path Parameters
Name | Type | Description | Required |
---|---|---|---|
user_id | string | User ID | Yes |
domain_id | string | Domain ID | Yes |
POST Body
Name | Type | Description | Required |
---|---|---|---|
disable | bool | Set true disable p2p or false to enable p2p | Yes |
Response
Status: 200
{
"ret":0,
"name":"control",
"data":
{
"allow":true,
"succeed":true
}
}