Versions Compared

Key

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

...

Expand
titlejavascript

github

Code Block
languagejs
// Example For Delete 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 + ""CLOUD_VENDOR";
const CLOUD_REGION="CLOUD_REGION";
const URL =  `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/v1/lakes/tags"${LAKE_ID}/tags`;

//var CASErequest - delete error when no exist tag name

app.get(
    '/delete_tag_name_sensor', function(req, res) {
        const Data = {
            name: 'sensor',
        }
        var request = require('request');
        var option = {
            url: URL,= require('request');


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

// CASE - delete tag

request.delete({
    url: URL, 
    headers: {
        "Content-Type": "application/json",
        "x-api-key": API_KEY
    },
    qs: {
        name: "sensor1"
  headers: { }}, 
    function(error, response, body) {
      'Content-Type': 'application/json',
 console.log(body);
        // Return Format
    'x-api-key': API_KEY   // {
        },//     "success":true,
       body: JSON.stringify(Data) //         };
        request.delete( option, function(error, response, body) {"reason":"delete tag meta success"
        // }
    if (!error})
{
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{},"status":"success"} or {"message":"no such name : sensor1","status":"error"}
     /* ------------------------------------------------------------------------------------------------- */

// CASE - delete error when no exist tag name

request.delete({
    url: URL, 
    headers: } else {
           "Content-Type": "application/json",
    console.log(error)    "x-api-key": API_KEY
    },
  }  qs: {
     })   name: "sensor1"
 } )  //}}, CASE
- delete tag  app.get(
    '/delete_tag_name_sensor1', function(req, res) {function(error, response, body) {
        console.log(body);
        // constReturn DataFormat
= {       // status code:400 Bad Request
 name: 'sensor1',      // {
 }       //  var request = require('request'); "success":false,
        var// option = {  "reason":"no such name:wrong_name"
        url: URL,// }
    })
Expand
titlepython

github

Code Block
languagepy
"""
Example For Delete Tag API by headers:using {requests in python
written by yeony kim
sensor1, sensor2 is applied in lake
"""

import requests
'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
            body: JSON.stringify(Data)
        };
        request.delete( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{},"status":"success"} or {"message":"no such name : sensor1","status":"error"}
            } else {
                console.log(error)
            }
        })
    }
)

// CASE - delete tag

app.get(
    '/delete_tag_name_sensor2', function(req, res) {
        const Data = {
            name: 'sensor2',
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
            body: JSON.stringify(Data)
        };
        request.delete( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{},"status":"success"} or {"message":"no such name : sensor1","status":"error"}
            } else {
                console.log(error)
            }
        })
    }
)

app.listen(8888, function() {
    console.log('http://127.0.0.1:8888/delete_tag_name_sensor is result for delete sensor tag (error)')
    console.log('http://127.0.0.1:8888/delete_tag_name_sensor1 is result for delete sensor1 tag')
    console.log('http://127.0.0.1:8888/delete_tag_name_sensor1 is result for delete sensor2 tag')
})
Expand
titlepython

github

Code Block
"""
Example For Delete Tag API by using requests 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"
headers = {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY
}

# CASE - delete error when no exist tag name

params = {
    'name': 'sensor',
}

response = requests.delete(URL, headers=headers,  json=params, verify=False)
print(response.content.decode('utf-8'))  # {"message":"no such name : sensor","status":"error"}

# CASE - delete tag

params = {
    'name': 'sensor1',
}

response = requests.delete(URL, headers=headers,  json=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{},"status":"success"}

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 - delete tag

params = {
    "name": "sensor",
}

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

# Return Format
# {
#     "success":true,
#     "reason":"delete tag meta success"
# }

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

# CASE - delete error when no exist tag name

params = {
    '"name'": 'sensor2'"wrong_name",
}

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

# Return Format
# status code:400 Bad Request
# {"data
#     "success":{},"statusfalse,
#     "reason":"success"}no such name:wrong_name"
# }