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

Version 1 Next »

이 API는 tag name을 위시한 칼럼별로 데이터를 정렬하여 칼럼과 데이터 배열로 json을 구성하여 전송하는 방법이다. 모든 데이터에 칼럼명이 기록되지 않기 때문에 대량의 데이터를 빠르게 전송할 수 있다.

HTTP Request

POST https://${CloudVendor}.${CountryCode}.machlake.com/lakes/${lake_id}/values/bulk
Content-Type: application/json; charset=utf8
x-api-key: {API Key}
  
{
    "date_format"   : "{date_format}",
    "values"        : [["{tag_name1}", "{time1}", {value1}], ["(tag_name2}", "{time2}", {value2}], ... ]
}

Parameters

no parameters

Request Example

POST https://aws1.us.machlake.com/lakes/xbacd1234/values/bulk
Content-Type: application/json; charset=utf8
x-api-key: {API Key}
 
{
    "date_format"   : "YYYY-MM-DD HH24:MI:SS",
    "values"        : [
        ["tag_01", "2021-07-06 12:12:25", 1625.0],
        ["tag_02", "2021-07-06 12:12:26", 1627.0],
        ["tag_02", "2021-07-06 12:12:27", 1629.0]
    ]
}

Response Example

Status 200
 
{
    "status": "success",
    "data": {
        "fail": 0,
        "success": 3
    }
}

Sample Code

In this sample, value schema contains, [time:datetime, value: double] so record of value consist of [name, time, value], so when different value schema then record of values also might change

 window(batch)

github

chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Insert Bulk 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/bulk

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

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

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

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

:: Return Format
:: {"data":{"fail":0,"success":6},"status":"success"}

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

:: CASE - Insert Bulk Data with nano date time stamp

set VALUES=[[\"sensor1\", 1609930804000000000, 2.0], [\"sensor1\", 1609930805000000000, 2.5], [\"sensor1\", 1609930806000000000, 2.0], [\"sensor2\", 1609930804000000000, 2.0], [\"sensor2\", 1609930805000000000, 2.5], [\"sensor2\", 1609930806000000000, 2.0]]

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

:: Return Format
:: {"data":{"fail":0,"success":6},"status":"success"}

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

github

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

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

# CASE - Insert Bulk Data with nano date time string format

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

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

# Return Format
# {"data":{"fail":0,"success":6},"status":"success"}

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

# CASE - Insert Bulk Data with nano date time stamp

VALUES="[[\"sensor1\", 1609930804000000000, 2.0], [\"sensor1\", 1609930805000000000, 2.5], [\"sensor1\", 1609930806000000000, 2.0], [\"sensor2\", 1609930804000000000, 2.0], [\"sensor2\", 1609930805000000000, 2.5], [\"sensor2\", 1609930806000000000, 2.0]]"

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

# Return Format
# {"data":{"fail":0,"success":6},"status":"success"}

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

github

// Example For Insert Bulk 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 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/bulk";

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

app.get(
    '/insert_bulk_with_nano_date_time_string', function(req, res) {
        const Data = {
            date_format: 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
            values: [["sensor1","2021-01-06 18:00:00 001:000:000", 2.0], ["sensor1","2021-01-06 18:00:00 002:000:000", 2.5], ["sensor1","2021-01-06 18:00:00 003:000:000", 2.0], ["sensor2","2021-01-06 18:00:00 001:000:000", 2.0], ["sensor2","2021-01-06 18:00:00 002:000:000", 2.5], ["sensor2","2021-01-06 18:00:00 003:000:000", 2.0]]
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
            body: JSON.stringify(Data)
        };
        request.post( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"fail":0,"success":6},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)

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

app.get(
    '/insert_bulk_with_nano_timestamp', function(req, res) {
        const Data = {
            values: [["sensor1", 1609930804000000000, 2.0], ["sensor1", 1609930805000000000, 2.5], ["sensor1", 1609930806000000000, 2.0], ["sensor2", 1609930804000000000, 2.0], ["sensor2", 1609930805000000000, 2.5], ["sensor2", 1609930806000000000, 2.0]]
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
            body: JSON.stringify(Data)
        };
        request.post( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"fail":0,"success":6},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)

app.listen(8888, function() {
    console.log('http://127.0.0.1:8888/insert_bulk_with_nano_date_time_string is result for insert bulk data with nano date time string')
    console.log('http://127.0.0.1:8888/insert_bulk_with_nano_timestamp is result for insert bulk data with nano timestamp')
})
 python

github

"""
Example For Insert Bulk 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/bulk"

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

# CASE - Insert Bulk Data with nano date time string format

params = {
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
    'values': [["sensor1","2021-01-06 18:00:00 001:000:000", 2.0], ["sensor1","2021-01-06 18:00:00 002:000:000", 2.5], ["sensor1","2021-01-06 18:00:00 003:000:000", 2.0], ["sensor2","2021-01-06 18:00:00 001:000:000", 2.0], ["sensor2","2021-01-06 18:00:00 002:000:000", 2.5], ["sensor2","2021-01-06 18: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":6},"status":"success"}


# CASE - Insert Bulk Data with nano date time string format


params = {
    'values': [["sensor1", 1609930804000000000, 2.0], ["sensor1", 1609930805000000000, 2.5], ["sensor1", 1609930806000000000, 2.0], ["sensor2", 1609930804000000000, 2.0], ["sensor2", 1609930805000000000, 2.5], ["sensor2", 1609930806000000000, 2.0]]
}

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

 

  • No labels