Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
minLevel1
maxLevel7
typeflat

이 API는 Machlake에서 machlake에서 하나의 센서를 표시하기 위해 사용되는 tag를 생성한다. Tag를 생성할 때 이미 디자인한 스키마와 같은 형태로 데이터를 입력해야 한다. 여러개의 tag를 한꺼번에 등록할 수 있다. Tag 생성 API를 수행하여 결과가 성공이면 입력한 데이터에 따라 Tag의 id와 정보들이 입력되고 입력 결과를 json arry형태로 반환한다.

...

Code Block
languagejson
POST https://aws1.us.machlake.com/lakes/xbacd1234/tags

{
    "tag" : [["newtag01"], ["newtag02"]]
}

Sample Code

In Sample Code, create tag that name sensor1, sensor2 and tag_schema is only name column thus tag field in json is list of [name_variable], if tag_schema is different then this field data should be change이 예제는 sensor1, senso2의 이름을 갖는 tag를 생성한다. Tag_schema 메타정보는 name column만을 갖는 상황이므로 json데이터는 name_variable의 배열로 구성되었다. Tag_schema가 다른 경우 추가 필드값이 필요할 수 있다.

Expand
titleWindow(Batch)

github

Code Block
chcp 65001 
:: Text Encoding to UTF-8  in CMD
:: Example For Create Tag API by using curl in window script
:: written by yeony kim

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/tags

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

:: CASE - create TAG

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data "{\"tag\": [[\"sensor1\"], [\"sensor2\"]]}"

:: Return Format
:: {"data":{"success_count":2,"tag":[{"name":"sensor1"},{"name":"sensor2"}]},"status":"success"}

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

:: CASE - tag duplicate error

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data "{\"tag\": [[\"sensor1\"], [\"sensor2\"]]}"

:: Return Format / Example For Exist same tag name in lake
:: {"message":"Metadata key (sensor2) of TAGDATA table is already inserted.","status":"error"}

:: ------------------------------------------------------------------------------------------------- ::
Expand
titleLinux(Shell)

github

 

Code Block
languagebash
# Text Encoding to UTF-8 in CMD
# Example For Create Tag 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}/tags

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

# CASE - create TAG

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER --data "{\"tag\": [[\"sensor1\"], [\"sensor2\"]]}"

# Return Format
# {"data":{"success_count":2,"tag":[{"name":"sensor1"},{"name":"sensor2"}]},"status":"success"}

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

# CASE - tag duplicate error

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER --data "{\"tag\": [[\"sensor1\"], [\"sensor2\"]]}"

# Return Format / Example For Exist same tag name in lake
# {"message":"Metadata key (sensor2) of TAGDATA table is already inserted.","status":"error"}

# ------------------------------------------------------------------------------------------------- #
Expand
titlejavascript

github

 

Code Block
languagejs
// Example For Create Tag API by using request in nodejs
// written by yeony kim

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/tags";

// CASE - create TAG / tag duplicate error

app.get(
    '/create_tag_sensor1_2', function(req, res) {
        const Data = {
            tag: [['sensor1'], ['t_sensor1'], ['t_sensor2']],
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
            body: JSON.stringify(Data)
        };
        request.post( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"success_count":2,"tag":[{"name":"sensor1"},{"name":"sensor2"}]},"status":"success"} or {"message":"Metadata key (sensor2) of TAGDATA table is already inserted.","status":"error"}
            } else {
                console.log(error)
            }
        })
    }
)

app.listen(8888, function() {
    console.log('http://127.0.0.1:8888/create_tag_sensor1_2 is result for create sensor1 and sensor2 tag')
})

Expand
titlepython

github

 

Code Block
languagepy
"""
Example For Create Tag API by using request 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/tags"

# CASE - create TAG / tag duplicate error

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

params = {
    'tag': [['sensor1'], ['sensor2']],
}

response = requests.post(URL, headers=headers,  json=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"success_count":2,"tag":[{"name":"sensor1"},{"name":"sensor2"}]},"status":"success"}