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으로 되어있음 확인 필요.

HTTP Request

Code Block
GET https://${CloudVendor}.${CountryCode}.machlake.com/lakes/${lake_id}/tag
Content-Type: application/json; charset=utf8
x-api-key: {API Key}

...

Code Block
Status 200
 
{
    "status": "success",
    "data": {
        "name": "newtag01"
    }
}

Sample Code

이 예제코드는 Tag name이 ‘sensor1’인 tag 정보를 얻는다.

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_TOKEN

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%.machlake.com/lakes/tag

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

:: CASE - Get Tag Information

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

set 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
titleLinux(shell)

github

Code Block
# Text Encoding to UTF-8 in CMD
# Example For Get Tag View API by using curl in ubuntu

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
URL=https://${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

// 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 TAG_NAME = "YOUR_TAG";

var request = require('request');
request.get({
    url: `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/tag`, 
    qs: {'name': TAG_NAME},
    headers: {
        'x-api-key': API_KEY
    }}, 
    function(error, response, body) {
        console.log(body)
    })
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://{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"}

...