Versions Compared

Key

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

...

Info

Tag_name 변수에 지정한 tag에 대한 자세한 정보를 반환한다. tag_name변수에 적절한 값을 반드시 설정해야 한다.

Info

Windows batch 예제코드가 lakeid.machlake.com으로 되어있음 확인 필요.

...

Expand
titleLinux(shell)

github

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

API_KEY=YOUR_API_TOKEN
LAKE_ID=$YOUR_LAKE_ID
API_KEY=$YOUR_API_KEY
CLOUD_VENDOR=$YOUR_CLOUD_VENDOR
CLOUD_REGION=$YOUR_CLOUD_REGION
TAG_NAME=$YOUR_TAG_NAME

CONTENT_HEADER=Content-Type:application/json
API_HEADER=x-api-key:$API_KEY
LAKE_ID=YOUR_LAKE_ID
URL=https://$LAKE_ID${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/tag

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

# CASE - Get Tag Information

TAG_NAME=sensor

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"}

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"}

# ------------------------------------------------------------------------------------------------- #
Expand
titlejavacsript

github

Code Block
// 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 CLOUD_VENDOR= "https://" + LAKE_ID + ".machlake.com/lakes/tag";

// CASE - Get Tag Information

app.get(
    '/get_tag_view_no_tag_name', function(req, res) {
        "CLOUD_VENDOR";
const CLOUD_REGION="CLOUD_REGION";
const TAG_NAME = "YOUR_TAG";

var request = require('request');
        const QueryParams = new URLSearchParams()

        QueryParams.set("name", "sensor")
        var option = {
      request.get({
     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: {
       `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/tag`, 
    qs: {'name': TAG_NAME},
    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')
})
Expand
titlepython

github

Code Block
"""
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"
CLOUD_VENDOR="CLOUD_VENDOR"
CLOUD_REGION="CLOUD_REGION"

URL = f"https://{LAKE_ID{CLOUD_VENDOR}.{CLOUD_REGION}.machlake.com/lakes/{LAKE_ID}/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"}

# CASE - Get Tag Information

params = {
    'name': 'sensor1'
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"name":"sensor1"},"status":"success"}

...