Versions Compared

Key

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

...

Table of Contents
minLevel1
maxLevel7
typeflat

Optional

Type

Description

Example

name

string

name of tag

?name=newtag01

Request Example

Paste code macro
languagehttp
themeSunburst
GET https://lake01.machlake.com/lakes/tag?name=newtag01
Content-Type: application/json; charset=utf8
x-api-key: {API Key}

...

Paste code macro
languagejson
themeSunburst
Status 200
 
{
    "status": "success",
    "data": {
        "name": "newtag01"
    }
}

Sample Code

In this sample, tag contains only sensor1, sensor2

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=

set CONTENT_HEADER="Content-Type: application/json"
set API_HEADER="x-api-key: %API_KEY%"
set LAKE_ID=c5ehcdmcb0jc72ia6pug
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
# written by yeony kim
# sensor1, sensor2 is applied in lake

API_KEY=

CONTENT_HEADER=Content-Type:application/json
API_HEADER=x-api-key:$API_KEY
LAKE_ID=c5ehcdmcb0jc72ia6pug
URL=https://$LAKE_ID.machlake.com/lakes/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
languagejs
// 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 = "c5ehcdmcb0jc72ia6pug"
const URL = "https://" + LAKE_ID + ".machlake.com/lakes/tag";

// CASE - Get Tag Information

app.get(
    '/get_tag_view_no_tag_name', function(req, res) {
        var request = require('request');
        const QueryParams = new URLSearchParams()

        QueryParams.set("name", "sensor")
        var option = {
            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: {
                '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
languagepy
"""
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 = "c5ehcdmcb0jc72ia6pug"
URL = f"https://{LAKE_ID}.machlake.com/lakes/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"}