Advanced Hosting stands with Ukraine. Here’s how you can help our country win with just several clicks
To use API you must get API token.
The document contains a cache API description presented as curl commands with parameters. Also, there are variables needed for mentioned commands work. All the code could be executed in shell or added to sh-script. Naturally, the code could be adapted to any programming language.
Variables, needed for all the commands work: export API_URL=”https://api.websa.com” export ACCESS_TOKEN=”ExAmPlEeXaMpLeExAmPlEeXa”
ACCESS_TOKEN could be retrieved in Websa interface section Settings->API ( https://websa.advancedhosting.com/api ) after pressing CREATE NEW TOKEN link and creating the token. Then it is needed to press the menu button (three vertical dots) on the newly created token, press “Copy token” and copy it.
So, commands:
curl -X GET “$API_URL/v2/pull_zones” \ -H “Accept: application/json” \ -H “Authorization: Bearer $ACCESS_TOKEN”
The next commands will be related to a definite pull zone. That’s why we need to find the ID of the pull zone in the previously retrieved list and add it to the variable PULL_ZONE_ID. This ID also could be found in the link of pull zone settings, like https://websa.advancedhosting.com/cdn/abcdef01-2345-6789-abcd-ef0123456789
export PULL_ZONE_ID=”abcdef01-2345-6789-abcd-ef0123456789″
curl -X DELETE “$API_URL/v2/pull_zones/$PULL_ZONE_ID/cache” \ -H “Accept: application/json” \ -H “Authorization: Bearer $ACCESS_TOKEN”
Path should be inserted in path array in the POST (POST is JSON-formatted) Path should begin from the / sign.
curl -X DELETE “$API_URL/v2/pull_zones/$PULL_ZONE_ID/cache” \ -H “Accept: application/json” \ -H “Authorization: Bearer $ACCESS_TOKEN” \ -H “Content-Type: application/json” \ -d ‘{ “paths”: “/file1.txt”, “/file2.txt” }’
It is better to create less “Purge by full path” tasks but with more paths in each – in this case deleting will work more effectively.
Manage CDN Resource
Token for X-Auth-Token header could be retrieved in Websa interface section Settings->API ( https://websa.advancedhosting.com/api ) after pressing CREATE NEW TOKEN link and creating the token. Then it is needed to press menu button (three vertical dots) on newly created token, press “Copy token” and copy it.
So, the API: http://cdn80233383.ahacdn.me/docs/API_%20PullZones.pdf
Manage User Domains
Token for X-Auth-Token header could be retrieved in Websa interface section Settings->API ( https://websa.advancedhosting.com/api ) after pressing CREATE NEW TOKEN link and creating the token. Then it is needed to press menu button (three vertical dots) on newly created token, press “Copy token” and copy it.
:pull_zone_id – the ID of pull-zone, it could be found in the link of pull zone settings, like https://websa.advancedhosting.com/cdn/abcdef01-2345-6789-abcd-ef0123456789 :custom_domain_id – the ID of custom domain, it could in the link of certificate configuration, like https://websa.advancedhosting.com/cdn/abcdef01-2345-6789-abcd-ef0123456789/domains/abcdef01-2345-6789-abcd-ef0123456789/pullZoneSSL (the second id).
So, the API: http://cdn80233383.ahacdn.me/docs/API_%20CustomDomains.pdf
Manage SSL Certificates
Token for X-Auth-Token header could be retrieved in Websa interface section Settings->API ( https://websa.advancedhosting.com/api ) after pressing CREATE NEW TOKEN link and creating the token. Then it is needed to press menu button (three vertical dots) on newly created token, press “Copy token” and copy it.
:pull_zone_id – the ID of pull-zone, it could be found in the link of pull zone settings, like https://websa.advancedhosting.com/cdn/abcdef01-2345-6789-abcd-ef0123456789 :custom_domain_id – the ID of custom domain, it could in the link of certificate configuration, like https://websa.advancedhosting.com/cdn/abcdef01-2345-6789-abcd-ef0123456789/domains/abcdef01-2345-6789-abcd-ef0123456789/pullZoneSSL (the second id).
So, the API: http://cdn80233383.ahacdn.me/docs/API_%20SSL%20Сertificate.pdf
Statistics
Token for X-Auth-Token header could be retrieved in Websa interface section Settings->API ( https://websa.advancedhosting.com/api ) after pressing CREATE NEW TOKEN link and creating the token. Then it is needed to press the menu button (three vertical dots) on newly created token, press “Copy token” and copy it.
curl -X GET “https://api.websa.com/api/v1/pull_zones/statistics?type=:type&date=:date&period=:period&records_format=array” -H “X-Auth-Token: token” :type – statistics type. Possible types: traffic, hybrid, bandwidth. :date – date of statistics. Format: 2018-03-25. :period – period of statistics. possible values: day, month, year. :records_format – format of returned data. Possible values: array, plain. :pull_zone_id – optional parameter that represents pull zone to get statistics for.
Example:
Query: curl -X GET “https://api.websa.com/api/v1/pull_zones/statistics?type=bandwidth&date=2018-04-10&period=day&records_format=array” -H “X-Auth-Token: qpq5vJvHCxRKFR6uyGmbaK2p”
Answer: { “fields”:”total_bandwidth”, “records”:{“total_bandwidth”:0,”date”:”2018-04-10T00:00:00.000Z”}, {“total_bandwidth”:0,”date”:”2018-04-10T00:05:00.000Z”}, …, {“total_bandwidth”:0,”date”:”2018-04-10T23:50:00.000Z”}, {“total_bandwidth”:0,”date”:”2018-04-10T23:55:00.000Z”}, “summary”:{} }