POST Create Application – Client examples

Create Application

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Create Application client demonstrates adding an application to your Bluedot backend
 * using the 'request' node module.
 */
var request = require('request');
var applicationData = {
    "security": {
        /* This key is generated by Bluedot Point Access UI when your account is created. It is also available
         * on the PointAccess interface in the Edit Profile section. */
        "customerApiKey": "86577370-7b91-11e4-bcb7-a0481cdc3311"
    },
    "content": {
        "application" : {
            "name" : "A Bluedot Application",
            "packageName": "au.com.bluedot.creationtest",
            /* Time in Hour:Minute format.*/
            "nextRuleUpdateIntervalFormatted": "00:07"
        }
    }
};
var options = {
    uri: 'https://api.bluedotinnovation.com/1/applications',
    method: 'POST',
    json: applicationData
};
request ( options,
    function (error, response, body) {
        if (error) {
            console.log(error);
        }
        console.log(JSON.stringify(response.body));
    }
);

Create Application with Webhook

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Add Application with Webhook client demonstrates adding an application for which a Webhook will be enabled, to your Bluedot backend
 * using the 'request' node module.
 */
var request = require('request');
var applicationData = {
    "security": {
        /* The customerApiKey is generated when customer registers first time. It is also available
         * on the PointAccess interface in the Edit Profile section. */
        "customerApiKey": "86577370-7b91-11e4-bcb7-a0481cdc3311"
    },
    "content": {
        "application" : {
            "name" : "A Bluedot Application",
            "packageName": "com.bluedot.creationtest",
            /* Time in Hour:Minute format.*/
            "nextRuleUpdateIntervalFormatted": "00:07",
            "webhook": {
                /*The URL of the server where the webhooks will be received.*/
                "url": "https://api.campusapp.com/webhook/checkinreceiver",
                "enabled": true,
                /*The Security Token Key is the name of the field to be sent in the POST request header.*/
                "securityTokenKey": "authToken",
                /*The Security Token Value field is value of the Security Token Key field sent in the POST request header.*/
                "securityTokenValue": "f2f7a58c-f0d5-498c-9bad-acbc89923dc5"
            }
        }
    }
};
var options = {
    uri: 'https://api.bluedotinnovation.com/1/applications',
    method: 'POST',
    json: applicationData
};
request ( options,
    function (error, response, body) {
        if (error) {
            console.log(error);
        }
        console.log(JSON.stringify(response.body));
    }
);

Create Application with Zones Sync enabled

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Create Application Zones Sync Enabled client demonstrates adding an application to your Bluedot backend
 * using the 'request' node module for which the zones sync will be available using Firebase push.
 */
var request = require('request');
var applicationWithZonesSync = {
    "security": {
        /* This key is generated by Bluedot Point Access UI when your account is created. It is also available
         * on the PointAccess interface in the Edit Profile section. */
        "customerApiKey": "86577370-7b91-11e4-bcb7-a0481cdc3311"
    },
    "content": {
        "application" : {
            "name" : "A Bluedot Application",
            "packageName": "au.com.bluedot.creationtest",
            /* Time in Hour:Minute format.*/
            "nextRuleUpdateIntervalFormatted": "00:07",
            /*The Web API key from Firebase project settings.
             * Using this key our backend will be able to communicate with Firebase to deliver the
             * zones that need to be synced to your application.*/
            "firebaseApiKey": "gDZyt1Bj_Y6S8BKyQfKH6uZ9wc475hrRlGA_6lS"
        }
    }
};
var options = {
    uri: 'https://api.bluedotinnovation.com/1/applications',
    method: 'POST',
    json: applicationWithZonesSync
};
request ( options,
    function (error, response, body) {
        if (error) {
            console.log(error);
        }
        console.log(JSON.stringify(response.body));
    }
);

Create Application

package com.bluedotinnovation.application;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
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;
import com.bluedotinnovation.common.BDCommon;
/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Add application client demonstrates adding an application to your Bluedot backend using Apache HTTP client and JSON Simple libraries.
 */
public class AddApplication extends BDCommon {
     
    private static String bdRestUrl = "https://api.bluedotinnovation.com/1/applications";
     
    /**
     * @param args
     * @throws IOException
     * @throws ParseException
     * @throws NoSuchAlgorithmException
     * @throws KeyManagementException
     */
    public static void main(String[] args) throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException {
         
        String bdCustomerApiKey    = "7cd1ea80-d40e-11e4-84cb-b8ca3a6b879f"; //This key is generated by Bluedot Point Access UI when your account is created
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
         
        String application =
            "{" +
                "\"security\": {" +
                    "\"customerApiKey\":" +"\"" +bdCustomerApiKey + "\"" +
                "}," +
                "\"content\": {"
                    +"\"application\" : {"+
                        "\"name\" : \"Java-Test Application-After-Create\"," +
                        "\"packageName\": \"com.bluedot.creationtestbdtestere\"," +
                        "\"nextRuleUpdateIntervalFormatted\": \"00:10\"" +
                    "}"+
                "}"+
            "}";
                     
        JSONObject bdApplicationJSONObject;    
        JSONParser parser       = new JSONParser();
        bdApplicationJSONObject = (JSONObject)  parser.parse(application);
           
        HttpPost postRequest = new HttpPost(bdRestUrl);
        postRequest.addHeader("content-type", "application/json");
        postRequest.setEntity(new StringEntity(bdApplicationJSONObject.toJSONString(), Charset.defaultCharset()));
      
        HttpResponse response = httpRestClient.execute(postRequest);
         
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println("Application was successfully created");
            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("apiKey for your application is : " + jsonResult.get("apiKey"));
        } else {
            InputStream inputStream = response.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json error result
            System.out.println(resultString);
        }          
    }
}

Create Application with Webhook

package com.bluedotinnovation.application;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
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;
import com.bluedotinnovation.common.BDCommon;
/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Add Application with Webhook client demonstrates adding an application for which a Webhook will be enabled,
 * to your Bluedot backend using Apache HTTP client and JSON Simple libraries.
 */
public class AddApplicationWithWebhook extends BDCommon {
     
    private static String bdRestUrl = "https://api.bluedotinnovation.com/1/applications";
     
    /**
     * @param args
     * @throws IOException
     * @throws ParseException
     * @throws NoSuchAlgorithmException
     * @throws KeyManagementException
     */
    public static void main(String[] args) throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException {
         
        String bdCustomerApiKey    = "7cd1ea80-d40e-11e4-84cb-b8ca3a6b879f"; //This key is generated by Bluedot Access UI when you register
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
         
        String applicationWithWebhook =
                "{"+
                    "\"security\": {"+
                        "\"customerApiKey\":" +"\"" +bdCustomerApiKey + "\"" +
                    "}," +
                    "\"content\": {"+
                        "\"application\": {"+
                            "\"name\" : \"Java-Test Application-After-Create\"," +
                            "\"packageName\": \"com.bluedot.creationtestbdtester\"," +
                            "\"nextRuleUpdateIntervalFormatted\": \"00:10\"," +
                            "\"webhook\": {" +
                                //The URL of the server where the webhooks will be received.
                                "\"url\": \"https://api.bdtester.com/webhook/checkinreceiver\"," +
                                "\"enabled\" : true," +
                                //The Security Token Key is the name of the field to be sent in the POST request header.
                                "\"securityTokenKey\" : \"authToken\"," +
                                //The Security Token Value field is value of the Security Token Key field sent in the POST request header.
                                "\"securityTokenValue\" : \"f2f7a58c-f0d5-498c-9bad-acbc89923dc5\"" +
                            "}"+
                        "}"+
                    "}"+
                "}";
                     
        JSONObject bdApplicationJSONObject;    
        JSONParser parser       = new JSONParser();
        bdApplicationJSONObject = (JSONObject)  parser.parse(applicationWithWebhook);
           
        HttpPost postRequest = new HttpPost(bdRestUrl);
        postRequest.addHeader("content-type", "application/json");
        postRequest.setEntity(new StringEntity(bdApplicationJSONObject.toJSONString(), Charset.defaultCharset()));
      
        HttpResponse response = httpRestClient.execute(postRequest);
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println("Application was successfully created");
            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("apiKey for your application is : " + jsonResult.get("apiKey"));
        } else {
            InputStream inputStream = response.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json error result
            System.out.println(resultString);
        }          
    }
}

Create Application with Zones Sync enabled

package com.bluedotinnovation.application;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
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;
import com.bluedotinnovation.common.BDCommon;
/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Add Application Zones Sync Enabled client demonstrates adding an application to your Bluedot backend
 * using Apache HTTP client and JSON Simple libraries for which the zones sync will be available using Firebase push.
 */
public class AddApplicationZonesSyncEnabled extends BDCommon {
     
    private static String bdRestUrl = "https://api.bluedotinnovation.com/1/applications";
     
    /**
     * @param args
     * @throws IOException
     * @throws ParseException
     * @throws NoSuchAlgorithmException
     * @throws KeyManagementException
     */
    public static void main(String[] args) throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException {
         
        String bdCustomerApiKey    = "7cd1ea80-d40e-11e4-84cb-b8ca3a6b879f"; //This key is generated by Bluedot Point Access UI when your account is created.
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
         
        String applicationWithZonesSync =
            "{" +
                "\"security\": {" +
                    "\"customerApiKey\":" +"\"" +bdCustomerApiKey + "\"" +
                "}," +
                "\"content\": {"
                    +"\"application\" : {"+
                        "\"name\" : \"New Application with Zones sync enabled\"," +
                        "\"packageName\": \"com.bluedot.zonesSync.enabled \"," +
                        "\"nextRuleUpdateIntervalFormatted\": \"00:10\"," +
                        /*The Web API key from Firebase project settings.
                         * Using this key our backend will be able to communicate with Firebase to deliver the
                         * zones that need to be synced to your application.*/
                        "\"firebaseApiKey\": \"gDZyt1Bj_Y6S8BKyQfKH6uZ9wc475hrRlGA_6lS\"" +
                    "}"+
                "}"+
            "}";
                     
        JSONObject bdApplicationJSONObject;    
        JSONParser parser       = new JSONParser();
        bdApplicationJSONObject = (JSONObject)  parser.parse(applicationWithZonesSync);
           
        HttpPost postRequest = new HttpPost(bdRestUrl);
        postRequest.addHeader("content-type", "application/json");
        postRequest.setEntity(new StringEntity(bdApplicationJSONObject.toJSONString(), Charset.defaultCharset()));
      
        HttpResponse response = httpRestClient.execute(postRequest);
         
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println("Application with Zones Sync enabled was successfully created");
            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("apiKey for your application is : " + jsonResult.get("apiKey"));
        } else {
            InputStream inputStream = response.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json error result
            System.out.println(resultString);
        }          
    }
}

Create Application

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.
 * Create Application client demonstrates adding an application to to an existing the customer's account using .net http web api library
 */
 
namespace BluedotPublicApiClient.applicationclient
{
    public class CreateApplication
    {
        public void create()
        {
            String bdCustomerApiKey = "76e1ae30-c616-11e5-a7c0-b8ca3a6b879d"; //This key is generated by Bluedot Point Access UI when your account is created
            String bdRestUrl        = "https://api.bluedotinnovation.com/1/applications";
 
            String application =
               "{" +
                 "\"security\": {" +
                /*
                  customerApiKey is generated when customer registers first time. It is also available
                  on the PointAccess interface in the Edit Profile section.
                */
                         "\"customerApiKey\":" + "\"" + bdCustomerApiKey + "\"" +
               "}," +
               "\"content\": { " +
                   "\"application\" : {" +
                            "\"name\" : \"A Bluedot Application\"," +
                            "\"packageName\": \"com.bluedotinnovation.testapplication\"," +
                            /* Time in Hour:Minute format.*/
                             "\"nextRuleUpdateIntervalFormatted\": \"00:07\"" +
                        "}" +
                   "}" +
             "}";
 
            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;
 
            httpRestClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
 
            HttpContent jsonApplicationContent         = new StringContent(@application);
            jsonApplicationContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
 
            HttpResponseMessage serverResponse         = httpRestClient.PostAsync(new Uri(bdRestUrl), jsonApplicationContent).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);
            }
        }
    }
}

Create Application with Webhook

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.
 * Create Application client demonstrates adding an application to to an existing the customer's account using .net http web api library
 */
 
namespace BluedotPublicApiClient.applicationclient
{
    public class CreateApplicationWithWebhook
    {
        public void create()
        {
            String bdCustomerApiKey = "73ad7b80-7c4e-11e4-a2d3-b8ca3a6b879d"; //This key is generated by Bluedot Access UI when you register
            String bdRestUrl        = "https://api.bluedotinnovation.com/1/applications";
 
            String application =
               "{" +
                    "\"security\": {" +
                    /*
                      customerApiKey is generated when customer registers first time. It is also available
                      on the PointAccess interface in the Edit Profile section.
                    */
                         "\"customerApiKey\":" + "\"" + bdCustomerApiKey + "\"" +
                   "}," +
                   "\"content\": { " +
                       "\"application\" : {" +
                            "\"name\" : \"A Bluedot Application\"," +
                            "\"packageName\": \"com.bluedotinnovation.testapplication\"," +
                            /* Time in Hour:Minute format.*/
                            "\"nextRuleUpdateIntervalFormatted\": \"00:07\"," +
                            "\"webhook\": {" +
                                /*The URL of the server where the webhooks will be received.*/
                                "\"url\": \"https://api.testapplication.com/webhook/checkinreceiver\"," +
                                "\"enabled\" : true," +
                                /*The Security Token Key is the name of the field to be sent in the POST request header.*/
                                "\"securityTokenKey\" : \"authToken\"," +
                                /*The Security Token Value field is value of the Security Token Key field sent in the POST request header.*/
                                "\"securityTokenValue\" : \"f2f7a58c-f0d5-498c-9bad-acbc89923dc5\"" +
                            "}" +
                        "}" +
                    "}" +
                "}";
 
            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;
 
            httpRestClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
 
            HttpContent jsonApplicationContent         = new StringContent(@application);
            jsonApplicationContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
 
            HttpResponseMessage serverResponse         = httpRestClient.PostAsync(new Uri(bdRestUrl), jsonApplicationContent).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);
            }
        }
    }
}

Create Application with Zones Sync enabled

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.
 * Create Application Zones Sync Enabled client demonstrates adding an application to your Bluedot backend
 * using .net http web api library for which the zones sync will be available using Firebase push.
 */
namespace BluedotPublicApiClient.applicationclient
{
    public class CreateApplicationZonesSyncEnabled
    {
        public void create()
        {
            String bdCustomerApiKey = "76e1ae30-c616-11e5-a7c0-b8ca3a6b879d"; //This key is generated by Bluedot Point Access UI when your account is created
            String bdRestUrl        = "https://api.bluedotinnovation.com/1/applications";
            String applicationWithZonesSync =
               "{" +
                 "\"security\": {" +
                /*
                  customerApiKey is generated when customer registers first time. It is also available
                  on the PointAccess interface in the Edit Profile section.
                */
                         "\"customerApiKey\":" + "\"" + bdCustomerApiKey + "\"" +
               "}," +
               "\"content\": { " +
                   "\"application\" : {" +
                            "\"name\" : \"A Bluedot Application\"," +
                            "\"packageName\": \"com.bluedotinnovation.testapplication\"," +
                            /* Time in Hour:Minute format.*/
                             "\"nextRuleUpdateIntervalFormatted\": \"00:07\"," +
                            /*The Web API key from Firebase project settings.
                            * Using this key our backend will be able to communicate with Firebase to deliver the
                            * zones that need to be synced to your application.*/
                            "\"firebaseApiKey\": \"gDZyt1Bj_Y6S8BKyQfKH6uZ9wc475hrRlGA_6lS\"" +
                        "}" +
                   "}" +
             "}";
            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;
            httpRestClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpContent jsonApplicationContent = new StringContent(@applicationWithZonesSync);
            jsonApplicationContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage serverResponse         = httpRestClient.PostAsync(new Uri(bdRestUrl), jsonApplicationContent).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 January 17, 2018

Start the discussion