DELETE Beacon from Zone – Client examples

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Delete Beacon from Zone client demonstrates dissociating a Beacon added to an existing Zone
 * using 'request' node module.
 */
var request = require('request');
  
var bdCustomerApiKey = "b2a9e860-2890-11e6-8148-0639e7649356"; //This key is generated by Bluedot Point Access UI when your account is created
var bdApplicationApiKey    = "38655d80-3774-11e6-9cb1-0639e7649356"; //This apiKey is generated when you create an application
var bdZoneId = "083ec47c-7785-45dd-8c59-eb7eef96acd7"; //This is the ID of the Zone being updated. This can be retrieved through the GET Zones API.
var bdBeaconId = "09d04533-d421-449b-9fc1-84c89b3a34d1"; //Beacon ID generated when creating new Beacons. This can be retrieved through the GET Beacons API.
  
var options = {
    uri: "https://api.bluedotinnovation.com/1/zones/beacons?customerApiKey=" + bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey +
        "&zoneId=" + bdZoneId + "&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 from Zone client demonstrates dissociating a Beacon added to an existing Zone using Apache HTTP client libraries.
 */
  
public class DeleteBeaconFromZone extends BDCommon {
     
    public static void main(String[] args) throws ParseException, IOException, KeyManagementException, NoSuchAlgorithmException {
          
        String bdCustomerApiKey     = "b2a9e860-2890-11e6-8148-0639e7649356"; //This key is generated by Bluedot Point Access UI when your account is created
        String bdApplicationApiKey  = "38655d80-3774-11e6-9cb1-0639e7649356"; //This apiKey is generated when you create an application
        String bdZoneId             = "083ec47c-7785-45dd-8c59-eb7eef96acd7"; //This is the ID of the Zone being updated. This can be fetched by calling GET Zones API.
        String bdBeaconId           = "09d04533-d421-449b-9fc1-84c89b3a34d1"; //Beacon ID generated when creating new Beacons. This can be fetched by calling GET Beacon API
        String bdUrl                = "https://api.bluedotinnovation.com/1/zones/beacons?customerApiKey="+bdCustomerApiKey+ "&apiKey=" + bdApplicationApiKey +
                "&zoneId=" + bdZoneId + "&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 dissociated successfully from the Zone");
            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 dissociating Beacon from Zone");
            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 Beacon from Zone client demonstrates dissociating a Beacon added to an existing Zone using .Net http web api library.
 */
namespace BluedotPublicApiClient.beaconclient
{
    class DeleteBeaconFromZone
    {
        private static String bdCustomerApiKey      = "b2a9e860-2890-11e6-8148-0639e7649356"; //This key is generated by Bluedot Point Access UI when your account is created
        private static String bdApplicationApiKey   = "38655d80-3774-11e6-9cb1-0639e7649356"; //This apiKey is generated when you create an application
        private static String bdZoneId              = "083ec47c-7785-45dd-8c59-eb7eef96acd7"; //This is the ID of the Zone being updated.
        private static String bdBeaconId            = "09d04533-d421-449b-9fc1-84c89b3a34d1"; //Beacon ID generated when creating new Beacons
        private static String bdRestUrl             = "https://api.bluedotinnovation.com/1/zones/beacons?";
        public void delete()
        {
            bdRestUrl = bdRestUrl + "customerApiKey=" + bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey +
                "&zoneId=" + bdZoneId + "&beaconId=" + bdBeaconId;
            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