Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
minLevel1
maxLevel7
typeflat

This API deletes the calculated data automatically created by Machlake. Since this calculated data is designed not to be deleted even if the original tag data is deleted, a separate deletion process is required. All data before the time specified as base_time can be deleted. If this value is not specified, all data existing in calculated will be deleted.Machlake에 의해서 자동생성된 통계데이터를 삭제한다. 자동생성된 통계데이터는 원시 데이터가 삭제되어도 같이 삭제되지 않으므로 별도의 API호출이 필요하다. Base_time매개변수의 포멧은 Single Tag Value Delete API와 동일하며, base_time 매개변수를 지정하지 않으면 모든 통계 데이터가 삭제된다.

HTTP Request

Code Block
DELETE https://${CloudVendor}.${CountryCode}.machlake.com/lakes/${lake_id}/values/calculated
Content-Type: application/json; charset=utf8
x-api-key: {API Key}
  
{
    "base_time" : "{time}"
}

...

Code Block
Status 200

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

Sample Code

Expand
titlewindow(batch)

github

Code Block
chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Delete Calculated 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/calculated

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

:: CASE - Delete Calculated Data

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

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

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

set BASE_TIME=\"1609930800\"

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

:: ------------------------------------------------------------------------------------------------- ::
Expand
titlelinux(shell)

github

Code Block
# Text Encoding to UTF-8 in CMD
# Example For Delete Calculated 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/calculated

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

# CASE - Delete Calculated Data

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

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

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

BASE_TIME="\"1609930800\""

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

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

github

Code Block
// Example For Delete Calculated 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/calculated";

// CASE - Delete Calculated Data

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

        const Data = {
            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 Calculated Data WITH second time stamp

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

        const Data = {
            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_calculate_with_date_string is result for delete calculated data with date time string')
    console.log('http://127.0.0.1:8888/delete_calculate_with_timestamp is result for delete calculated data with timestamp')
})

...

titlepython

github

...