Versions Compared

Key

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

...

Paste code macro
languagehttp
themeSunburst
GET https://{lake_id${CloudVendor}.${CountryCode}.machlake.com/v1/lakes/${lake_id}/values/current
Content-Type: application/json; charset=utf8
x-api-key: {API Key}

...

Optional

Type

Description

Example

type

string

select type

&type=current

tag_name

string

tag name with , separator

&tag_name=tag1,tag2,tag3

date_format

string

date format of select time
or
timestamp type ("SECOND", "MILLISECOND", "MICROSECOND", "NANOSECOND")

&date_format=YYYY-MM-DD HH24:MI:SS
or
&date_format=MILLISECOND

(default : YYYY-MM-DD HH24:MI:SS)

columns

string

columns to filter out

&columns=value,value2 (default : value)

separator

string

separator for tag_name, columns, and_condition

&separator=| (default : ,)

aliases

string

columns to be aliased (If Empty orthe columns is incorrect, an error will occur)

&aliases=myvalue,myvalu2

value_return_form

int

result set format

Optimized for various chart libraries and configured to return

0 : separate standard (default)
or1 : merged standard

Request Example

Paste code macro
languagehttp
themeSunburst
GET https://lake01aws1.us.machlake.com/v1/lakes/xbacd1234/values/?type=current?&tag_name=tag_01,tag_02&columns=VALUE&aliases=MyVal&value_return_form=0
Content-Type: application/json; charset=utf8
x-api-key: {API Key}

...

Paste code macro
languagejson
themeSunburst
Status 200

// return format = 0
{
    "success": true,
    "statusreason": "success",
    "data": {
        "calc_modecolumns": "raw", [
            {"name": "NAME", "type": 5, "columnslength": [80},
            {"name": "TIME", "type": 5, "length": 4096},
            {"name": "MyVal", "type": 20, "length": 17}
        ],
        "samplesrows": [
            {
                ["tag_name": "tag_02",
   01","2021-07-06 12:12:27", 1629],
            "data": [{"MyVal": 1629,"TIME": tag_02","2021-07-06 12:12:2725"}, 1625]
        ]
    },
}
 

Sample Code

Expand
titlewindow(batch)

github

Code Block
chcp 65001 
:: Text Encoding to UTF-8 in CMD
{
:: Example For Select Current Data for tag API by using curl in window 
"tag_name": "tag_01", "data": [{"MyVal": 1625,"TIME": "2021-07-06 12:12:25"}] } ] } } // return format = 1 { "status": "success", "data": { "calc_mode": "raw", "columns": [ {"name": "TIME", "type": 5, "length": 4096}, {"name": "MyVal", "type": 20, "length": 17} ],
script
:: written by yeony kim

set API_KEY=YOUR_API_KEY
set LAKE_ID=YOUR_LAKE_ID
set CLOUD_VENDOR=YOUR_CLOUD_VENDOR
set CLOUD_REGION=YOUR_CLOUD_REGION

set CONTENT_HEADER="Content-Type: application/json"
set API_HEADER="x-api-key: %API_KEY%"
set URL="https://%CLOUD_VENDOR%.%CLOUD_REGION%.machlake.com/v1/lakes/%LAKE_ID%/values"

set SELECT_TYPE=current

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

:: CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

set TAG_NAME=sensor1,sensor2
set DATE_FORMAT=YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% \
    --data-urlencode "type=%SELECT_TYPE%" \
    --data-urlencode "tag_name=%TAG_NAME%" \
    --data-urlencode "date_format=%DATE_FORMAT%"

:: Return Format
:: {
::     "success": true,
::     "reason": "success",
::     "data":{
::         "
samples
columns":[
[
::             {"name":"NAME","type":5,"length":80},
::             
"tag_name": "tag_02",
{"name":"TIME","type":5,"length":4096},
::             
"data": {
{"name":"VALUE","type":20,"length":17}
::         ],
::         "
MyVal
rows":
[
1629],

::             
"TIME": [
["sensor2","2021-
07-06 12:12:27"]
01-07 02:00:00 009:000:000",2],
::             ["sensor1","2021-01-06 20:00:06 
}
000:000:000",2]
::         ]
::   
},
  }
:: 
{ "tag_name": "tag_01", "data": { "MyVal": [1625], "TIME": ["2021-07-06 12:12:25"] } } ] } }

Sample Code

Expand
titlewindow(batch)

github

Code Block
chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Select Current Data for 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/values/current"

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

:: CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
set TAG_NAME=sensor1,sensor2
set DATE_FORMAT=YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data-urlencode "tag_name=%TAG_NAME%" --data-urlencode "date_format=%DATE_FORMAT%"

:: Return Format
:: {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":[{"TIME":"2021-01-07 02:00:00 009:000:000","VALUE":2}]},{"tag_name":"sensor1","data":[{"TIME":"2021-01-06 20:00:06 000:000:000","VALUE":2}]}]},"status":"success"}

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

:: CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
set TAG_NAME=sensor1,sensor2
set DATE_FORMAT=YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
set VALUE_RETURN_FORM=1

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data-urlencode "tag_name=%TAG_NAME%" --data-urlencode "date_format=%DATE_FORMAT%" --data-urlencode "value_return_form=%VALUE_RETURN_FORM%"

:: Return Format
:: {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":{"TIME":["2021-01-07 02:00:00 009:000:000"],"VALUE":[2]}},{"tag_name":"sensor1","data":{"TIME":["2021-01-06 20:00:06 000:000:000"],"VALUE":[2]}}]},"status":"success"}

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

github

Code Block
# Text Encoding to UTF-8 in CMD
# Example For Select Current Data for tag API by using curl in ubuntu
# written by yeony kim

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/values/current

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

# CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
TAG_NAME=sensor1,sensor2
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "date_format=$DATE_FORMAT"

# Return Format
# {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":[{"TIME":"}
Expand
titlelinux(shell)

github

Code Block
languagebash
# Text Encoding to UTF-8 in CMD
# Example For Select Current Data for 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/v1/lakes/${LAKE_ID}/values

SELECT_TYPE=current

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

# CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

TAG_NAME=sensor1,sensor2
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER \
    --data-urlencode "type=$SELECT_TYPE" \
    --data-urlencode "tag_name=$TAG_NAME" \
    --data-urlencode "date_format=$DATE_FORMAT"

# Return Format
# {
#     "success": true,
#     "reason": "success",
#     "data":{
#         "columns":[
#             {"name":"NAME","type":5,"length":80},
#             {"name":"TIME","type":5,"length":4096},
#             {"name":"VALUE","type":20,"length":17}
#         ],
#         "rows":[
#             ["sensor2","2021-01-07 02:00:00 009:000:000",2],
#             ["sensor1","2021-01-06 20:00:06 000:000:000",2]
#         ]
#     }
# }
Expand
titlejavascript

github

Code Block
languagejs
// Example For Select Current Data for tag API by using request in node js
// written by yeony kim
// sensor1, sensor2 is applied in lake

// 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 URL = `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/v1/lakes/${LAKE_ID}/values`;

var request = require('request');

const TAG_NAME = "sensor1,sensor2";
const SELECT_TYPE="current";


/* ------------------------------------------------------------------------------------------------- */

// CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

request.get({
    url: URL, 
    qs: {
        type: SELECT_TYPE,
        tag_name: TAG_NAME,
        date_format: "YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"
    },
    headers: {
        "x-api-key": API_KEY
    }}, 
    function(error, response, body) {
        console.log(body);
        // Return Format
        // {
        //     "success": true,
        //     "reason": "success",
        //     "data":{
        //         "columns":[
        //             {"name":"NAME","type":5,"length":80},
        //             {"name":"TIME","type":5,"length":4096},
        //             {"name":"VALUE","type":20,"length":17}
        //         ],
        //         "rows":[
        //             ["sensor2","2021-01-07 02:00:00 009:000:000","VALUE":2}]},{"tag_name":"sensor1","data":[{"TIME":,
        //             ["sensor1","2021-01-06 20:00:06 000:000:000","VALUE":2}]}]},"status":"success"}

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

# CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
TAG_NAME=sensor1,sensor2
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"
VALUE_RETURN_FORM=1

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "date_format=$DATE_FORMAT" --data-urlencode "value_return_form=$VALUE_RETURN_FORM"

# Return Format
# {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":{"TIME":["2021-01-07 02:00:00 009:000:000"],"VALUE":[2]}},{"tag_name":"sensor1","data":{"TIME":["2021-01-06 20:00:06 000:000:000"],"VALUE":[2]}}]},"status":"success"}

# ]
        //         ]
        //     }
        // }
    })
Expand
titlepython

gitgub

Code Block
languagepy
"""
Example For Select Current Data for tag API by using request in python
written by yeony kim
"""

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/v1/lakes/{LAKE_ID}/values"

SELECT_TYPE="current"
TAG_NAME="sensor1,sensor2"

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


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

github

Code Block
languagejs
// Example For Select Current Data for tag API by using request in node js
// 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/values/current";

// CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

app.get(
    '/select_current_date_with_nano_time_date_string', function(req, res) {
        var request = require('request');

        const QueryParams = new URLSearchParams()
        
        QueryParams.set('tag_name', 'sensor1,sensor2')
        QueryParams.set('date_format', 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn')

        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) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":[{"TIME":"2021-01-07 02:00:00 009:000:000","VALUE":2}]},{"tag_name":"sensor1","data":[{"TIME":"2021-01-06 20:00:06 000:000:000","VALUE":2}]}]},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)

// CASE - Current DATA GET with another value form

app.get(
    '/select_current_date_with_nano_time_date_string_another_form', function(req, res) {
        var request = require('request');

        const QueryParams = new URLSearchParams()
        
        QueryParams.set('tag_name', 'sensor1,sensor2')
        QueryParams.set('date_format', 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn')
        QueryParams.set('value_return_form', 1)

        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) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":{"TIME":["2021-01-07 02:00:00 009:000:000"],"VALUE":[2]}},{"tag_name":"sensor1","data":{"TIME":["2021-01-06 20:00:06 000:000:000"],"VALUE":[2]}}]},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)

app.listen(8888, function() {
    console.log('http://127.0.0.1:8888/select_current_date_with_nano_time_date_string is result for select current data with nano date time string')
    console.log('http://127.0.0.1:8888/select_current_date_with_nano_time_date_string_another_form is result for select current data with nano date time string with value return form = 1')
})
Expand
titlepython

gitgub

Code Block
languagepy
"""
Example For Select Current Data for 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/values/current"

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

# CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

params = {
    'tag_name': 'sensor1,sensor2',
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":[{"TIME":"2021-01-07 02:00:00 009:000:000","VALUE":2}]},{"tag_name":"sensor1","data":[{"TIME":"2021-01-06 20:00:06 000:000:000","VALUE":2}]}]},"status":"success"}


# CASE - Current DATA GET with another value form

params = {
    'tag_name': 'sensor1,sensor2',
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
    'value_return_form': 1
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"calc_mode":"raw","columns":[ #

# CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

params = {
    "type": SELECT_TYPE,
    "tag_name": TAG_NAME,
    "date_format": "YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn",
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode("utf-8"))

# Return Format
# {
#     "success": true,
#     "reason": "success",
#     "data":{
#         "columns":[
#             {"name":"NAME","type":5,"length":80},
#             {"name":"TIME","type":5,"length":4096},
#             {"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor1","data":{"TIME":[17}
#         ],
#         "rows":[
#             ["sensor2","2021-01-0607 2002:00:0600 000009:000:000"],"VALUE":[2]}},{"tag_name":"sensor2","data":{"TIME":[",2],
#             ["sensor1","2021-01-0706 0220:00:0006 009000:000:000"],"VALUE":[2]}}]},"status":"success"}2]
#         ]
#     }
# }