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

Cet article vous a-t-il été utile ?

Authentication

Lyve Cloud uses a token to authenticate access to the Lyve Cloud Account API. The Token is obtained by calling an endpoint that uses the Account ID, Access Key, and Secret Key. It returns a valid time-bound token, where the default expiration duration is 24 hours. When a token expires, the account API returns HTTP 400 code, after which the client application needs to obtain a new token.

Each request to an API endpoint must include the bearer header value. This value requires specifying a token in the authorization header of a request.

A token is a unique string. Tokens eliminate the need for passing user credentials with requests. Such a token is issued by the /auth/token endpoint.

Request

A POST to /auth/token is used to exchange user credentials for an access token.

POST /auth/token

Body parameter

{ 
  "accountId": "string",
  "accessKey": "string",
  "secret": "string"
}

Parameters

Name In Type Required Description
accountId body string True The Account ID is a unique identifier of the Lyve Cloud Account. The Account ID is created during the customer onboarding and is unique across all Lyve Cloud accounts.
accessKey body string True The access key is generated when you generate Account API credentials. For more information, see Using Account API.
secret body string True The secret key is generated when you generate Account API credentials. For more information, see Using Account API.

Code samples

Go

    package main

    import (
        "bytes"
        "net/http"
    )

    func main() {
        headers := map[string][]string{
            "Content-Type": []string{
                "application/json",
            },
            "Accept": []string{
                "application/json",
            },
        }

        jsonReq := `{"key":"value"}` // replace with your JSON request
        data := bytes.NewBuffer([]byte(jsonReq))
        req, err := http.NewRequest("POST", "https://api.lyvecloud.seagate.com/v2/auth/token/", data)
        if err != nil {
            // handle error
        }
        req.Header = headers

        client := &http.Client{}
        resp, err := client.Do(req)
        if err != nil {
            // handle error
        }
        // handle response _ = resp }

Java

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

    public class Main {
        public static void main(String[] args) {
            try {
                URL obj = new URL("https://api.lyvecloud.seagate.com/v2/auth/token/");
                HttpURLConnection con = (HttpURLConnection) obj.openConnection();
                con.setRequestMethod("POST");
                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 inputBody = `{
        "accountId": "string",
        "accessKey": "string",
        "secret": "string"
    }`;

    const headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    };

    fetch('https://api.lyvecloud.seagate.com/v2/auth/token/', {
        method: 'POST',
        body: inputBody,
        headers: headers
    })
    .then(function(res) {
        return res.json();
    }).then(function(body) { console.log(body); });

Python

    import requests
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }

    data = {
        "accountId": "string",
        "accessKey": "string",
        "secret": "string"
    }

    r = requests.post('https://api.lyvecloud.seagate.com/v2/auth/token/', headers=headers, json=data) print(r.json())

Ruby

    require 'rest-client'
    require 'json'

    headers = {
        'Content-Type' => 'application/json',
        'Accept' => 'application/json'
    }

    data = {
        "accountId" => "string",
        "accessKey" => "string",
        "secret" => "string"
    }

    result = RestClient.post 'https://api.lyvecloud.seagate.com/v2/auth/token/', data.to_json, headers

    p JSON.parse(result)
  

Responses

Status Code Description Return JSON payload
200 OK

The session token is returned successfully to use in subsequent API calls.The expiration time of the token is returned in response, ater the expiration duration the token is expired.
{ 
  "token": "string",
  "expirationSec": 864000,
}
Field Description
token The JWT session token to use in subsequent API calls.
expirationSec The number of seconds remaining till the token expires.
400 Bad request

The request is invalid and has invalid information.
{
  "code": "string",
  "message": "string"
}
code message
InvalidArgument This error might occur for the following reasons:
  • One or more of the specified arguments was not valid.
  • The request was missing an argument.
403 Authentication failed.
{
  "code": "string",
  "message": "string"
}
code message
Authentication failed Authentication failed.
500 Internal Server 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.

Testing a session token for validity

To access the API, you must request an access token when authenticating a user. The GET /auth/token is used to validate a session and return the remaining duration for that session.

Request

The GET API allows validating a session. It returns the remaining duration of the token.

GET /auth/token

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/auth/token/", data) 
        req.Header = headers 
        client := &http.Client{} 
        resp, err := client.Do(req) 
        // ... }

Java

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

    public class Main {
        public static void main(String[] args) {
            try {
                URL obj = new URL("https://api.lyvecloud.seagate.com/v2/auth/token/");
                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/auth/token/', {
        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/auth/token/', 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/auth/token/', headers: headers

    p JSON.parse(result)
  

Responses

Status Code Description Return JSON payload
200 OK

A session token is valid and is in effect.
{
 "expirationSec": 0
}
Field Description
expirationSec Number of seconds remaining until the token expires.
400 Bad request

Either the token is expired or not valid.
{
  "code": "string",
  "message": "string"
}
code message
ExpiredToken Token expired.
InvalidToken Token is not valid.
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.