Skip to main content

Using the API

Once you have an access key from the panel, you can use the API of Arvancloud products to make changes and run operations on each feature with HTTP requests.

In this guide, we look at examples of API requests as curl commands. In all examples, MU-KEY is used in place of the machine user access key.

If you try to send a request with a machine user key that doesn't exist or doesn't have access to a specific product, you get the following error:

{
"message": "Unauthenticated."
}

Make sure you copy and paste your machine user's access key correctly.

Using the CDN API​

In this section, to get familiar with the API structure, we look at a few examples of CDN API requests.

Example: Getting the List of Registered Domains​

To see the list of all domains registered in your account, 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>'

Example: Getting a Domain's DNS Records​

To see the list of DNS records of a domain in your account, send a GET request to /domains/domain/dns-records.

Replace domain with your domain name.

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

Example: Registering a New Domain​

To register a new domain in your account, send a POST request to /domains/dns-service. To review and define the parameters of this request, see the domain registration API documentation.

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 the Cloud Server API​

In this section, to get familiar with the API structure, we look at a few examples of Cloud Server API requests.

Example: Getting the List of Servers in a Data Center​

To see the list of all servers created in your account, send a GET request to /regions/region/servers. To get the values of region, see the Cloud Server API documentation.

Replace region with the data center name.

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

Example: Getting the List of Images and Operating Systems in a Data Center​

To see the list of all images available in your account, send a GET request to /regions/region/images. To get the values of region, see the Cloud Server API documentation.

Replace region with the data center name.

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

Example: Creating a Server in a Data Center​

To create a new server in a data center, send a POST request to /regions/region/servers. To review and define the parameters of this request, see the documentation for this API request.

In this example, after sending requests to get the account's operating systems, networks, plans, and firewall groups, we create a server with the Ubuntu operating system on the public network, with the 75-2-2 plan and the default firewall group.

curl --location --request POST 'https://napi.arvancloud.ir/ecc/v1/regions/nl-ams-su1/servers' \
--header 'Authorization: <MU-KEY>' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "abrak",
"network_id": "fe9645fc-2234-4865-895b-e3bb4bb0eb7b",
"flavor_id": "g1-2-2-75",
"image_id": "8751dd0c-6529-44a9-afec-2a1b29411116",
"security_groups": [
{
"name": "054f34d8-f4c1-45bc-ba4e-bcb8c00f17f6"
}
],
"ssh_key": true,
"key_name":"testkey",
"count": 1
}'

Using the Video Platform API​

In this section, to get familiar with the API structure, we look at a few examples of video service API requests.

Example: Getting the List of Video Channels​

To get the details of all channels created in your account, you can send a GET request to /channels.

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

Example: Getting the List of Videos in a Channel​

After getting the list of channels, to see the list of videos in a channel, send a GET request to /channels/channel-id/videos using the ID of the channel you want.

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

Example: Creating a New Channel​

To create a new channel, send a POST request to /channels. To review and define the parameters of this request, see the API documentation for creating a new channel.

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 the Object Storage API​

In this section, to get familiar with the structure and use of the API, we look at a few examples of Object Storage API requests.

Example: Getting an Object from a Bucket​

To get an object, we can send a GET request in 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

Example: Getting the List of Objects in a Bucket​

To get the list of files in a bucket, we can send a GET request in 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

Example: Creating a New Bucket​

To create a bucket with the API, you need to 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"

We recommend using the SDK of this service to work with Arvancloud Object Storage.