- Created by machlake (Unlicensed) , last modified on Feb 21, 2023
You are viewing an old version of this content. View the current version.
Compare with Current View Version History
« Previous Version 12 Current »
This API is an improved method supported by Machlake. The tag name, time, and each value are sent in plain JSON format. However, since this JSON consists of an array of values, inserting data is faster and less expensive.
HTTP Request
Parameters
no parameters
Request Example
Response Example
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
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_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 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 :: { :: "success": true, :: "reason": "append success", :: "data": {"fail": 0,"success": 6} :: } :: ------------------------------------------------------------------------------------------------- :: :: CASE - Insert 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%}" :: { :: "success": true, :: "reason": "append success", :: "data": {"fail": 0,"success": 6} :: }
# Text Encoding to UTF-8 in CMD # Example For Insert Bulk 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 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 # { # "success": true, # "reason": "append success", # "data": {"fail": 0,"success": 6} # } # ------------------------------------------------------------------------------------------------- # # CASE - Insert 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 # { # "success": true, # "reason": "append success", # "data": {"fail": 0,"success": 6} # }
// 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 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 = { 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] ] } 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": 6} // } }); /* ------------------------------------------------------------------------------------------------- */ // CASE - Insert Data with nano date time stamp var 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] ] } 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": 6} // } }); /* ------------------------------------------------------------------------------------------------- */ // CASE - Insert Data with UTC-0 timezone var Data = { timezone: "Africa/Abidjan", 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] ] } 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": 6} // } });
""" 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