Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
minLevel1
maxLevel7
typeflat

This API creates a data lake for the user to use. Define the Tag of the data lake to be created, its extended columns and Values, and its definite columns. And, don't forget to design well in advance because the data structure determined in this way cannot be changed. The last created Data Lake incurs an immediate cost, so call it with cautionis 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

Paste code macro
languagehttp
themeSunburst
POST https://api${CloudVendor}.${CountryCode}.machlake.com/v1/lakes/${lake_id}/values
Content-Type: application/json; charset=utf8
x-api-key: {API Key}
  
{
    "lake_info""date_format"   : "{date_format}",
    "values"        : [
        ["{tag_name1}", "{time1}", {value1}], 
        ["lake(tag_namename2}", "{time2}", {value2}], 
        ...
    ]
}

Parameters

no parameters

Request Example

Paste code macro
languagehttp
themeSunburst
POST https://aws1.us.machlake.com/v1/lakes/xbacd1234/values
Content-Type: application/json; charset=utf8
x-api-key: {API Key}
 
{
"{lake_name}",    "date_format"   : "YYYY-MM-DD HH24:MI:SS",
    "values"        : [
        ["lake_tier"    : "{lake_tier}"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

Paste code macro
languagejson
themeSunburst
Status 200
 
{
    "success": true,
    "reason": "append success",
    "data": {
   "lake_type"    : "{lake_type}",
        "owner"        : "{owner}" 
    },
    "tag_schema"   : [
       {
        "col_name"   : "{column name}",
        "col_type"   : "{column type}",
        "col_length" : "{column length}"
       },
       ......
    ],
    "value_schema" : [
       {
        "col_name"   : "{column name}",
        "col_type"   : "{column type}     "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

Expand
titlewindow(batch)

github

Code Block
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}
:: }
Expand
titlelinux(shell)

github

Code Block
languagebash
# 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}
# }
Expand
titlejavascript

github

Code Block
languagejs
// 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",
        
"col_length" : "{column length}" },
"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]
    ]
}

Parameters

...

Prerequisites

...

Key

...

Type

...

Description

...

lake_name

...

string

...

lake name

...

lake_type

...

string

...

Type of Lake

N or M, Can be omitted

(N when omitted)

...

lake_tier

...

string

...

free / basic / small / enterprise

...

owner

...

string

...

Lake's Owner

(When omitted, the user who calls the API)

...

Optional

...

Key

...

Type

...

Description

...

tag_schema

...

JSON

...

additional columns for this lake's Tag meta col_name : column name col_type : column type (long or string) col_length : if string type, assign length

...

value_schema

...

JSON

...

additional columns for this lake's Tag Table col_name : column name col_type : column type (long or string) col_length : if string type, assign length

Request Example

Paste code macro
languagejson
themeSunburst
POST https://api.machlake.com/lakes Content-Type: application/json; charset=utf8 x-api-key: {API Key} { "lake_info" : {


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}
        // }
    });
Expand
titlepython

github

Code Block
languagepy
"""
Example For Insert Bulk 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"

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


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

# CASE - Insert Data with nano date time string format

params = {
    "date_format": "YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn",
    "values": [
        
"lake_name" : "My Lake",
["sensor1","2021-01-06 18:00:00 001:000:000", 2.0], 
        ["sensor1","2021-01-06 18:00:00 002:000:000", 2.5], 
        
"lake_tier" : "free",
["sensor1","2021-01-06 18:00:00 003:000:000", 2.0], 
        ["sensor2","2021-01-06 18:00:00 001:000:000", 2.0], 
        
"lake_type"
["sensor2","2021-01-06 18:00:00 002:000:000", 2.5], 
        ["sensor2","2021-01-06 18:00:
"N",
00 003:000:000", 2.0]
    ]
}

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

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

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

# CASE - Insert Data with nano date time stamp

params = {
    "
tag_schema"
values": [
      
:
  ["sensor1", 1609930804000000000, 2.0], 
        
{
["sensor1", 1609930805000000000, 2.5], 
        ["
col_name
sensor1", 1609930806000000000, 2.0], 
       
:
 ["
corr-X
sensor2", 1609930804000000000, 2.0], 
        ["
col_type"
sensor2", 1609930805000000000, 2.5], 
       
:
 ["
long
sensor2", 1609930806000000000, 2.0]
    ]
}

response = 
]
requests.post(URL, headers=headers,  json=params, verify=False)
"value_schema" : [
print(response.content.decode("utf-8"))

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

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

# CASE - 
"col_name" : "testcol",
Insert Data with UTC-0 timezone

params = {
    "timezone": "Africa/Abidjan",
    "values": [
        ["sensor1","2021-01-06 18:00:00 001:000:000", 2.0], 
        
"col_type" : "string",
["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], 
        
"col_length" : 128
["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 Example

Paste code macro
languagejson
themeSunburst
Status 200


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

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