Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

Version 1 Current »

이 API를 이용하면 특정한 Tag의 데이터를 삭제할 수 있다. Tag_name, base_time값에 해당하는 센서 데이터가 삭제된다. Base_time 매개변수를 지정하지 않으면 해당 tag의 모든 데이터가 삭제된다. 시간값을 지정하는 기본 포멧은 "YYYY-MM-DD HH24:MI:SS" 이다. 자세한 내용은 링크에 기술되어 있다.

HTTP Request

DELETE https://${CloudVendor}.${CountryCode}.machlake.com/lakes/${lake_id}/values/raw
Content-Type: application/json; charset=utf8
x-api-key: {API Key}
  
{
    "tag_name"   : "{name_of_tag}",
    "base_time"  : "{end_time}"
}

Parameters

No parameters.

Request Example

DELETE https://aws1.us.machlake.com/lakes/xbacd1234/values/raw
Content-Type: application/json; charset=utf8
x-api-key: {API Key}
{
    "tag_name"   : "tag_01",
    "base_time"  : "2021-07-06 12:13:00"
}

Response Example

Status 200

{
    "status": "success",
    "data": {}
}

Sample Code

 window(batch)

github

chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Delete Single Data for tag API by using curl in window script
:: written by yeony kim

set API_KEY=YOUR_API_TOKEN

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%.machlake.com/lakes/values/raw

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

:: CASE - DELETE TAG DATA WITH TIME String

set TAG_NAME=sensor1
set BASE_TIME=\"2021-01-06 18:00:00 000:000:000\"

curl -k -X DELETE %URL% -H %CONTENT_HEADER% -H %API_HEADER% -d "{\"tag_name\": \"%TAG_NAME%\", \"base_time\": %BASE_TIME%}"

:: Return Format / not exist tag name in lake
:: {"data":{},"status":"success"}

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

:: CASE - DELETE TAG DATA WITH second time stamp

set TAG_NAME=sensor2
set BASE_TIME=\"1609930800\"

curl -k -X DELETE %URL% -H %CONTENT_HEADER% -H %API_HEADER% -d "{\"tag_name\": \"%TAG_NAME%\", \"base_time\": %BASE_TIME%}"
:: Return Format
:: {"data":{},"status":"success"}

:: ------------------------------------------------------------------------------------------------- ::
 linux(shell)

github

 # Text Encoding to UTF-8 in CMD
 # Example For Delete Single Data for 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/values/raw

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

 # CASE - DELETE TAG DATA WITH TIME String

 TAG_NAME=sensor1
 BASE_TIME="\"2021-01-06 18:00:00 000:000:000\""

curl -k -X DELETE $URL -H $CONTENT_HEADER -H $API_HEADER -d "{\"tag_name\": \"$TAG_NAME\", \"base_time\": $BASE_TIME}"

 # Return Format / not exist tag name in lake
 # {"data":{},"status":"success"}

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

 # CASE - DELETE TAG DATA WITH second time stamp

 TAG_NAME=sensor2
 BASE_TIME="\"1609930800\""

curl -k -X DELETE $URL -H $CONTENT_HEADER -H $API_HEADER -d "{\"tag_name\": \"$TAG_NAME\", \"base_time\": $BASE_TIME}"
 # Return Format
 # {"data":{},"status":"success"}

 # -------------------------------------------------------------------------------------------------  #
 javascript

github

// Example For Delete Single Data for tag API by using request in node js
// 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 ="https://" + LAKE_ID +".machlake.com/lakes/values/raw";

// CASE - DELETE TAG DATA WITH TIME String

app.get(
    '/delete_data_with_date_string', function(req, res) {
        var request = require('request');

        const Data = {
            tag_name: 'sensor1',
            base_time: "2021-01-06 18:00:00 000:000:000"
        }
        
        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"}
            } else {
                console.log(error)
            }
        })
    }
)

// CASE - DELETE TAG DATA WITH second time stamp

app.get(
    '/delete_data_with_timestamp', function(req, res) {
        var request = require('request');

        const Data = {
            tag_name: 'sensor2',
            base_time: "1609930800"
        }
        
        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"}
            } else {
                console.log(error)
            }
        })
    }
)

app.listen(8888, function() {
    console.log('http://127.0.0.1:8888/delete_data_with_date_string is result for delete tag data with date time string')
    console.log('http://127.0.0.1:8888/delete_data_with_timestamp is result for delete tag data with timestamp')
})
 python

github

"""
Example For Delete Single 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/raw"

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

# CASE - DELETE TAG DATA WITH TIME String

params = {
    'tag_name': 'sensor1',
    'base_time': "2021-01-06 18:00:00 000:000:000"
}

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


# CASE - DELETE TAG DATA WITH second time stamp

params = {
    'tag_name': 'sensor2',
    'base_time': '1609930800'
}

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


 

  • No labels