Lyve Cloud Account API version 2 Guide
Lyve Cloud Account API version 2 

此內容是否有幫助?

Usage

This API is used to get historical storage usage of the account for the current month or specified time range.

Getting historical storage usage by month

The monthly average usage is calculated by averaging the daily average usage of all the days in that month. The monthly average usage is used to calculate the monthly cost at the end of the month.

 Note
  • Based on the time range, it returns zero (0) if the data is unavailable.
  • The data is displayed for a maximum interval of six months.

Request

The GET operation provides the account's monthly usage for a specified duration.

GET /usage/monthly

Parameters

Name In Type Required Description
fromMonth query Integer true Specifies the start month, inclusive, from which to retrieve usage data.

Where, zero corresponds to January and 11 corresponds to December.
fromYear query Integer true Specifies the start year, inclusive, from which to retrieve usage data.
toMonth query Integer true Specifies the end month, inclusive, from which to retrieve usage data.

Where, zero corresponds to January and 11 corresponds to December.
toYear query Integer true Specifies the end year, inclusive, from which to retrieve usage data.

Code samples

Go

    package main

    import (
        "bytes"
        "net/http"
    )

    func main() {
        headers := map[string][]string{
            "Accept": []string{
                "application/json",
            },
            "Authorization": []string{
                "Bearer {access-token}",
            },
        }
        data := bytes.NewBuffer([]byte{jsonReq})
        req, err := http.NewRequest("GET", "https://api.lyvecloud.seagate.com/v2/usage/monthly/", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... }

Java

    try {
        URL obj = new URL("https://api.lyvecloud.seagate.com/v2/usage/monthly/?from%2Dmonth=11&from%2Dyear=2020&to%2Dmonth=11&to%2Dyear=2020");
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("GET");
        int responseCode = con.getResponseCode();
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        System.out.println(response.toString());
    } catch (IOException e) { e.printStackTrace(); }

JavaScript

    const headers = {
        'Accept': 'application/json',
        'Authorization': 'Bearer {access-token}'
    };
    fetch('https://api.lyvecloud.seagate.com/v2/usage/monthly/?from%2Dmonth=11&from%2Dyear=2020&to%2Dmonth=11&to%2Dyear=2020', {
            method: 'GET',
            headers: headers
        })
        .then(function(res) {
            return res.json();
        }).then(function(body) { console.log(body); });

Python

    import requests
    headers = {
        'Accept': 'application/json',
        'Authorization': 'Bearer {access-token}'
    }
    r = requests.get('https://api.lyvecloud.seagate.com/v2/usage/monthly/', params = {
        'from-month': '11',
        'from-year': '2020',
        'to-month': '11',
        'to-year': '2020' }, headers = headers) print(r.json())

Ruby

    require 'rest-client'
    require 'json'
    headers = {
        'Accept' => 'application/json', 'Authorization' => 'Bearer {access-token}'
    }
    result = RestClient.get 'https://api.lyvecloud.seagate.com/v2/usage/monthly/', params: {
        'from-month' => '[monthNumber](#schemamonthnumber)',
        'from-year' => '[yearNumber](#schemayearnumber)',
        'to-month' => '[monthNumber](#schemamonthnumber)',
        'to-year' => '[yearNumber](#schemayearnumber)'
    }, headers: headers p JSON.parse(result)
  

Responses

Status Code Description Returned JSON Payload
200 OK

Successfully returns the data usage. Each item in return corresponds to one month.

If the account is a master account, the response includes usageByBucket returning data usage for every bucket in the master account, and it also includes usageBySubAccount, returning data usage for its available sub-accounts.

If the account is a sub-account, the response includes usageByBucket , returning data usage for every bucket in the sub-account. However, usageBySubAccount, is not returned, as there are no sub-accounts associated to another sub account.
{
    "usageByBucket": [
        {
            "year": 0,
            "month": 0,
            "totalUsageGB": 0,
            "buckets": [
                {
                    "name": "string",
                    "usageGB": 0
                }
            ]
        }
    ],
    "usageBySubAccount": [
        {
            "year": 0,
            "month": 0,
            "totalUsageGB": 0,
            "subAccounts": [
                {    
                    "subAccountName": "subname1",
                    "subAccountId": "string",
                    "usageGB": 0,
                    "createTime": "2022-10-16T14:02:20.319Z"
                }
            ]
        }
    ]
}
Field Description
year Usage of the account for selected year.
month Usage of the account for selected month.
name Name of the bucket.
usageGB Bucket consumption in GB.
totalUsageGB Total storage consumption in GB.
buckets Bucket consumption.
subAccounts Details of sub-account.
subAccountName Name of the sub-account.
subAccountId Unique identifier of a sub-account.
400 Bad Request
{
  "code": "string",
  "message": "string"
}
code message
TokenExpired Token expired.
InvalidToken Token is not valid.
InvalidTimeRange Invalid time range.
403 Forbidden

The account has no services enabled.
{
  "code": "string",
  "message": "string"
}
code message
NoServiceAvailable The account has no services enabled for it.
500 The server encountered an internal error.
{
  "code": "string",
  "message": "string"
}
code message
Internalerror The server encountered an internal error. Please retry the request.
503 Service Unavailable
{
  "code": "string",
  "message": "string"
}
code message
ServiceNotReady The server is not ready to handle the request. Please retry the request later.

Getting current month storage usage

This API returns the current month's storage usage and lists all buckets in the account and their calculated total usage size to the current date. In addition, you get the total number of buckets currently in the account and the total calculated usage.

 Note—Based on the time range, it returns zero (0) if the data is unavailable.

Request

The GET operation provides usage for the current month to date.

GET /usage/current

Code samples

Go

    package main

    import (
        "bytes"
        "net/http"
    )

    func main() {
        headers := map[string][]string{
            "Accept": []string{
                "application/json",
            },
            "Authorization": []string{
                "Bearer {access-token}",
            },
        }
        data := bytes.NewBuffer([]byte{jsonReq})
        req, err := http.NewRequest("GET", "https://api.lyvecloud.seagate.com/v2/usage/current/", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... }

Java

    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;

    public class Main {
        public static void main(String[] args) {
            try {
                URL obj = new URL("https://api.lyvecloud.seagate.com/v2/usage/current/");
                HttpURLConnection con = (HttpURLConnection) obj.openConnection();
                con.setRequestMethod("GET");
                int responseCode = con.getResponseCode();
                BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String inputLine;
                StringBuffer response = new StringBuffer();
                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }
                in.close();
                System.out.println(response.toString());
            } catch (Exception e) { e.printStackTrace(); } } }

JavaScript

    const headers = {
        'Accept': 'application/json',
        'Authorization': 'Bearer {access-token}'
    };

    fetch('https://api.lyvecloud.seagate.com/v2/usage/current/', {
        method: 'GET',
        headers: headers
    })
    .then(function(res) {
        if (!res.ok) {
            throw new Error(`HTTP error! status: ${res.status}`);
        }
        return res.json();
    })
    .then(function(body) {
        console.log(body);
    })
    .catch(function(error) { console.log('There was a problem with the fetch operation: ' + error.message); });

Python

    import requests

    headers = {
        'Accept': 'application/json',
        'Authorization': 'Bearer {access-token}'
    }

    try:
        r = requests.get('https://api.lyvecloud.seagate.com/v2/usage/current/', headers=headers)
        r.raise_for_status()
        print(r.json())
    except requests.exceptions.HTTPError as err:
        print(f"HTTP error occurred: {err}")
    except Exception as err:
        print(f"An error occurred: {err}")

Ruby

    require 'rest-client'
    require 'json'

    headers = {
        'Accept' => 'application/json',
        'Authorization' => 'Bearer {access-token}'
    }

    begin
        result = RestClient.get 'https://api.lyvecloud.seagate.com/v2/usage/current/', params: {}, headers: headers
        p JSON.parse(result)
    rescue RestClient::ExceptionWithResponse => e
        puts "An error occurred: #{e.message}"
    end
  

Responses

Status Code Description Returned JSON payload
200 OK

Successfully return usage data.

If the account is a master account, the response includes usageByBucket, returning data usage for every bucket in the master account, and it also includes usageBySubAccount, returning data usage for its available sub-accounts.

If the account is sub-account, the response includes usageByBucket, returning data usage for every bucket in the sub-account. However, usageBySubAccountis not returned, as there are no sub-accounts associated to another sub-account
{
    "usageByBucket": {
        "numBuckets": 0,
        "totalUsageGB": 0,
        "buckets": [
            {
                "name": "string",
                "usageGB": 0
            }
        ]
    },
    "usageBySubAccount": {
        "totalUsageGB": 0,
        "subAccounts": [
            {
                "subAccountName": "subname1",
                "subAccountId": "string",
                "usageGB": 0,
                "users": 0,
                "serviceAccounts": 0,
                "buckets": 0,
                "trial": 0,
                "createTime": "2022-10-16T14:06:51.494Z"
            }
        ]
    }
}
Field Description
numBuckets Number of buckets.
totalUsageGB Total storage consumption in GB.
buckets Bucket consumption.
name Bucket name.
usageGB Bucket consumption in GB
totalUsageGB Total usage of the master account, including the sub-accounts.
subAccounts Details of sub-account.
subAccountName Name of the sub-account.
subAccountId Unique identifier of a sub-account.
usageGB Usage of the account in GB.
users Lists the total number of users for each sub-account.
serviceAccounts Lists the number of service accounts for each sub-account.
buckets Total number of buckets created in the Sub-account.
trial Remaining number of days for the trial to expire. If the trial is not provisioned for the account, then the trial is -1.
createTime Date and time when the Sub-account is created.
400 The token is not valid or is expired.
{
  "code": "string",
  "message": "string"
}
code message
ExpiredToken Token expired.
InvalidToken Token is not valid.
403 Forbidden

The account has no services enabled.
{
  "code": "string",
  "message": "string"
}
code message
NoServiceAvailable The account has no services enabled for it.
500 The server encountered an internal error.
{
  "code": "string",
  "message": "string"
}
code message
InternalError The server encountered an internal error. Please retry the request.
503 Service Unavailable
{
  "code": "string",
  "message": "string"
}
code message
ServiceNotReady The server is not ready to handle the request. Please retry the request later.