Versions Compared

Key

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

...

Expand
titlejavascript

github

Code Block
languagejs
// Example For Create Tag API by using request in nodejs
// written by yeony kim

// 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}/tags`;


var request = require('request');


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

//  CASE - create TAG

var Data = {
    tag: [
        ["sensor1"], 
        ["sensor2"]
    ]
}

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":"create tag success",
        //     "data":{
        //         "success_count":2,
        //         "tag":[
        //             {"name":"sensor1"},
        //             {"name":"sensor2"}
        //         ]
        //     }
        // }
    })

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

//  CASE - create TAG with addition columns

var Data = {
    tag: [
        ["sensor01", "3F-101"],
        ["sensor02", "3F-102"]
    ]
}

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":"create tag success",
        //     "data":{
        //         "success_count":2,
        //         "tag":[
        //             {
        //                 "location":"3F-101",
        //                 "name":"sensor01"
        //             },
        //             {
        //                 "location":"3F-102",
        //                 "name":"sensor02"
        //             }
        //         ]
        //     }
        // }        
    })

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

//  CASE - Create exist Tag

var Data = {
    tag: [
        ["sensor1"]
    ]
}

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
        // status code:400 Bad Request
        // {
        //     "success":false,
        //     "reason":"Metadata key (sensor1) of TAGDATA table is already inserted."
        // }
    })
Expand
titlepython

github

Code Block
languagepy
"""
Example For Create 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"
CLOUD_VENDOR="CLOUD_VENDOR"
CLOUD_REGION="CLOUD_REGION"

URL = f"https://
{LAKE_ID
{CLOUD_VENDOR}.{CLOUD_REGION}.machlake.com/v1/lakes/{LAKE_ID}/tags"
#

CASE

- create TAG / tag duplicate error
headers = {
    
'
"Content-Type
'
": 
'
"application/json
'
",
    
'
"x-api-key
'
": API_KEY
}

params

= { 'tag': [['sensor1'], ['sensor2']], } response = requests.post(URL, headers=headers, json=params, verify=False) print(response.content.decode('utf-8')) # {"data":{"success_count":2,"tag":[{"name":"sensor1"},{"name":"sensor2"}]},"status":"success"}
# ------------------------------------------------------------------------------------------------- #

# CASE - Create Tag

params = {
    "tag": [
        ["sensor1"], 
        ["sensor2"]
    ]
}

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

# Return Format
# {
#     "success":true,
#     "reason":"create tag success",
#     "data":{
#         "success_count":2,
#         "tag":[
#             {"name":"sensor1"},
#             {"name":"sensor2"}
#         ]
#     }
# }

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

# CASE - Create Tag with addition columns
# columns
# name (varchar, 80), location (varchar, 40)

params = {
    "tag":[
        ["sensor01", "3F-101"],
        ["sensor02", "3F-102"]
    ]
}

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

# Return Format
# {
#     "success":true,
#     "reason":"create tag success",
#     "data":{
#         "success_count":2,
#         "tag":[
#             {
#                 "location":"3F-101",
#                 "name":"sensor01"
#             },
#             {
#                 "location":"3F-102",
#                 "name":"sensor02"
#             }
#         ]
#     }
# }

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

# CASE - Create exist Tag

params = {
    "tag": [
        ["sensor1"]
    ]
}

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

# Return Format
# status code:400 Bad Request
# {
#     "success":false,
#     "reason":"Metadata key (sensor1) of TAGDATA table is already inserted."
# }