DELETE Beacon – Client examples

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Delete Beacon client demonstrates deleting a Beacon using 'request' node module.
 * If a Beacon is added to the zone then it will not be deleted and an error response will be returned.
 * A Beacon can only be deleted if it is not added to any zone, in any of the applications of the user's account.
 */
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 bdBeaconId = "29d0571f-cfb3-459f-a346-6e11a351ad31"; // This is the Id of the Beacon to be deleted. This can be retrieved through the GET Beacons API.
  
var options = {
    uri: "https://api.bluedotinnovation.com/1/beacons?customerApiKey=" + bdCustomerApiKey + "&beaconId=" + bdBeaconId,
    method: "DELETE"
};
  
request ( options,
    function (error, response, body) {
        if (error) {
            console.log(error);
        }
        console.log(JSON.stringify(response.body));
    }
);
package com.bluedotinnovation.beacon;
  
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 Beacon client demonstrates deleting a Beacon using Apache HTTP client libraries
 * If a Beacon is added to the zone then it will not be deleted and an error response will be returned.
 * A Beacon can only be deleted if it is not added to any zone, in any of the applications of the user's account.
 */
  
public class DeleteBeacon extends BDCommon {
     
    public static void main(String[] args) throws ParseException, IOException, KeyManagementException, NoSuchAlgorithmException {
          
        String bdCustomerApiKey     = "7cd1ea80-d40e-22e4-84cb-b8ca3a6b879d"; //This key is generated by Bluedot Point Access UI when your account is created
        String bdBeaconId           = "41cca1b8-2e71-41cd-897a-67336c1fc91f"; //Beacon ID generated when creating new Beacons.
        String bdUrl                = "https://api.bluedotinnovation.com/1/beacons?customerApiKey=" + bdCustomerApiKey + "&beaconId=" + bdBeaconId;
          
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
        HttpDelete request    = new HttpDelete(bdUrl);
        HttpResponse response = httpRestClient.execute(request);
        JSONParser parser     = new JSONParser();
         
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println("Beacon 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 {
            System.out.println("Error in deleting Beacon");
            InputStream inputStream = response.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json error result
            System.out.println(resultString);
        }
    }
}
package com.bluedotinnovation.beacon;
  
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 Beacon client demonstrates deleting a Beacon using Apache HTTP client libraries
 * If a Beacon is added to the zone then it will not be deleted and an error response will be returned.
 * A Beacon can only be deleted if it is not added to any zone, in any of the applications of the user's account.
 */
  
public class DeleteBeacon extends BDCommon {
     
    public static void main(String[] args) throws ParseException, IOException, KeyManagementException, NoSuchAlgorithmException {
          
        String bdCustomerApiKey     = "7cd1ea80-d40e-22e4-84cb-b8ca3a6b879d"; //This key is generated by Bluedot Point Access UI when your account is created
        String bdBeaconId           = "41cca1b8-2e71-41cd-897a-67336c1fc91f"; //Beacon ID generated when creating new Beacons.
        String bdUrl                = "https://api.bluedotinnovation.com/1/beacons?customerApiKey=" + bdCustomerApiKey + "&beaconId=" + bdBeaconId;
          
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
        HttpDelete request    = new HttpDelete(bdUrl);
        HttpResponse response = httpRestClient.execute(request);
        JSONParser parser     = new JSONParser();
         
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println("Beacon 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 {
            System.out.println("Error in deleting Beacon");
            InputStream inputStream = response.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json error result
            System.out.println(resultString);
        }
    }
}
Created by Bluedot DevOps on March 5, 2018

Start the discussion