Skip to content

API for HTTP-resource

Description

This section describes API methods for creating, deleting and configurations changing of your resources. You will as well find here information on cache managing and statistical data receiving.

All the responses (including errors) return in JSON Format.

Attention!

You can make no more than:

  • 5 API requests per minute for HTTP resource configuring;
  • 125 API requests per minute for cache management.

Find below examples for monitoring and configuring of the options in connection with HTTP-caching service.

General configuration

Find below an example of general configuration, while in the following sections the particular examples will be clarified.

        http resource json object (HRJO) - data from request/response
        HRJO structure and keys:
        { 
            id <string> - uid of resource (used in api url)
            name <string> - identificator for web UI (required)
            origin <json> - section for traffic origin description (required)
            certificate <integer> - id of created certificate
            names <json> - section for names description
            robots <json> - section for robots file description
            headers <json> - section for specific headers description
            cache <json> - section for cache options description
            client_cache <json> - section for extra cache options description
            auth <json> - section for auth options description
            cors <json> - section for cors description
            modern_tls_only <boolean> - use only modern versions of TLS
            locations <json> - section for locations description
        }  

origin section

        {
            https <boolean> - use or not https during requests to origin
            hostname <string> - set host header during requests to origin
            servers <json> - client nodes description
        }

servers section

        {
            <client_domain/ip_address>: client node address <json>
        }

client node address section

        {
            port <integer> - client node port (default 80 and 443)
            weight <integer> - load balancing parameters
            read_timeout <integer> - load balancing parameters
            send_timeout <integer> - load balancing parameters
            connect_timeout <integer> - load balancing parameters
            max_fails <integer> - load balancing parameters
            backup <boolean> - use node only in backup mode
        }

names section

        list of string cnames, f.e. [‘alias1.client.cdn.ru’]

robots section

        {
            type <string> - ‘deny’, ‘custom’ or ‘cached’
            content <string> - client’s robots.txt text (only for ‘custom’ type)
        }

headers section

        {
            request <json> - headers for requests to origin
            response <json> - header for customer responses
        }

request headers section

        {
            <header_name>: <header_value>
        }

response headers section

        {
            <header_name>: <header_value>
        }

cache section

        {
            disable <boolean> - do not cache content
            consider_args <boolean> - use querystring while cache process
            valid <json> - time of caching
        }

valid section

        {
            2xx <string> - cache ttl for 2xx response codes
            3xx <string> - cache ttl for 3xx response codes
            4xx <string> - cache ttl for 4xx response codes
            5xx <string> - cache ttl for 5xx response codes
            force <boolean> - force cache update on clientside
        }

client cache section

        {
            expires <integer> - expire cache time
        }

cors section

        {
            disable <boolean> - disable cors (default: false)
            domains <list of strings> - list of allowed domains
            headers <list of strings> - list of secure request headers (Accept, Accept-Language, Content-Type, Content-Language are allowed by default)
            expose <list of strings> - list of upper level API accessible headers (Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma are allowed by default)
            methods <list of strings> - list of safe methods (GET, HEAD, POST are allowed by default)
            max_age <integer> - preflight request response lifetime
            credentials <boolean> - set an Access-Control-Allow-Credentials header
        }

locations section

        {
            key <string> - path to content: locations params <json>
        }

locations params section

        {
            headers <json> - like global section
            cache <json> - like global section
            client_cache <json> - like global section
            auth <json> - like global section
            cors <json> - like global section
        }

Minimal Configuration

Example of Minimal Configuration with origin example.com

        {
             "name": "example", 
             "origin": {
             "servers": {
             "example.com": {}
                }
             },    

        }

In this case CDNvideo network will cache all the static content example.com, using the default settings.

Configuring for HTTP resource

Get all resources

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/resource/http/

  • Method: GET
  • Headers: CDN-AUTH-TOKEN
  • Response Data Type: JSON Array or JSON Object in case of error
Status Code Response Data Response Format Description
200 All HTTP resources configured in specified account or error description JSON Response with list of resources or error
403 None None Forbidden
404 None None Not Found
500 None None Internal Server Error
503 None None Service Unavailable

Request example

curl -H 'cdn-auth-token:cdn2_OSKVHEJCGDOPEQJJXQN284ZTQUEPJ2' https://api.cdnvideo.ru/cdn/api/v1/<account_name>/resource/http/

Successful response example

[{"origin": {"https": false, "servers": {"test.test.te": {"backup": false, "port": 80, "weight": 1}}}, "cdn_domain": "krvdpfc0t0.a.trbcdn.net", "name": "default2", "active": true, "cache": {"consider_args": false}, "robots": {"type": "deny"}, "names": [], "id": "krvdpfc0t0"}, {"origin": {"https": false, "servers": {"test.test.tet": {"backup": false, "port": 80, "weight": 1}}}, "cdn_domain": "zm4rrn4mkt.a.trbcdn.net", "name": "default", "active": true, "cache": {"consider_args": false}, "robots": {"type": "custom", "robotsContent": "1\n"}, "names": [], "id": "zm4rrn4mkt"}]

Unsuccessful response example

{"status": "error", "message": "Not allowed method", "description": "Request is forbidden"}

Attention

To get deactivated resources, use the query parameter "active" with the value "false"

Get specific resource

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/resource/http/<resource_id>

  • Method: GET
  • Headers: CDN-AUTH-TOKEN
  • Response Data Type: JSON Object
Status Code Response Data Response Format Description
200 HTTP resource configured in specified account or error description JSON Response with resource or error
403 None None Forbidden
404 None None Not Found
500 None None Internal Server Error
503 None None Service Unavailable

Request example

curl -H 'cdn-auth-token:cdn2_OSKVHEJCGDOPEQJJXQN284ZTQUEPJ2' https://api.cdnvideo.ru/cdn/api/v1/<account_name>/resource/http/<resource_id>

Successful response example

{"origin": {"https": false, "servers": {"test.test.te": {"backup": false, "port": 80, "weight": 1}}}, "cdn_domain": "krvdpfc0t0.a.trbcdn.net", "name": "default2", "active": true, "cache": {"consider_args": false}, "robots": {"type": "deny"}, "names": [], "id": "krvdpfc0t0"}

Unsuccessful response example

{"status": "error", "message": "Invalid Token", "description": "Invalid or expired token"}

Attention

To get deactivated resource, use the query parameter "active" with the value "false"

Create resource

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/resource/http/

  • Method: POST
  • Headers: CDN-AUTH-TOKEN
  • Request Data: JSON with resource data
  • Response Data Type: JSON Object
Status Code Response Data Response Format Description
200 task_id, resource_id or error description JSON Created, id of task in global task queue or error
400 None None Bad Request
404 None None Not Found
500 None None Internal Server Error
503 None None Service Unavailable

Request example

curl -H 'cdn-auth-token:cdn2_2YXPIWIYRT15SZGQ2Q0JN362PUDXIE' 
  -X POST 
  -d '{"origin": {"servers": {"<origin_host>": {"port": 80}}},  "name": "<resource_name>"}'
  https://api.cdnvideo.ru/cdn/api/v1/<account_name>/resource/http/

Successful response example

{"status": "accept", “task_id": "20180402162358692400", "resource_id": "v7sdnx3ytm"}

Unsuccessful response example

{"status": "error", "message": "value invalid name", "description": "Json invalid name is not uniq in account <account_name>"}

Update resource

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/resource/http/<resource_id>

  • Method: PATCH
  • Headers: CDN-AUTH-TOKEN
  • Request Data: JSON with new resource data
  • Response Data Type: JSON Object
Status Code Response Data Response Format Description
200 task_id or error description None Updated, id of task in global task queue or error
400 None None Bad Request
404 None None Not Found
500 None None Internal Server Error
503 None None Service Unavailable

Request example

curl -H 'cdn-auth-token:cdn2_2YXPIWIYRT15SZGQ2Q0JN362PUDXIE'
  -X PATCH
  -d '{"origin": {"servers": {"<new_origin_host>": {"port": 80}}},  "name": "<new_resource_name>"}'
  https://api.cdnvideo.ru/cdn/api/v1/<account_name>/resource/http/<resource_id>

Successful response example

{"status": "accept", “task_id": "20180402162358692401"}

Unsuccessful response example

{"status": "error", "message": "Json invalid", "description": "Key incorrect or not found ( origin )"}

Deactivate resource

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/resource/http/<resource_id>

  • Method: PATCH
  • Headers: CDN-AUTH-TOKEN
  • Response Data Type: JSON Object
Status Code Response Data Response Format Description
200 task_id or error description JSON Deactivated, id of task in global task queue or error
400 None None Bad Request
404 None None Not Found
500 None None Internal Server Error
503 None None Service Unavailable

Request example

curl -H 'cdn-auth-token:cdn2_2YXPIWIYRT15SZGQ2Q0JN362PUDXIE'
  -X PATCH
  -d '{"active": false, "origin": {"servers": {"<origin_host>": {"port": 80}}},  "name": "<resource_name>"}'
  https://api.cdnvideo.ru/cdn/api/v1/<account_name>/resource/http/<resource_id>

Successful response example

{"status": "accept", "task_id": "20180402162358692413"}

Unsuccessful response example

{"status": "error", "message": "Not allowed method", "description": "Request is forbidden"}

Activate resource

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/resource/http/<resource_id>

  • Method: PATCH
  • Headers: CDN-AUTH-TOKEN
  • Response Data Type: JSON Object
Status Code Response Data Response Format Description
200 task_id or error description JSON Activated, id of task in global task queue or error
400 None None Bad Request
404 None None Not Found
500 None None Internal Server Error
503 None None Service Unavailable

Request example

curl -H 'cdn-auth-token:cdn2_2YXPIWIYRT15SZGQ2Q0JN362PUDXIE'
  -X PATCH
  -d '{"active": true, "origin": {"servers": {"<origin_host>": {"port": 80}}},  "name": "<resource_name>"}'
  https://api.cdnvideo.ru/cdn/api/v1/<account_name>/resource/http/<resource_id>

Successful response example

{"status": "accept", "task_id": "20180402162358692413"}

Unsuccessful response example

```json {"status": "error", "message": "Not allowed method", "description": "Request is forbidden"}

Local authorization

Create resource with local authorization

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/resource/http/

  • Method: POST
  • Headers: CDN-AUTH-TOKEN
  • Request Data: JSON with resource data and local authorization parameters
  • Response Data Type: JSON Object
Status Code Response Data Response Format Description
200 task_id, resource_id or error description JSON Created, id of task in global task queue or error
400 None None Bad Request
404 None None Not Found
500 None None Internal Server Error
503 None None Service Unavailable

Request example

curl -H 'cdn-auth-token:cdn2_2YXPIWIYRT15SZGQ2Q0JN362PUDXIE' 
  -X POST 
  -d '{"auth": {"md5": {"secret": "123", "forever": true, "anywhere": true}}, "origin": {"servers": {"<origin_host>": {"port": 80}}},  "name": "<resource_name>"}'
  https://api.cdnvideo.ru/cdn/api/v1/<account_name>/resource/http/

Successful response example

{"status": "accept", “task_id": "20180402162358692400", "resource_id": "v7sdnx3ytm"}

Unsuccessful response example

{"status": "error", "message": "value invalid name", "description": "Json invalid name is not uniq in account <account_name>"}

Update resource local authorization

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/resource/http/<resource_id>

  • Method: PATCH
  • Headers: CDN-AUTH-TOKEN
  • Request Data: JSON with new parameters of local authorization
  • Response Data Type: JSON Object
Status Code Response Data Response Format Description
200 task_id or error description None Updated, id of task in global task queue or error
400 None None Bad Request
404 None None Not Found
500 None None Internal Server Error
503 None None Service Unavailable

Request example

curl -H 'cdn-auth-token:cdn2_2YXPIWIYRT15SZGQ2Q0JN362PUDXIE'
  -X PATCH
  -d '{"auth": {"md5": {"secret": "456", "forever": true}}, "origin": {"servers": {"<origin_host>": {"port": 80}}},  "name": "<resource_name>"}'
  https://api.cdnvideo.ru/cdn/api/v1/<account_name>/resource/http/<resource_id>

Successful response example

{"status": "accept", “task_id": "20180402162358692401"}

Unsuccessful response example

{"status": "error", "message": "Not allowed method", "description": "Request is forbidden"}

External authorization

Create resource with external authorization

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/resource/http/

  • Method: POST
  • Headers: CDN-AUTH-TOKEN
  • Request Data: JSON with resource data and external authorization parameters
  • Response Data Type: JSON Object
Status Code Response Data Response Format Description
200 task_id, resource_id or error description JSON Created, id of task in global task queue or error
400 None None Bad Request
404 None None Not Found
500 None None Internal Server Error
503 None None Service Unavailable

Request example

curl -H 'cdn-auth-token:cdn2_2YXPIWIYRT15SZGQ2Q0JN362PUDXIE'
  -X POST
  -d '{"auth": {"url": "https://test.com/yourscript"}, "origin": {"servers": {"<origin_host>": {"port": 80}}},  "name": "<resource_name>"}'
  https://api.cdnvideo.ru/cdn/api/v1/<account_name>/resource/http/

Successful response example

{"status": "accept", “task_id": "20180402162358692400", "resource_id": "v7sdnx3ytm"}

Unsuccessful response example

{"status": "error", "message": "value invalid name", "description": "Json invalid name is not uniq in account <account_name>"}

Update resource external authorization

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/resource/http/<resource_id>

  • Method: PATCH
  • Headers: CDN-AUTH-TOKEN
  • Request Data: JSON with new parameters of external authorization
  • Response Data Type: JSON Object
Status Code Response Data Response Format Description
200 task_id or error description None Updated, id of task in global task queue or error
400 None None Bad Request
404 None None Not Found
500 None None Internal Server Error
503 None None Service Unavailable

Request example

curl -H 'cdn-auth-token:cdn2_2YXPIWIYRT15SZGQ2Q0JN362PUDXIE'
  -X PATCH
  -d '{"auth": {"url": "https://test.com/yourscript2"}, "origin": {"servers": {"<origin_host>": {"port": 80}}},  "name": "<resource_name>"}'
  https://api.cdnvideo.ru/cdn/api/v1/<account_name>/resource/http/<resource_id>

Successful response example

{"status": "accept", “task_id": "20180402162358692401"}

Unsuccessful response example

{"status": "error", "message": "Not allowed method", "description": "Request is forbidden"}

Content distribution zones expansion

Adding more distribution zones via ChinaNetCenter Network (CDNvideo`s partner). Find more details about partner`s network coverage here

Get current configuration

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/cncconfiguration/<resource_id>

  • Method: GET
  • Headers: CDN-AUTH-TOKEN
  • Response Data Type: JSON Object
Status Code Response Data Response Format Description
200 code: type integer, message: type string, data: {areas: type list, certificate: type string or None, cnc_configured: type bool, is_changes_apply: type bool} JSON OK
401 None None Unauthorized
500 None None Internal Server Error

Possible values areas:

Value Description
am the USA
apac Asia and the Pacific
emea Europe, Middle East, Africa

Request example

curl -H 'cdn-auth-token: cdn2_P5OGFSL0USFFEW2NWU2VCKK79FQJU2'
https://api.cdnvideo.ru/cdn/api/v1/cpfgdakp/cncconfiguration/lajjncnn6d

Successful response example

{
  "message": "Ok",
  "code": 200,
  "data": {
    "is_changes_apply": true,
    "cnc_configured": true,
    "certificate": null,
    "areas": ["apac", "emea"]
  }
}

Add/Change distribution zones

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/cncconfiguration/<resource_id>

  • Method: POST
  • Headers: CDN-AUTH-TOKEN
  • Request Data: JSON with configuration data
  • Response Data Type: JSON Object

Request data description:

Parameter name Value Type Required
{areas, certificate} JSON Object Yes
areas Array, one or more from ("apac", "am", "emea") Yes
certificate String or None No

Possible response codes:

Status Code Response Data Response Format Description
200 message: type string, code: type integer JSON OK
400 None None Bad Request
401 None None Unauthorized
409 None None Conflict (previous changes haven`t been applied yet)

Request example

curl -X POST -d '{"areas": ["apac", "emea"]}'
-H 'cdn-auth-token: cdn2_P5OGFSL0USFFEW2NWU2VCKK79FQJU2'
https://api.cdnvideo.ru/cdn/api/v1/cpfgdakp/cncconfiguration/lajjncnn6d

Successful response example

{
  "message": "Ok",
  "code": 200
}

Disable additional distribution zones

URL: https://api.cdnvideo.ru/cdn/api/v1/<your_account_name>/cncconfiguration/<resource_id>

  • Method: POST
  • Headers: CDN-AUTH-TOKEN
  • Request Data: JSON with configuration data
  • Response Data Type: JSON Object

Request data description:

Parameter name Value Type Required
{areas, certificate} JSON Object Yes
areas Empty Array [ ] Yes
certificate String or None No

Possible response codes:

Status Code Response Data Response Format Description
200 message: type string, code: type integer JSON OK
400 None None Bad Request
401 None None Unauthorized
409 None None Conflict (previous changes haven`t been applied yet)

Request example

curl -X POST -d '{"areas": []}'
-H 'cdn-auth-token: cdn2_P5OGFSL0USFFEW2NWU2VCKK79FQJU2'
https://api.cdnvideo.ru/cdn/api/v1/cpfgdakp/cncconfiguration/lajjncnn6d

Successful response example

{
  "message": "Ok",
  "code": 200
}

Cache managing

Preloading or deleting files from cache as well as whole cache deletion.

These operations are performed asynchronously and their response contains task_id. You can check status of the task using task_id (described below).

Attention!

You can make no more than 125 API requests per minute for cache management.

Delete file

URL: https://api.cdnvideo.ru/app/cache/v2/objects?cdn_url=http://<domain>/path/to/file

Either the dedicated CDN domain <resource_id>.a.trbcdn.net or CNAME can be set as <domain>.

  • Method: DELETE
  • Headers: CDN-AUTH-TOKEN
  • Response Data Type: JSON Object

Query string parameters:

Parameter name Value Type Required
cdn_url Text Yes

Possible response codes:

Status Code Response Data Response Format Description
202 task_id: type string JSON OK
401 None None Access Denied
503 None None Service Unavailable

Request example

curl -X DELETE
-H 'cdn-auth-token:cdn2_G5LVU4LSC85AO2RAG4G1DL90I7CADR'
'https://api.cdnvideo.ru/app/cache/v2/objects?cdn_url=http://lajjncnn6d.a.trbcdn.net/aloha/cdn/sample_03.flv'

Successful response example

{
  "task_id": "f0f9601e75b2415db0e2219ea07d8fde"
}

Delete whole cache

URL: https://api.cdnvideo.ru/app/cache/v2/objects?cdn_url=http://<domain>/path/to/file&all

Either the dedicated CDN domain <resource_id>.a.trbcdn.net or CNAME can be set as <domain>.

  • Method: DELETE
  • Headers: CDN-AUTH-TOKEN
  • Response Data Type: JSON Object

Query string parameters:

Parameter name Value Type Required
cdn_url Text Yes
all No value Yes

Possible response codes:

Status Code Response Data Response Format Description
202 task_id: type string JSON OK
401 None None Access Denied
503 None None Service Unavailable

Request example

curl -X DELETE
-H 'cdn-auth-token:cdn2_G5LVU4LSC85AO2RAG4G1DL90I7CADR'
'https://api.cdnvideo.ru/app/cache/v2/objects?cdn_url=http://lajjncnn6d.a.trbcdn.net/aloha/cdn/sample_03.flv&all'

Successful response example

{
  "task_id": "ccf82df380a34fe7a4992ca810ccfee4"
}

Preload file

URL: https://api.cdnvideo.ru/app/cache/v2/objects?cdn_url=http://origin:port/path/to/file'

  • Method: PUT
  • Headers: CDN-AUTH-TOKEN
  • Response Data Type: JSON Object

Query string parameters:

Parameter name Value Type Required
cdn_url Text Yes

Possible response codes:

Status Code Response Data Response Format Description
202 task_id: type string JSON OK
401 None None Access Denied
503 None None Service Unavailable

Request example

curl -X PUT
-H 'cdn-auth-token:cdn2_G5LVU4LSC85AO2RAG4G1DL90I7CADR'
'https://api.cdnvideo.ru/app/cache/v2/objects?cdn_url=http://cache-cdntest.cdnvideo.ru/aloha/cdn/sample_03.flv'

Successful response example

{
  "task_id": "7a14702e80ec4b99ba5792ca9d781b3d"
}

Check status of task

URL: https://api.cdnvideo.ru/app/cache/v2/tasks?id=<task_id>

  • Method: GET
  • Headers: CDN-AUTH-TOKEN
  • Response Data Type: JSON Object

Possible response codes:

Status Code Response Data Response Format Description
200 task_description: type string, status: type string, date_started: type string, message: type string JSON OK
400 None None Bad Request
401 None None Access Denied
503 None None Service Unavailable

Request example

curl -X GET
-H 'cdn-auth-token:cdn2_G5LVU4LSC85AO2RAG4G1DL90I7CADR'
'https://api.cdnvideo.ru/app/cache/v2/tasks?id=7a14702e80ec4b99ba5792ca9d781b3d'

Successful response example

{
  "task_description": "PRELOAD http://cache-cdntest.cdnvideo.ru/aloha/cdn/sample_03.flv",
  "status": "completed",
  "date_started": "2018-11-27T09:55:11",
  "message": ""
}