Versions Compared

Key

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

...

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 express = require('express');
const app =
express();
const API_KEY ="YOUR_API_TOKEN";
const LAKE_ID ="YOUR_LAKE_ID";
const URL CLOUD_VENDOR="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 = {
  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: [
         url: URL,
["sensor1","2021-01-06 18:00:00 001:000:000", 2.0], 
        ["sensor1","2021-01-06  headers: {18:00:00 002:000:000", 2.5], 
           ["sensor1","2021-01-06 18:00:00 003:000:000", 2.0], 
  'Content-Type': 'application/json',     ["sensor2","2021-01-06 18:00:00 001:000:000", 2.0], 
       'x-api-key': API_KEY
   ["sensor2","2021-01-06 18:00:00 002:000:000", 2.5], 
        },
  ["sensor2","2021-01-06 18:00:00 003:000:000", 2.0]
    ]
}

  body: JSON.stringify(Data)request.post({
    url: URL, 
 };   headers: {
    request.post( option, function(error, response, body) { "Content-Type": "application/json",
        "x-api-key": API_KEY
  if (!error) { },
    body: JSON.stringify(Data)
    }, 
    res.writeHead(200);
  function(error, response, body) {
             res.endconsole.log(body);
        // Return Format
       console.log(body) // {"data":{"fail":0,"success":6},"status":"success"}
        //    } else {"success": true,
        //     "reason": "append  console.log(error)success",
        //     }
        })"data": {"fail": 0,"success": 6}
     } )  // 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],  });

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

// CASE - Insert Data with nano date time stamp

var Data = {
    values: [
        ["sensor1", 1609930804000000000, 2.0], 
        ["sensor1", 16099308060000000001609930805000000000, 2.05], 
        ["sensor2sensor1", 16099308040000000001609930806000000000, 2.0], 
        ["sensor2", 16099308050000000001609930804000000000, 2.50], 
        ["sensor2", 16099308060000000001609930805000000000, 2.05]], 
       } ["sensor2", 1609930806000000000, 2.0]
    ]
var}
request.post({
= require('request');   url: URL, 
   var optionheaders: = {
            url: URL"Content-Type": "application/json",
        "x-api-key": API_KEY
  headers: { },
    body: JSON.stringify(Data)
    }, 
   'Content-Type': 'application/json',
   function(error, response, body) {
        console.log(body)
    'x-api-key': API_KEY   // Return Format
       }, // {
        //  body: JSON.stringify(Data)  "success": true,
     };   //      request.post( option, function(error, response, body) {"reason": "append success",
        //     "data": {"fail":  if (!error) {0,"success": 6}
        // }
    });


 res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"fail":0,"success":6},"status":"success"}
     /* ------------------------------------------------------------------------------------------------- */

// CASE - Insert Data with UTC-0 timezone

var Data = {
    timezone: "Africa/Abidjan",
    values: [
      } else {
   ["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}
        // }
    });
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": [
        ["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"))

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

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

console.log(error)
            }# CASE - Insert Data with nano date time stamp

params = {
    "values": [
  })     } )

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

github

Code Block
languagepy
"""
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]["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"))

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

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

# CASE - Insert Data with UTC-0 timezone

params = {
    "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]
    ]
}

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},"status":"success"}
# }