Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 2 Next »

등록된 Tag에 대한 정보를 변경한다. 변경할 tag의 이름을 name 필드에 설정하고, 변경할 정보를 해당하는 “col_name” 및 “value” 필드에 지정하여 json arry로 설정한 후 호출하여야 한다.

HTTP Request

PUT https://${CloudVendor}.${CountryCode}.machlake.com/lakes/${lake_id}/tags
Content-Type: application/json; charset=utf8
x-api-key: {API Key}
 
{
    "name"    : "{original tag name}",
    "columns" : [{ "col_name" : "{column_name}", "value" : "{value to be changed}" }, .... ]
}

Parameters

no parameters

Request Example

PUT https://aws1.us.machlake.com/lakes/xbacd1234/tags
Content-Type: application/json; charset=utf8
x-api-key: {API Key}
 
{
    "name"    : "newtag01",
    "columns" : [{ "col_name" : "name", "value" : "changetag01"}]
}

Response Example

Status 200

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

Sample Code

이 예제는 sensor1 tag를 sensor10으로 변경했다가 다시 sensor1로 변경하는것을 보여준다.

 window(batch)

github

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

:: ------------------------------------------------------------------------------------------------- ::
 linux(shell)

github

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

# ------------------------------------------------------------------------------------------------- #
 javascript

github

// 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')
})
 python

github

"""
Example For Update Tag 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"
URL = f"https://{LAKE_ID}.machlake.com/lakes/tags"
headers = {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY
}

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

params = {
    'name': 'sensor1',
    'columns': [{'col_name': "name", 'value': "sensor10"}]
}

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

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

params = {
    'name': 'sensor10',
    'columns': [{'col_name': "name", 'value': "sensor1"}]
}

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

  • No labels