POST Zones Sync – Client examples

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * The Post Zones Sync client demonstrates how the zones/sync endpoint can be used to sync the newly created, updated or deleted Zones to
 * all mobile devices using your application.
 */
var request = require('request');
var zonesDataSync =
    {
        "security": {
            /* The apiKey is generated when you create an application. */
            "apiKey" : "c2c8211f-796f-4eda-b6ce-05467b5263a9",
            /* 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"
        }
    };
var options = {
    uri: 'https://api.bluedotinnovation.com/1/zones/sync',
    method: 'POST',
    json: zonesDataSync
};
request(options,
    function (error, response, body) {
        if (error) {
            console.log(error);
        }
        console.log(JSON.stringify(response.body));
    }
);
package com.bluedotinnovation.zone;
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.
 * The Post Zones Sync client demonstrates how the zones/sync endpoint can be used to sync the newly created, updated or deleted Zones to
 * all mobile devices using your application.
 */
public class PostZonesSync extends BDCommon {
     
    public static void main(String[] args) throws ParseException, IOException, KeyManagementException, NoSuchAlgorithmException {
         
        String bdCustomerApiKey    = "86577370-7b91-11e4-bcb7-a0481cdc3311"; //This key is generated by Bluedot Point Access UI when your account is created.
        String bdApplicationApiKey = "9beebb18-ec2e-4f30-8e1c-2286c77007d4"; //This apiKey is generated when you create an application
        String bdRestUrl          = "https://api.bluedotinnovation.com/1/zones/sync";
         
        String zonesSyncJson = "{" +
                "\"security\": {" +
                    "\"apiKey\":" + "\"" + bdApplicationApiKey + "\"," +
                    "\"customerApiKey\":" + "\"" + bdCustomerApiKey + "\"" +
                "}" +
            "}";
         
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
         
        JSONParser parser    = new JSONParser();
        JSONObject bdZoneSyncJSONObject = (JSONObject) parser.parse(zonesSyncJson); //JSON of Zones sync request
        HttpPost postRequest = new HttpPost(bdRestUrl);
        postRequest.addHeader("content-type", "application/json");
        postRequest.setEntity(new StringEntity(bdZoneSyncJSONObject.toJSONString(), Charset.defaultCharset()));
      
        HttpResponse response = httpRestClient.execute(postRequest);
                         
        if (response.getStatusLine().getStatusCode() == 200) {
            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.IO;
using System.Web.Script.Serialization;
using System.Security.Cryptography.X509Certificates;
/**
* @author Bluedot Innovation
* Copyright (c) 2016 Bluedot Innovation. All rights reserved.
* The Post Zones Sync client demonstrates how the zones/sync endpoint can be used to sync the newly created, updated or deleted Zones to
* all mobile devices using your application.
*/
namespace BluedotPublicApiClient.zoneclient
{
    public class PostZonesSync
    {
        private void sync()
        {
            String bdCustomerApiKey      = "76e1ae30-c616-11e5-a7c0-b8ca3a6b879d"; //This key is generated by Bluedot Point Access UI when your account is created
            String bdApplicationApiKey   = "dee11930-ebff-11e5-8e27-bc305bf60831"; //This key is generated by Bluedot Access UI when you register
            String bdRestUrl             = "https://api.bluedotinnovation.com/1/zones/sync";
            String zonesSyncJson = "{" +
                "\"security\": {" +
                    "\"apiKey\":" + "\"" + bdApplicationApiKey + "\"," +
                    "\"customerApiKey\":" + "\"" + bdCustomerApiKey + "\"" +
                "}" +
            "}";
            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 jsonContent = new StringContent(zonesSyncJson);
            jsonContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage serverResponse = httpRestClient.PostAsync(new Uri(bdRestUrl), jsonContent).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 3, 2018

Start the discussion