DELETE Fence – Client examples

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Delete Fence client demonstrates deleting a fence using 'request' node module.
 */
var request = require('request');
  
var bdCustomerApiKey = "6ab02370-97c4-11e4-b3f3-00155d53317c"; //This key is generated by Bluedot Point Access UI when your account is created
var bdApplicationApiKey    = "d66d4f5d-7c09-4bd1-8549-48893f121"; //This apiKey is generated when you create an application
var bdZoneId = "4f134aaa-3382-49bb-b7c7-a0bf72e56238"; //This is the id of the zone being updated. This can be fetched by calling GET zones API
var bdFenceId = "916988ef-f0c1-45b8-a719-6dc4b401025e"; //This is the id of the fence being deleted. This can be fetched by calling GET zones API
  
var options = {
    uri: "https://api.bluedotinnovation.com/1/fences?customerApiKey="+ bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey +
        "&zoneId=" + bdZoneId + "&fenceId=" + bdFenceId,
    method: "DELETE"
};
  
request ( options,
    function (error, response, body) {
        if (error) {
            console.log(error);
        }
        console.log(JSON.stringify(response.body));
    }
);
package com.bluedotinnovation.fence;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import com.bluedotinnovation.common.BDCommon;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Delete Fence client demonstrates deleting a fence using Apache HTTP client libraries
 */
public class DeleteFence extends BDCommon {
    public static void main(String[] args) throws ParseException, IOException, KeyManagementException, NoSuchAlgorithmException {
         
        String bdCustomerApiKey     = "0cbfd210-9544-11e4-b884-402cf464abb8"; //This key is generated by Bluedot Point Access UI when your account is created
        String bdApplicationApiKey  = "d3161e80-38d1-11e4-b039-bc305bf60831"; //This apiKey is generated when you create an application
        String bdZoneId             = "d6c3b688-cf2e-4aac-b76b-b29f371f448e"; //This is the id of the zone being updated. This can be fetched by calling GET Zones API
        String bdFenceId            = "2cf924f0-f9a0-4a5a-abf6-4fc18a22db56"; //This is the id of the fence being deleted. This can be fetched by calling GET Zones API
        String bdRestUrl            = "https://api.bluedotinnovation.com/1/fences?customerApiKey="+bdCustomerApiKey+ "&apiKey=" + bdApplicationApiKey +
                "&zoneId=" + bdZoneId + "&fenceId=" + bdFenceId;
         
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
        HttpDelete request    = new HttpDelete(bdRestUrl);
        HttpResponse response = httpRestClient.execute(request);
        JSONParser parser     = new JSONParser();
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println("Fence has been deleted successfully");
            InputStream inputStream = response.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json result
            JSONObject jsonResult   = (JSONObject)  parser.parse(resultString);
            System.out.println(jsonResult);
        } else {
            InputStream inputStream = response.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json error result
            System.out.println(resultString);
        }
    }
}
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Net;
using System.Web.Script.Serialization;
using System.IO;
using System.Security.Cryptography.X509Certificates;
/**
* @author Bluedot Innovation
* Copyright (c) 2016 Bluedot Innovation. All rights reserved.
* Delete Fence client demonstrates deleting a fence using the id provided, through http web api library
*/
namespace BluedotPublicApiClient.fenceclient
{
    class DeleteFence
    {
        public void delete()
        {
            String bdCustomerApiKey     = "835d9460-7b91-11e4-bcb7-a0481cdc3311"; //This key is generated by Bluedot Point Access UI when your account is created
            String bdApplicationApiKey  = "a46fc46a-63ac-4c0c-8a9c-3c9aafd88e46"; //This apiKey is generated when you create an application
            String bdZoneId             = "3846fa1d-11f7-4044-8eab-0977f90d987e"; //This is the id of the zone being updated. This can be fetched by calling zones/getAll API
            String fenceId              = "fe6c357a-5273-4f95-8980-2e37ef2dc115"; //This is the id of the fence being updated. This can be fetched by calling zones/get API
            String bdRestBaseUrl        = "https://api.bluedotinnovation.com/1/fences?";
            String bdRestUrl = bdRestBaseUrl + "customerApiKey=" + bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey + "&zoneId=" + bdZoneId + "&fenceId=" + fenceId;
             
            WebRequestHandler handler = new WebRequestHandler();
            X509Certificate2 certificate = new X509Certificate2();
            handler.ClientCertificates.Add(certificate);
            HttpClient httpRestClient = new HttpClient(handler);
            //specify to use TLS 1.2 as default connection
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            HttpResponseMessage serverResponse = httpRestClient.DeleteAsync(new Uri(bdRestUrl)).Result;
            if (serverResponse.IsSuccessStatusCode)
            {
                var result = serverResponse.Content.ReadAsStringAsync().Result;
                Console.WriteLine("{0}", result);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)serverResponse.StatusCode, serverResponse.Content.ReadAsStringAsync().Result);
            }
        }
    }
}
Created by Bluedot DevOps on March 5, 2018

Start the discussion