Versions Compared

Key

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

...

Paste code macro
languagehttp
themeSunburst
POST https://${CloudVendor}.${CountryCode}.machlake.com/v1/lakes/${lake_id}/tags
 
{
    "tag" : [["{tag_name}", {additional value 1}, "{additional value 2}"], [ second tag values ], ...]
}

...

Request Example

Paste code macro
languagejsonhttp
themeSunburst
POST https://${CloudVendor}.${CountryCode}aws1.us.machlake.com/v1/lakes/${lake_id}xbacd1234/tags

{
    "tag" : [["newtag01"], ["newtag02"]]
}

...

Paste code macro
languagejson
themeSunburst
Status 200
 
{
    "success": true,
    "statusreason" : "create tag success",
    "data"   : {
        "success_count": 2,
        "tag": [
            {"name": "newtag01"},
            {"name": "newtag02"}
        ]
    }
}

...

Expand
titleWindow(Batch)

github

Code Block
chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Create Tag API by using curl in window script
:: written by yeony kim

set API_KEY=YOUR_API_TOKENKEY

set CONTENTLAKE_HEADER="Content-Type: application/json"
set API_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 LAKE_ID=YOUR_LAKE_ID
 set URL="https://%LAKE_ID%%CLOUD_VENDOR%.%CLOUD_REGION%.machlake.com/v1/lakes/%LAKE_ID%/tags"

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

:: CASE - create TAG

curl:: -kdata -Xformat
POST:: %URL%{
-H %CONTENT_HEADER% -H %API_HEADER% --data "{\"tag\": [[\"sensor1\"], [\"sensor2\"]]}"

:: Return Format
:: {"data":{"success_count":2,"tag":[{"name":"sensor1"},{"name":"sensor2"}]},"status":"success"}

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

:: CASE - tag duplicate error

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data "{\"tag\": [[\"sensor1\"], [\"sensor2\"]]}"

:: Return Format / Example For Exist same tag name in lake
:: {"message":"Metadata key (sensor2) of TAGDATA table is already inserted.","status":"error"::     "tag":[
::         ["sensor1"], 
::         ["sensor2"]
::     ]
:: }

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data "{\"tag\": [[\"sensor1\"], [\"sensor2\"]]}"

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

:: ------------------------------------------------------------------------------------------------- ::
Expand
titleLinux(Shell)

github

Code Block
#
Text

Encoding
:: 
to
CASE 
UTF
-
8
 
in
Create 
CMD
Tag 
#
with 
Example
addition 
For
columns
Create 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/tags # ------------------------------------------------------------------------------------------------- # # CASE - create TAG curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER --data "{\"tag\": [[\"sensor1\"], [\"sensor2\"]]}" # Return Format # {"data":{
:: columns
:: name (varchar, 80), location (varchar, 40)

:: data format
:: {
::     "tag":[
::         ["sensor01", "3F-101"],
::         ["sensor02", "3F-102"]
::     ]
:: }

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER% -d "{\"tag\":[[\"sensor01\",\"3F-101\"],[\"sensor02\",\"3F-102\"]]}"

:: Return Format
:: {
::     "success":true,
::     "reason":"create tag success",
::     "data":{
::         "success_count":2,
"

::         "tag":[
::             {
"name

::                 "location":"
sensor1
3F-101"
}
,
{"name":"sensor2"}]},"status":"success"} # -------------------------------------

::                 "name":"sensor01"
::             },
::             {
::                 "location":"3F-102",
::                 "name":"sensor02"
::             }
::         ]
::     }
:: }

:: ------------------------------------------------------------
# # CASE - tag duplicate error curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER --data "{\"tag\": [[\"sensor1\"], [\"sensor2\"]]}" # Return Format / Example For Exist same tag name in lake # {"message":"Metadata key (sensor2
------------------------------------- #

:: CASE - Create exist Tag

:: data format
:: {
::     "tag":[["sensor1"]]
:: }

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER% -d "{\"tag\":[[\"sensor1\"]]}"

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

:: }
// Example For Create Tag API by using request in nodejs // written by yeony kim 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/tags"; // CASE - create TAG / tag duplicate error app.get( '/create_tag_sensor1_2', function(req, res) { const Data = {
Expand
titleLinux(Shell)

github

Code Block
languagebash
# Text Encoding to UTF-8 in CMD
# Example For Create 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}/tags

# -----------------------------------------------------------------------
#
Expand
titlejavascript

github

Code Block
languagejs
-------------------------- #

# CASE - Create Tag

# data format
# {
#     "tag":[
#         ["sensor1"], 
#         ["sensor2"]
#     ]
# }

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER -d "{\"tag\":[[\"sensor1\"], [\"sensor2\"]]}"

# Return Format
# {
#     "success":true,
#     "reason":"create tag success",
#     "data":{
#       
tag:
 
[['sensor1'], ['t_sensor1'], ['t_sensor2']],
 "success_count":2,
#         
}
"tag":[
#        
var
 
request
 
=
 
require('request');
  {"name":"sensor1"},
#      
var
 
option
 
=
 
{
    {"name":"sensor2"}
#        
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) {
# ------------------------------------------------------------------------------------------------- #

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

# data format
# {
#     "tag":[
#         ["sensor01", "3F-101"],
#         
res.writeHead(200);
["sensor02", "3F-102"]
#     ]
# }

curl -k -X POST $URL 
res.end(body); console.log(body) // {"data":{"success_count":2,"tag":[{"name":"sensor1"},{"name":"sensor2"}]},"status":"success"} or {"message":"Metadata key (sensor2) of TAGDATA table is already inserted.","status":"error"} } else {
-H $CONTENT_HEADER -H $API_HEADER -d "{\"tag\":[[\"sensor01\",\"3F-101\"],[\"sensor02\",\"3F-102\"]]}"

# Return Format
# {
#     "success":true,
#     "reason":"create tag success",
#     "data":{
#         
"success_count":2,
#     
console.log(error)
    "tag":[
#        
}
     {
#   
})
     
}
 
)
  
app.listen(8888,
 
function()
 
{
    
console.log('http://127.0.0.1:8888/create_tag_sensor1_2 is result for create sensor1 and sensor2 tag') }) 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" URL = f"https://{LAKE_ID}.machlake.com/lakes/tags" # CASE - create TAG / tag duplicate error headers = { 'Content-Type': 'application/json', 'x-api-key': API_KEY }
"location":"3F-101",
#                 "name":"sensor01"
#             },
#             {
#                 "location":"3F-102",
#                 "name":"sensor02"
#             }
#         ]
#     }
# }

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

# CASE - Create exist Tag

# data format
# {
#     "tag":[["sensor1"]]
# }

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER -d "{\"tag\":[[\"sensor1\"]]}"

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

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}/tags"

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


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

# 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'], ['sensor2']],

        ["sensor1"]
    ]
}

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

# Return Format
# status code:400 Bad Request
# {
#    
#
 
{
"
data":{"
success
_count
":
2,"tag
false,
#     "reason":
[{"name":"sensor1"},{"name":"sensor2"}]},"status":"success"}
"Metadata key (sensor1) of TAGDATA table is already inserted."
# }