Versions Compared

Key

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

...

Code Block
Status 200

{
    "status": "success",
    "data": {
        "name": "changetag01"
    }
}

Sample Code

in this sample, try to update sensor1 to sensor10 and recover sensor10 to sensor1

Expand
titlewindow(batch)

github

Code Block
chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Update Tag 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/tags

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

:: CASE - Tag Name Change SRC to TAR

set SRC_TAG_NAME=sensor1
set TAR_TAG_NAME=sensor10

curl -k -X PUT %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"name\": \"%SRC_TAG_NAME%\", \"columns\": [{\"col_name\": \"name\", \"value\": \"%TAR_TAG_NAME%\"}]}"

:: Return Format
:: {"data":{"name":"sensor10"},"status":"success"}

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

:: CASE - Tag Name Change Error when Not exist

curl -k -X PUT %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"name\": \"%SRC_TAG_NAME%\", \"columns\": [{\"col_name\": \"name\", \"value\": \"%TAR_TAG_NAME%\"}]}"

:: Return Format / SRC_TAG_NAME이 존재 하지 않는 경우 예시
:: {"message":"no such name : sensor1","status":"error"}

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

:: CASE - Tag Name Change SRC to TAR

set SRC_TAG_NAME=sensor10
set TAR_TAG_NAME=sensor1

curl -k -X PUT %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"name\": \"%SRC_TAG_NAME%\", \"columns\": [{\"col_name\": \"name\", \"value\": \"%TAR_TAG_NAME%\"}]}"

:: Return Format
:: {"data":{"name":"sensor1"},"status":"success"}

:: ------------------------------------------------------------------------------------------------- ::
Expand
titlelinux(shell)

github

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

API_KEY=YOUR_API_TOKEN

CONTENT_HEADER=Content-Type:application/json
API_HEADER=x-api-key:$API_KEY
LAKE_ID=YOUR_LAKE_ID
URL=https://$LAKE_ID.machlake.com/lakes/tags

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

# CASE - Tag Name Change SRC to TAR

SRC_TAG_NAME=sensor1
TAR_TAG_NAME=sensor10

curl -k -X PUT $URL -H $CONTENT_HEADER -H $API_HEADER  -d "{\"name\": \"$SRC_TAG_NAME\", \"columns\": [{\"col_name\": \"name\", \"value\": \"$TAR_TAG_NAME\"}]}"

# Return Format
# {"data":{"name":"sensor10"},"status":"success"}

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

# CASE - Tag Name Change Error when Not exist

curl -k -X PUT $URL -H $CONTENT_HEADER -H $API_HEADER  -d "{\"name\": \"$SRC_TAG_NAME\", \"columns\": [{\"col_name\": \"name\", \"value\": \"$TAR_TAG_NAME\"}]}"

# Return Format / SRC_TAG_NAME이 존재 하지 않는 경우 예시
# {"message":"no such name : sensor1","status":"error"}

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

# CASE - Tag Name Change SRC to TAR

SRC_TAG_NAME=sensor10
TAR_TAG_NAME=sensor1

curl -k -X PUT $URL -H $CONTENT_HEADER -H $API_HEADER  -d "{\"name\": \"$SRC_TAG_NAME\", \"columns\": [{\"col_name\": \"name\", \"value\": \"$TAR_TAG_NAME\"}]}"

# Return Format
# {"data":{"name":"sensor1"},"status":"success"}

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

github

Code Block
// Example For Update Tag 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/tags";

// CASE - Tag Name Change SRC to TAR / Tag Name Change Error when Not exist

app.get(
    '/update_tag_name_1t10', function(req, res) {
        const Data = {
            name: 'sensor1',
            columns: [{col_name: "name", value: "sensor10"}]
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
            body: JSON.stringify(Data)
        };
        request.put( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"name":"sensor10"},"status":"success"} or {"message":"no such name : sensor1","status":"error"}
            } else {
                console.log(error)
            }
        })
    }
)

// CASE - Tag Name Change TAR to SRC / Tag Name Change Error when Not exist

app.get(
    '/update_tag_name_10t1', function(req, res) {
        const Data = {
            name: 'sensor10',
            columns: [{col_name: "name", value: "sensor1"}]
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
            body: JSON.stringify(Data)
        };
        request.put( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"name":"sensor1"},"status":"success"} or {"message":"no such name : sensor1","status":"error"}
            } else {
                console.log(error)
            }
        })
    }
)


app.listen(8888, function() {
    console.log('http://127.0.0.1:8888/update_tag_name_1t10 is result for update tag name that sensor1 to sensor10')
    console.log('http://127.0.0.1:8888/update_tag_name_10t1 is result for update tag name that sensor10 to sensor1')
})

...

titlepython

github

...

이 예제에서, sensor1, sensor2의 tag가 사전에 생성되어 있는 것을 가정한다. 해당 tag가 없으면 오류로 처리된다.