Skip to main content

API Usage

You can use the API of Arvancloud’s products when you have received a Machine User key from your user panel. Then, you can change and manage these products through HTTP requests.

Here, we will go through sample API requests in curl commands. In all of the provided samples, the MAchin User Key is shown by MU-KEY.

If you try to access a product or send a request with a nonexistent API key, you will be shown this error:

{
"message": "Unauthenticated."
}

Make sure that you copy and paste your Access key correctly.

Using Arvancloud CDN’s API

Here, we will go through a few sample API requests of our CDN service.

Sample: Get The Registered Domains List

To see all registered domains in your account, you must send a Get request to /domains.

curl --location --request GET 'https://napi.arvancloud.ir/cdn/4.0/domains' \
--header 'Accept: application/json' \
--header 'Authorization: <MU-KEY>'

Sample: Get The DNS Records of a Domain

To see the list of all registered domains in your account, you must send a GET request to /domains/{domain}/dns-records.

curl --location --request GET 'https://napi.arvancloud.ir/cdn/4.0/domains/example.com/dns-records' \
--header 'Accept: application/json' \
--header 'Authorization: <MU-KEY>'

Sample: Register a New Domain

To register, you must send a POST request to /domains/dns-service. Read the Domain Registration API document to learn more about defining the parameters of this request.

curl --location --request POST 'https://napi.arvancloud.ir/cdn/4.0/domains/dns-service' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: <MU-KEY>' \
--data-raw '{
"domain": "www.example.com",
"domain_type": "full"
}'

Using Arvancloud Cloud Server’s API

Here are a few API requests for this particular service.

Sample: Get the Instance List of a Data Center

To see all of the created instances of your account, send a GET request to /regions/{region}/servers. Go to the Cloud Server API document to get the region values.

curl --location --request GET 'https://napi.arvancloud.ir/ecc/v1/regions/ir-thr-c2/servers' \
--header 'Accept: application/json' \
--header 'Authorization: <MU-KEY>'

Sample: Get All Images and OS of a Data Center

To check and see the list of all the images in your account, you need to send a GET request to /regions/{region}/images. To check and get the region values, refer to the Cloud Server API document.

curl --location --request GET 'https://napi.arvancloud.ir/ecc/v1/regions/ir-thr-c2/images' \
--header 'Accept: application/json' \
--header 'Authorization: <MU-KEY>'

Sample: Create an Instance In a Data Center

You must send POST request to /regions/{region}/servers. Go to this API’s document page to learn how to define the parameters.

In this sample, after sending the request, we create an instance with ubuntu OS in the public network with the 75-2-2 values and the default firewall settings to receive the list of OS, networks, packages, and firewall groups of the account.

curl --location --request GET 'https://napi.arvancloud.ir/ecc/v1/regions/ir-thr-c2/images' \
--header 'Accept: application/json' \
--header 'Authorization: <MU-KEY>'

Using Arvancloud Video Platform’s API

Here are some samples to get to know the API structure.

Sample: Get Channel’s list

You can access all of the channels’ details of your account by sending a GET request to /channels.

curl --location --request GET 'https://napi.arvancloud.ir/vod/2.0/channels' \
--header 'Authorization: <MU-KEY>'

Sample: Create a new channel

To create one, you must send a POST request to channels/. Read the document of Create New Channel’s API to learn about the parameters.

curl --location --request POST 'https://napi.arvancloud.ir/vod/2.0/channels' \
--header 'Content-Type: application/json' \
--header 'Authorization: <MU-KEY>' \
--data-raw '{
"title": "test",
"description": "optional",
"secure_link_enabled": false,
"secure_link_key": "something ",
"secure_link_with_ip": true,
"ads_enabled": false,
"present_type": "manual",
"campaign_id": "{id}"
}'

Using Arvancloud Object Storage's API

In this section, to get familiar with the structure and how to use the API, we examine some examples of Object Storage API requests.

Sample: Get an Object from a Bucket

To get an object, we can send a GET request in the form of a script:

S3KEY="Accesskey"
S3SECRET="Secretkey" # pass these in

function getObject
{
bucket='Bucketname'
file="Filename"
date=$(date +"%a, %d %b %Y %T %z")
string="GET\n\n\n$date\n/$bucket/$file"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64)
curl -X GET \
-H "Host: $bucket.s3.ir-thr-at1.arvanstorage.ir" \
-H "Date: $date" \
-H "Authorization: AWS ${S3KEY}:$signature" \
"https://s3.ir-thr-at1.arvanstorage.ir/$file"
}

getObject

Sample: Get a Bucket's Object List

To get the list of files in a bucket, we can send a GET request in the form of a script:

S3KEY="Accesskey"
S3SECRET="Secretkey"

function listObjects
{
bucket='Bucketname'
date=$(date +"%a, %d %b %Y %T %z")
string="GET\n\n\n$date\n/$bucket/"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64)
curl -X GET \
-H "Host: $bucket.s3.ir-thr-at1.arvanstorage.ir" \
-H "Date: $date" \
-H "Authorization: AWS ${S3KEY}:$signature" \
"https://$bucket.s3.ir-thr-at1.arvanstorage.ir"
}

listObjects

Sample: Create a New Bucket

To create a new bucket using API, you must send a PUT request:

S3KEY="Accesskey"
S3SECRET="Secretkey"

function createBucket
{
bucket=$1
date=$(date +"%a, %d %b %Y %T %z")
string="PUT\n\n\n$date\n/$bucket/"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64)
curl -X PUT \
-H "Host: $bucket.s3.ir-thr-at1.arvanstorage.ir" \
-H "Date: $date" \
-H "Authorization: AWS ${S3KEY}:$signature" \
"https://s3.ir-thr-at1.arvanstorage.ir/"
}

createBucket "$1"

Check the API documentation to learn more about other Arvancloud products’ API requests.