Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

# Text Encoding to UTF-8 in CMD # Example For Get Lake View API by using curl in shell script API_KEY=$YOUR_API_KEY LAKE_ID=$YOUR_LAKE_ID CONTENT_HEADER="Content-Type:application/json" API_HEADER="x-api-key:$API_KEY" URL=https://api.machlake.com/v1/lakes/$LAKE_ID # ------------------------------------------------------------------------------------------------- # # CASE - GET LAKE List curl -k -X GET $URL -H $CONTENT_HEADER -H $API_HEADER # Return Format # { # "success":true, # "reason":"get lake info success", # "data":{ # "lake_id":"xbcd0001", # "lake_info":{ # "lake_name":"sample_lake", # "lake_plan":"basic", # "lake_type":"N", # "region":"aws1.kor", # "timezone":"America/Los_Angeles", #
Expand
titlewindow(batch)

github

Code Block
chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Get Tag View API by using curl in window script
:: written by yeony kim
:: sensor1, sensor2 is applied in lake

set API_KEY=YOUR_API_TOKENKEY
set LAKE_ID=YOUR_LAKE_ID
set CLOUD_VENDOR=YOUR_CLOUD_VENDOR
set CLOUD_REGION=YOUR_CLOUD_REGION

set CONTENT_HEADER="Content-Type: application/json"
set API_HEADER="x-api-key: %API_KEY%"
set LAKE_ID=YOUR_LAKE_ID
set URL="https://%LAKE_ID%%CLOUD_VENDOR%.%CLOUD_REGION%.machlake.com/v1/lakes/tag%LAKE_ID%/tag"

:: ------------------------------------------------------------------------------------------------- ::

:: CASE - Get Tag Information

set TAG_NAME=sensorsensor1

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% \
    --data-urlencode "name=%TAG_NAME%"

:: Return Format / not exist tag name in lake
:: {"message":"no such name : sensor","status":"error"}

set TAG_NAME=sensor1

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data-urlencode "name=%TAG_NAME%"
:: Return Format
:: {"data":
::     "success": true,
::     "reason": "get tag meta success",
::     "data": {"name": "sensor1sensor01"},"status":"success"}
:: }


:: ------------------------------------------------------------------------------------------------- ::

::
Expand
titleLinux(shell)

github

Code Block
languagebash
 CASE - Get Tag Information when no exist tag name

set TAG_NAME=wrong_name

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% \
    --data-urlencode "name=%TAG_NAME%"

:: Return Format
:: status code : 400 Bad Request
:: {
::     "success": false,
::     "reason": "no such name : wrong_name"
:: }
Expand
titleLinux(shell)

github

Code Block
languagebash
# Text Encoding to UTF-8 in CMD
# Example For Get Lake View API by using curl in shell script

API_KEY=$YOUR_API_KEY
LAKE_ID=$YOUR_LAKE_ID

CONTENT_HEADER="Content-Type:application/json"
API_HEADER="x-api-key:$API_KEY"

URL=https://api.machlake.com/v1/lakes/$LAKE_ID

# ------------------------------------------------------------------------------------------------- #

# CASE - GET LAKE List

curl -k -X GET $URL -H $CONTENT_HEADER -H $API_HEADER

# Return Format
# {
#     "success":true,
#     "reason":"get lake info success",
#     "data":{
#         "
create
lake_
time
id":"
2021-09-30 10:30:05
xbcd0001",
#
         "
update
lake_
time
info":
"2021-10-01 14:59:12"
{
#
        
},
 
#
    
"lake_status":{
"lake_name":"sample_lake",
#             "
count
lake_
of_tag
plan":
128
"basic",
#             "
count
lake_
of_value
type":
123456
"N",
#             "
query_call
region":
0
"aws1.kor",
#             "
traffic
timezone":
4743829
"America/Los_Angeles",
#             "
storage":3032870912,
create_time":"2021-09-30 10:30:05",
#             "
state
update_time":"
running"
2021-10-01 14:59:12"
#         },
#         "
plan
lake_
limit
status":{
#             "
max
count_of_tag":
1000
128,
#             "
max
count_of_
query
value":
10000
123456,
#             "
max
query_
disk
call":
32212254720
0,
#             "
max_concurrent
traffic":
100000
4743829,
#             
"limit_select_tag":1000
"storage":3032870912,
#             "
limit_select_value
state":
100,
"running" 
#         },
#         "plan_limit
_append_value
":
100,
{
#             "
limit_append
max_tag":1000,
#             "
default
max_
tag_count
query":10000,
#
   
},
 
#
         "
tag
max_
schema
disk":
[
32212254720,
#             
{
"max_concurrent":100000,
#
             "
col
limit_select_
name
tag":
"name"
1000,
#
             "
col
limit_select_
type
value":
"varchar"
100,
#
             "
col
limit_append_
length
value":
40
100,
#             
}
"limit_append_tag":1000,
#         
],
 
#
   "default_tag_count":10000
#         },
#         "
value
tag_schema":[
#             {
#                 "col_name":"
time
name",
#                 "col_type":"
datetime
varchar",
#                 
},
"col_length":40
#             
{
}
#         ],
#         "
col
value_
name
schema":
"value",
[
#             {
#                 "col_
type
name":"
double
time",
#               
}
 
#
 "col_type":"datetime"
#       
]
 
#
     },
# 
}
Expand
titlejavacsript

github

Code Block
languagejs
// Example For Get Tag View API by using request in  {
# nodejs // written by yeony kim // sensor1, sensor2 is applied in lake  process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";"col_name":"value",
#  const express = require('express'); const app = express(); const API_KEY = "YOUR_API_TOKEN"; const LAKE_ID = "YOUR_LAKE_ID"
const URL = "https://" + LAKE_ID + ".machlake.com/lakes/tag";

// CASE - Get Tag Information

app.get(
    '/get_tag_view_no_tag_name', function(req, res) {
        var request = require('request');
        const QueryParams = new URLSearchParams()

        QueryParams.set("name", "sensor")
        var option = {
            url: URL + "?" + QueryParams.toString(),
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
        };
        request.get(option, function(error, response, body) {
            if (!error && response.statusCode === 200) {
                res.writeHead(200);col_type":"double"
#             }
#         ]
#     }
# }
Expand
titlejavacsript

github

Code Block
languagejs
// Example For Get Tag View API by using request in nodejs

// process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

const API_KEY = "YOUR_API_TOKEN";
const LAKE_ID = "YOUR_LAKE_ID";
const CLOUD_VENDOR="CLOUD_VENDOR";
const CLOUD_REGION="CLOUD_REGION";
const URL =  `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/v1/lakes/${LAKE_ID}/tag`;

var request = require('request');


/* ------------------------------------------------------------------------------------------------- */

// CASE - Get Tag Information

request.get({
    url: URL, 
    qs: {
        name: "sensor1"
    },
    headers: {
        "x-api-key": API_KEY
    }}, 
 res.end(body);   function(error, response, body)   {
        console.log(body);
        // Return Format
 } else {     // {
        //  console.log('error');   "success": true,
        //    console.log(error, response)
    "reason": "get tag meta success",
        //    if (response !== undefined) {
 "data": {"name": "sensor01"}
        // }
         res.writeHead(200);})

                   res.end(body);
                    console.log(body) // {"message":"no such name : sensor","status":"error"}
                }
 /* ------------------------------------------------------------------------------------------------- */

// CASE - Get Tag Information when no exist tag name

request.get({
    url: URL, 
    qs: {
        name: "wrong_name"
}    },
    })headers: {
   } )  // CASE "x- Get Tag Information

app.get(api-key": API_KEY
    }}, 
   '/get_tag_view_tag_name', function(reqerror, response, resbody) {
        var request = require('request'console.log(body);
        const// QueryParamsReturn =Format
new URLSearchParams()       // status  QueryParams.set("name", "sensor1")
 code : 400 Bad Request
      var option =// {
          //  url: URL + "?success": + QueryParams.toString(),false,
        //     headers"reason": {"no such name : wrong_name"
        // }
  'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
        };
        request.get(option, function(error, response, body) {
            if (!error && response.statusCode === 200) {
                res.writeHead(200);
                res.end(body);
                console.log(body)
            } else {
                console.log('error');
                console.log(error, response)
                if (response !== undefined) {
                    res.writeHead(200);
                    res.end(body);
                    console.log(body) // {"data":{"name":"sensor1"},"status":"success"}
                }
            }
        })
    }
)


app.listen(8888, function() {
    console.log('http://127.0.0.1:8888/get_tag_view_no_tag_name is result for tag name not exist in lake')
    console.log('http://127.0.0.1:8888/get_tag_view_tag_name is result for tag name exsit in lake')
})
Expand
titlepython

github

Code Block
languagepy
"""
Example For Get Tag View API by using requests in python
written by yeony kim
sensor1, sensor2 is applied in lake
"""

import requests

API_KEY = "YOUR_API_TOKEN"
LAKE_ID = "YOUR_LAKE_ID"
URL = f"https://{LAKE_ID}.machlake.com/lakes/tag"

headers = {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY
}

# CASE - Get Tag Information

params = {
    'name': 'sensor'
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))  # {"message":"no such name : sensor","status":"error"} })
Expand
titlepython

github

Code Block
languagepy
"""
Example For Get Tag View API by using requests in python
written by yeony kim
"""

import requests

API_KEY = "YOUR_API_TOKEN"
LAKE_ID = "YOUR_LAKE_ID"
CLOUD_VENDOR="CLOUD_VENDOR"
CLOUD_REGION="CLOUD_REGION"

URL = f"https://{CLOUD_VENDOR}.{CLOUD_REGION}.machlake.com/v1/lakes/{LAKE_ID}/tag"

headers = {
    "Content-Type": "application/json",
    "x-api-key": API_KEY
}


# ------------------------------------------------------------------------------------------------- #

# CASE - Get Tag Information

params = {
    "name": "sensor1"
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode("utf-8"))

# Return Format
# {
#     "success": true,
#     "reason": "get tag meta success",
#     "data": {"name": "sensor01"}
# }


# ------------------------------------------------------------------------------------------------- #

# CASE - Get Tag Information when no exist tag name

params = {
    '"name'": 'sensor1'"wrong_name"
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('"utf-8'"))

# Return Format
# {"data":{"name":"sensor1"},"status":"success"} status code : 400 Bad Request
# {
#     "success": false,
#     "reason": "no such name : wrong_name"
# }