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 14 Current »

This API is a standardized data input method supported by Machlake. The tag name, time, and each value are transmitted in a typical JSON format. Since this function has a name entered for every value, the length of JSON occupies relatively long, so there may be a slight load on the network usage and processing performance.

HTTP Request

Parameters

no parameters

Request Example

Response Example

Sample Code

In this sample, value_schema in create lake is [time:datetime, value: double] so if value_schema is difference then result is different, and each record in values has same order to schema

 window(batch)

github

chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Insert Standard Data for tag API by using curl in window 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"

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

:: CASE - Insert Data with nano date time string format

set TAG_NAME=sensor1
set DATE_FORMAT=\"YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn\"
set VALUES=[[\"2021-01-06 17:00:00 001:000:000\", 1.0], [\"2021-01-06 17:00:00 002:000:000\", 1.5], [\"2021-01-06 17:00:00 003:000:000\", 2.0]]

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"tag_name\": \"%TAG_NAME%\", \"date_format\": %DATE_FORMAT%, \"values\": %VALUES%}"

:: Return Format 
:: {
::     "success": true,
::     "reason": "append success",
::     "data": {"fail": 0,"success": 3}
:: }

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

:: CASE - Insert Data with time format is empty but data format in data is nano date time string

set TAG_NAME=sensor1
set DATE_FORMAT=\"\"
set VALUES=[[\"2021-01-06 17:00:00 004:000:000\", 1.0], [\"2021-01-06 17:00:00 005:000:000\", 1.5], [\"2021-01-06 17:00:00 006:000:000\", 2.0]]

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"tag_name\": \"%TAG_NAME%\", \"date_format\": %DATE_FORMAT%, \"values\": %VALUES%}"

:: Return Format
:: {
::     "success": true,
::     "reason": "append success",
::     "data": {"fail": 0,"success": 3}
:: }

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

:: CASE - Insert Data with utc-0 time zone and time format is empty but data format in data is nano date time string

set TAG_NAME=sensor1
set DATE_FORMAT=\"\"
set VALUES=[[\"2021-01-06 8:00:00 007:000:000\", 1.0], [\"2021-01-06 8:00:00 008:000:000\", 1.5], [\"2021-01-06 8:00:00 009:000:000\", 2.0]]

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"timezone\": \"Africa/Abidjan\", \"tag_name\": \"%TAG_NAME%\", \"date_format\": %DATE_FORMAT%, \"values\": %VALUES%}"

:: Return Format 
:: {
::     "success": true,
::     "reason": "append success",
::     "data": {"fail": 0,"success": 3}
:: }


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

:: CASE - Insert Data with date time string format

set TAG_NAME=sensor2
set DATE_FORMAT=\"YYYY-MM-DD HH24:MI:SS\"
set VALUES=[[\"2021-01-06 17:00:00\", 1.0], [\"2021-01-06 17:00:01\", 1.5], [\"2021-01-06 17:00:02\", 2.0]]

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"tag_name\": \"%TAG_NAME%\", \"date_format\": %DATE_FORMAT%, \"values\": %VALUES%}"

:: Return Format 
:: {
::     "success": true,
::     "reason": "append success",
::     "data": {"fail": 0,"success": 3}
:: }

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

:: CASE - Insert Data with nano-timestamp

set TAG_NAME=sensor2
set VALUES=[[1609920003000000000, 1.0], [1609920004000000000, 1.5], [1609920005000000000, 2.0]]

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"tag_name\": \"sensor2\", \"values\": %VALUES%}"

:: Return Format
:: {
::     "success": true,
::     "reason": "append success",
::     "data": {"fail": 0,"success": 3}
:: }

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

:: CASE - Insert Data with utc-0 time zone and date time string format but data format in data is nano date time string

set TAG_NAME=sensor2
set DATE_FORMAT=\"YYYY-MM-DD HH24:MI:SS\"
set VALUES=[[\"2021-01-06 17:00:00 007:000:000\", 1.0], [\"2021-01-06 17:00:00 008:000:000\", 1.5], [\"2021-01-06 17:00:00 009:000:000\", 2.0]]

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"timezone\": \"Africa/Abidjan\", \"tag_name\": \"%TAG_NAME%\", \"date_format\": %DATE_FORMAT%, \"values\": %VALUES%}"

:: Return Format
:: {
::     "success": true,
::     "reason": "append success",
::     "data": {"fail": 0,"success": 3}
:: }
 linux(shell)

github

# Text Encoding to UTF-8 in CMD
# Example For Insert Standard 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

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

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

# CASE - Insert Data with nano date time string format

TAG_NAME=sensor1
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"
VALUES="[[\"2021-01-06 17:00:00 001:000:000\", 1.0], [\"2021-01-06 17:00:00 002:000:000\", 1.5], [\"2021-01-06 17:00:00 003:000:000\", 2.0]]"

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER  -d "{\"tag_name\": \"$TAG_NAME\", \"date_format\": \"$DATE_FORMAT\", \"values\": $VALUES}"

# Return Format 
# {
#     "success": true,
#     "reason": "append success",
#     "data": {"fail": 0,"success": 3}
# }

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

# CASE - Insert Data with time format is empty but data format in data is nano date time string

TAG_NAME=sensor1
DATE_FORMAT=""
VALUES="[[\"2021-01-06 17:00:00 004:000:000\", 1.0], [\"2021-01-06 17:00:00 005:000:000\", 1.5], [\"2021-01-06 17:00:00 006:000:000\", 2.0]]"

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER  -d "{\"tag_name\": \"$TAG_NAME\", \"date_format\": \"$DATE_FORMAT\", \"values\": $VALUES}"

# Return Format
# {
#     "success": true,
#     "reason": "append success",
#     "data": {"fail": 0,"success": 3}
# }

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

# CASE - Insert Data with utc-0 time zone and time format is empty but data format in data is nano date time string

TAG_NAME=sensor1
DATE_FORMAT=""
VALUES="[[\"2021-01-06 8:00:00 007:000:000\", 1.0], [\"2021-01-06 8:00:00 008:000:000\", 1.5], [\"2021-01-06 8:00:00 009:000:000\", 2.0]]"

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER -d "{\"timezone\": \"Africa/Abidjan\", \"tag_name\": \"$TAG_NAME\", \"date_format\": \"$DATE_FORMAT\", \"values\": $VALUES}"

# Return Format 
# {
#     "success": true,
#     "reason": "append success",
#     "data": {"fail": 0,"success": 3}
# }

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

# CASE - Insert Data with date time string format

TAG_NAME=sensor2
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
VALUES="[[\"2021-01-06 17:00:00\", 1.0], [\"2021-01-06 17:00:01\", 1.5], [\"2021-01-06 17:00:02\", 2.0]]"

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER -d "{\"tag_name\": \"$TAG_NAME\", \"date_format\": \"$DATE_FORMAT\", \"values\": $VALUES}"

# Return Format 
# {
#     "success": true,
#     "reason": "append success",
#     "data": {"fail": 0,"success": 3}
# }

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

# CASE - Insert Data with nano-timestamp

TAG_NAME=sensor2
VALUES="[[1609920003000000000, 1.0], [1609920004000000000, 1.5], [1609920005000000000, 2.0]]"

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER  -d "{\"tag_name\": \"sensor2\", \"values\": $VALUES}"

# Return Format
# {
#     "success": true,
#     "reason": "append success",
#     "data": {"fail": 0,"success": 3}
# }

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

# CASE - Insert Data with utc-0 time zone and date time string format but data format in data is nano date time string

TAG_NAME=sensor2
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
VALUES="[[\"2021-01-06 17:00:00 007:000:000\", 1.0], [\"2021-01-06 17:00:00 008:000:000\", 1.5], [\"2021-01-06 17:00:00 009:000:000\", 2.0]]"

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER -d "{\"timezone\": \"Africa/Abidjan\", \"tag_name\": \"$TAG_NAME\", \"date_format\": \"$DATE_FORMAT\", \"values\": $VALUES}"

# Return Format
# {
#     "success": true,
#     "reason": "append success",
#     "data": {"fail": 0,"success": 3}
# }
 javascript

github

// Example For Insert Standard Data for 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 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');

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

// CASE - Insert Data with nano date time string format

var Data = {
    tag_name: "sensor1",
    date_format: "YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn",
    values: [
        ["2021-01-06 17:00:00 001:000:000", 1.0], 
        ["2021-01-06 17:00:00 002:000:000", 1.5], 
        ["2021-01-06 17:00:00 003:000:000", 2.0]
    ]
}

request.post({
    url: URL, 
    headers: {
        "Content-Type": "application/json",
        "x-api-key": API_KEY
    },
    body: JSON.stringify(Data)
    }, 
    function(error, response, body) {
        console.log(body);
        // Return Format 
        // {
        //     "success": true,
        //     "reason": "append success",
        //     "data": {"fail": 0,"success": 3}
        // }
    });

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

// CASE - Insert Data with time format is empty but data format in data is nano date time string

var Data = {
    tag_name: "sensor1",
    values: [
        ["2021-01-06 17:00:00 004:000:000", 1.0], 
        ["2021-01-06 17:00:00 005:000:000", 1.5], 
        ["2021-01-06 17:00:00 006:000:000", 2.0]
    ]
}

request.post({
    url: URL, 
    headers: {
        "Content-Type": "application/json",
        "x-api-key": API_KEY
    },
    body: JSON.stringify(Data)
    }, 
    function(error, response, body) {
        console.log(body);
        // Return Format 
        // {
        //     "success": true,
        //     "reason": "append success",
        //     "data": {"fail": 0,"success": 3}
        // }
    });

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

// CASE - Insert Data with utc-0 time zone and time format is empty but data format in data is nano date time string

var Data = {
    timezone: "Africa/Abidjan",
    tag_name: "sensor1",
    values: [
        ["2021-01-06 8:00:00 007:000:000", 1.0], 
        ["2021-01-06 8:00:00 008:000:000", 1.5], 
        ["2021-01-06 8:00:00 009:000:000", 2.0]
    ]
}

request.post({
    url: URL, 
    headers: {
        "Content-Type": "application/json",
        "x-api-key": API_KEY
    },
    body: JSON.stringify(Data)
    }, 
    function(error, response, body) {
        console.log(body);
        // Return Format 
        // {
        //     "success": true,
        //     "reason": "append success",
        //     "data": {"fail": 0,"success": 3}
        // }
    });

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

// CASE - Insert Data with date time string format

var Data = {
    tag_name: "sensor2",
    date_format: "YYYY-MM-DD HH24:MI:SS",
    values: [
        ["2021-01-06 17:00:00", 1.0], 
        ["2021-01-06 17:00:01", 1.5], 
        ["2021-01-06 17:00:02", 2.0]
    ]
}

request.post({
    url: URL, 
    headers: {
        "Content-Type": "application/json",
        "x-api-key": API_KEY
    },
    body: JSON.stringify(Data)
    }, 
    function(error, response, body) {
        console.log(body);
        // Return Format 
        // {
        //     "success": true,
        //     "reason": "append success",
        //     "data": {"fail": 0,"success": 3}
        // }
    });

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

// CASE - Insert Data with nano-timestamp

var Data = {
    tag_name: "sensor2",
    values: [
        [1609920003000000000, 1.0], 
        [1609920004000000000, 1.5], 
        [1609920005000000000, 2.0]
    ]
}
request.post({
    url: URL, 
    headers: {
        "Content-Type": "application/json",
        "x-api-key": API_KEY
    },
    body: JSON.stringify(Data)
    }, 
    function(error, response, body) {
        console.log(body);
        // Return Format 
        // {
        //     "success": true,
        //     "reason": "append success",
        //     "data": {"fail": 0,"success": 3}
        // }
    });

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

// CASE - Insert Data with utc-0 time zone and date time string format but data format in data is nano date time string
var Data = {
    timezone: "Africa/Abidjan",
    tag_name: "sensor2",
    date_format: "YYYY-MM-DD HH24:MI:SS",
    values: [
        ["2021-01-06 17:00:00 007:000:000", 1.0], 
        ["2021-01-06 17:00:00 008:000:000", 1.5], 
        ["2021-01-06 17:00:00 009:000:000", 2.0]
    ]
}
request.post({
    url: URL, 
    headers: {
        "Content-Type": "application/json",
        "x-api-key": API_KEY
    },
    body: JSON.stringify(Data)
    }, 
    function(error, response, body) {
        console.log(body);
        // Return Format 
        // {
        //     "success": true,
        //     "reason": "append success",
        //     "data": {"fail": 0,"success": 3}
        // }
    });
 python

github

"""
Example For Insert Standard 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/standard"

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

# CASE - Insert Data with nano date time string format

params = {
    'tag_name': 'sensor1',
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
    'values': [["2021-01-06 17:00:00 001:000:000", 1.0], ["2021-01-06 17:00:00 002:000:000", 1.5], ["2021-01-06 17:00:00 003:000:000", 2.0]]
}

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

# CASE - Insert Data with time format is empty but data format in data is nano date time string

params = {
    'tag_name': 'sensor1',
    'values': [["2021-01-06 17:00:00 004:000:000", 1.0], ["2021-01-06 17:00:00 005:000:000", 1.5], ["2021-01-06 17:00:00 006:000:000", 2.0]]
}

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


# CASE - Insert Data with utc-0 time zone and time format is empty but data format in data is nano date time string

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

params = {
    'tag_name': 'sensor1',
    'values': [["2021-01-06 8:00:00 007:000:000", 1.0], ["2021-01-06 8:00:00 008:000:000", 1.5], ["2021-01-06 8:00:00 009:000:000", 2.0]]
}

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


# CASE - Insert Data with date time string format

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

params = {
    'tag_name': 'sensor2',
    'date_format': 'YYYY-MM-DD HH24:MI:SS',
    'values': [["2021-01-06 17:00:00", 1.0], ["2021-01-06 17:00:01", 1.5], ["2021-01-06 17:00:02", 2.0]]
}

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


# CASE - Insert Data with nano-timestamp

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

params = {
    'tag_name': 'sensor2',
    'values': [[1609920003000000000, 1.0], [1609920004000000000, 1.5], [1609920005000000000, 2.0]]
}

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


# CASE - Insert Data with utc-0 time zone and date time string format but data format in data is nano date time string

headers = {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY,
    "Use-Timezone": "Africa/Abidjan"
}

params = {
    'tag_name': 'sensor2',
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
    'values': [["2021-01-06 17:00:00 007:000:000", 1.0], ["2021-01-06 17:00:00 008:000:000", 1.5], ["2021-01-06 17:00:00 009:000:000", 2.0]]
}

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

  • No labels