Versions Compared

Key

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

...

Expand
titleLinux(shell)

github

Code Block
languagebash
# Text Encoding to UTF-8 in CMD
# Example For Get TagLake View API by using curl in ubuntu
# written by yeony kim
# sensor1, sensor2 is applied in lakeshell script

API_KEY=YOUR$YOUR_API_TOKEN_KEY
LAKE_ID=$YOUR_LAKE_ID

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

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

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

# CASE - GetGET TagLAKE InformationList

TAG_NAME=sensor

curl -k -GX GET $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "name=$TAG_NAME"

# Return Format
/# not{
exist# tag name in lake # {"messagesuccess":"notrue,
such# name : sensor","status  "reason":"error"}

TAG_NAME=sensor1

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "name=$TAG_NAME"
# Return Format
# {"data":{"name":"sensor1"},"status":"success"}

# ------------------------------------------------------------------------------------------------- #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",
#             "create_time":"2021-09-30 10:30:05",
#             "update_time":"2021-10-01 14:59:12"
#         },
#         "lake_status":{
#             "count_of_tag":128,
#             "count_of_value":123456,
#             "query_call":0,
#             "traffic":4743829,
#             "storage":3032870912,
#             "state":"running" 
#         },
#         "plan_limit":{
#             "max_tag":1000,
#             "max_query":10000,
#             "max_disk":32212254720,
#             "max_concurrent":100000,
#             "limit_select_tag":1000,
#             "limit_select_value":100,
#             "limit_append_value":100,
#             "limit_append_tag":1000,
#             "default_tag_count":10000
#         },
#         "tag_schema":[
#             {
#                 "col_name":"name",
#                 "col_type":"varchar",
#                 "col_length":40
#             }
#         ],
#         "value_schema":[
#             {
#                 "col_name":"time",
#                 "col_type":"datetime"
#             },
#             {
#                 "col_name":"value",
#                 "col_type":"double"
#             }
#         ]
#     }
# }
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";

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);
                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) // {"message":"no such name : sensor","status":"error"}
                }
            }
        })
    }
)

// CASE - Get Tag Information

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

        QueryParams.set("name", "sensor1")
        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);
                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')
})

...