POST Custom Action – Client examples

Custom Action

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Create Custom Action client demonstrates adding a custom action to an existing zone
 * using the 'request' node module.
 */
var request = require('request');
var actionData =
    {
        "security": {
            /* The apiKey is generated when you create an application. */
            "apiKey" : "dcbd2c48-577e-4187-959e-b8f9216e9875",
            /* 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": {
            "zone": {
                /* The zoneId is the id of the zone being updated. This can be fetched by calling GET Zones API */
                "zoneId": "1c48dc46-b516-4396-95ca-057e730c4bd7",
                "actions": {
                    "customActions": [
                        {
                            "name": "A Custom Application action"
                        }
                    ]
                }
            }
        }
    };
var options = {
    uri: 'https://api.bluedotinnovation.com/1/actions',
    method: 'POST',
    json: actionData
};
request(options,
    function (error, response, body) {
        if (error) {
            console.log(error);
        }
        console.log(JSON.stringify(response.body));
    }
);

Custom Action with Conditions

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Create Custom Action with Conditions client demonstrates adding a custom action with conditions to an existing zone
 * using the 'request' node module.
 */
var request = require('request');
var actionData =
    {
        "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"
        },
        "content": {
            "zone": {
                /* The zoneId is the id of the zone being updated. This can be fetched by calling GET Zones API */
                "zoneId": "722c991a-3ebb-4143-b441-5b0c0cf680a0",
                "actions": {
                    "customActions": [
                        {
                            "name": "My Custom Application action",
                            "conditions": {
                                "percentageCrossed": [
                                    {
                                        "percentage": 45,
                                        /* Time in Hour:Minute format.*/
                                        "timeoutPeriod": "00:01",
                                        /*When sequential is set true, the action will be triggered based on the
                                         * sequence in which of geofences, geolines or beacons are passed.*/
                                        "sequential": true
                                    }
                                ],
                                "dateRange": [
                                    {
                                        "start": "12/12/2014",
                                        "end": "14/12/2014"
                                    }
                                ],
                                "timeActive": [
                                    {
                                        "from": {
                                            /* Time in Hour:Minute format.*/
                                            "time": "10:00",
                                            "period": "am"
                                        },
                                        "to": {
                                            /* Time in Hour:Minute format.*/
                                            "time": "2:00",
                                            "period": "pm"
                                        }
                                    }
                                ],
                                "bearing": [
                                    {
                                        "fromAngle": 80,
                                        "toAngle": 200
                                    }
                                ],
                                "speed": [
                                    {
                                        "minimumSpeed": 10,
                                        "maximumSpeed": 30
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    };
 
var options = {
    uri: 'https://api.bluedotinnovation.com/1/actions',
    method: 'POST',
    json: actionData
};
request(options,
    function (error, response, body) {
        if (error) {
            console.log(error);
        }
        console.log(JSON.stringify(response.body));
    }
);

Custom Action with Custom Data Fields

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Create Custom Action client demonstrates adding a custom action with custom data fields to
 * an existing zone using the 'request' node module.
 * Custom data fields can be used to receive custom metadata when a custom action is triggered.
 */
var request = require('request');
var actionData =
    {
        "security": {
            /* The apiKey is generated when you create an application. */
            "apiKey" : "dcbd2c48-577e-4187-959e-b8f9216e9875",
            /* 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": {
            "zone": {
                /* The zoneId is the id of the zone being updated. This can be fetched by calling GET Zones API */
                "zoneId": "1c48dc46-b516-4396-95ca-057e730c4bd7",
                "actions": {
                    "customActions": [
                        {
                            "name": "A Custom Application action",
                            /*A maximum of 5 custom fields can be added per custom action*/
                            "customFields":[
                                {
                                    "key":"type",
                                    "value":"Coffee Shop"
                                },
                                {
                                    "key":"name",
                                    "value":"Blue Bottle Coffee"
                                },
                                {
                                    "key":"id",
                                    "value":"48707775-4991-434b-ba3a-f41ac1236c44"
                                }
                            ]
                        }
                    ]
                }
            }
        }
    };
var options = {
    uri: 'https://api.bluedotinnovation.com/1/actions',
    method: 'POST',
    json: actionData
};
request(options,
    function (error, response, body) {
        if (error) {
            console.log(error);
        }
        console.log(JSON.stringify(response.body));
    }
);

Custom Action

package com.bluedotinnovation.action;
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 Pty Ltd. All rights reserved.
 * Add Custom Action client demonstrates adding a custom action to an existing zone using JSON simple and Apache HTTP client libraries.
 */
public class AddCustomAction extends BDCommon {
     
    private static String bdCustomerApiKey    = "bc199c80-5441-11e4-b7bb-a0481cdc3311"; //This key is generated by Bluedot Point Access UI when your account is created
    private static String bdApplicationApiKey = "d3161e80-38d1-11e4-b039-bc305bf60831"; //This apiKey is generated when you create an application
    private static String bdZoneId            = "24d9a245-2087-421b-9972-2af2ee0970f1"; //This is the id of the zone being updated. This can be fetched by calling GET Zones API
    private static String bdRestUrl           = "https://api.bluedotinnovation.com/1/actions";
     
    /**
     * @param args
     * @throws IOException
     * @throws ParseException
     * @throws NoSuchAlgorithmException
     * @throws KeyManagementException
     */
    public static void main(String[] args) throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException {
         
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
         
        JSONParser parser    = new JSONParser();
        JSONObject bdCustomActionJSONObject = (JSONObject) parser.parse(getJsonCustomAction()); //Custom application action json
         
        HttpPost postRequest = new HttpPost(bdRestUrl);                            
        postRequest.addHeader("content-type", "application/json");
        postRequest.setEntity(new StringEntity(bdCustomActionJSONObject.toJSONString(), Charset.defaultCharset()));
      
        HttpResponse response = httpRestClient.execute(postRequest);
                         
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println("Custom application action was added to your zone 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);
        }          
    }
     
    /**
     * Example of Custom Action.
     * @return json String
     */
    private static String getJsonCustomAction() {
        String customActionJson =
             "{" +
                "\"security\": {" +
                    "\"apiKey\":" + "\"" + bdApplicationApiKey +"\"," +
                    "\"customerApiKey\":" +"\"" + bdCustomerApiKey + "\""+
                "}," +
                "\"content\": {" +
                    "\"zone\": {" +
                        "\"zoneId\":"+ "\"" + bdZoneId +"\"," +
                        "\"actions\": {" +
                            "\"customActions\": [" +
                                "{" +
                                    "\"name\": \"A Custom Application action\"" +
                                "}" +
                            "]" +
                        "}" +
                    "}" +
                "}" +
            "}";     
        return customActionJson;
    }
     
}

Custom Action with Conditions

package com.bluedotinnovation.action;
 
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 Pty Ltd. All rights reserved.
 * Add Custom Action client demonstrates adding a custom action to an existing zone using JSON simple and Apache HTTP client libraries.
 */
 
public class AddCustomActionWithConditions extends BDCommon {
     
    private static String bdCustomerApiKey    = "bc199c80-5441-11e4-b7bb-a0481cdc3311"; //This key is generated by Bluedot Point Access UI when your account is created.
    private static String bdApplicationApiKey = "d3161e80-38d1-11e4-b039-bc305bf60831"; //This apiKey is generated when you create an application
    private static String bdZoneId            = "24d9a245-2087-421b-9972-2af2ee0970f1"; //This is the id of the zone being updated. This can be fetched by calling GET Zones API
    private static String bdRestUrl           = "https://api.bluedotinnovation.com/1/actions";
     
    /**
     * @param args
     * @throws IOException
     * @throws ParseException
     * @throws NoSuchAlgorithmException
     * @throws KeyManagementException
     */
    public static void main(String[] args) throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException {
         
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
         
        JSONParser parser    = new JSONParser();
        JSONObject bdCustomActionJSONObject = (JSONObject) parser.parse(getJsonCustomActionWithCondition()); //Custom application action with conditions json
         
        HttpPost postRequest = new HttpPost(bdRestUrl);                            
        postRequest.addHeader("content-type", "application/json");
        postRequest.setEntity(new StringEntity(bdCustomActionJSONObject.toJSONString(), Charset.defaultCharset()));
      
        HttpResponse response = httpRestClient.execute(postRequest);
                         
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println("Custom application action was added to your zone 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);
        }          
    }
     
    /**
     * Example of Custom Action.
     * @return json String
     */
    private static String getJsonCustomActionWithCondition() {
        String customActionJson =
             "{" +
                "\"security\": {" +
                    "\"apiKey\":" + "\"" + bdApplicationApiKey +"\"," +
                    "\"customerApiKey\":" +"\"" + bdCustomerApiKey + "\""+
                "}," +
                "\"content\": {" +
                    "\"zone\": {" +
                        "\"zoneId\":"+ "\"" + bdZoneId +"\"," +
                        "\"actions\": {" +
                            "\"customActions\": [" +
                                "{" +
                                    "\"name\": \"A Custom Application action\"," +
                                    "\"conditions\": {" +
                                       "\"dateRange\": [" +
                                           "{" +
                                               "\"start\": \"10/11/2016\"," +
                                               "\"end\": \"26/12/2017\"" +
                                           "}" +
                                       "]," +
                                       "\"percentageCrossed\": [" +
                                          "{" +
                                              "\"percentage\": 90," +
                                              "\"timeoutPeriod\": \"00:15\"," +
                                              "\"sequential\": true" +
                                           "}" +
                                      "]," +
                                      "\"timeActive\": [{" +
                                        "\"from\": {" +
                                            "\"time\": \"06:01\"," +
                                            "\"period\": \"am\" " +
                                        "}," +
                                        "\"to\": {" +
                                            "\"time\": \"11:00\"," +
                                            "\"period\": \"pm\" " +
                                        "}" +
                                    "}]," +
                                    "\"bearing\": [" +
                                        "{" +
                                            "\"fromAngle\": 0," +
                                            "\"toAngle\": 90" +
                                        "}" +
                                    "]," +
                                    "\"speed\": [" +
                                        "{" +
                                            "\"minmumSpeed\": 10," +
                                            "\"maximumSpeed\": 20" +
                                        "}" +
                                    "]" +
                                   "}" +
                                "}" +
                            "]" +
                        "}" +
                    "}" +
                "}" +
            "}";     
        return customActionJson;
    }
     
}

Custom Action with Custom Data Fields

package com.bluedotinnovation.action;
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 Pty Ltd. All rights reserved.
 * Add Custom Action client demonstrates adding a custom action with custom data fields to an existing
 * zone using JSON simple and Apache HTTP client libraries.
 * Custom data fields can be used to receive custom metadata when a custom action is triggered.
 */
public class AddCustomActionWithCustomData extends BDCommon {
     
    private static String bdCustomerApiKey    = "bc199c80-5441-11e4-b7bb-a0481cdc3311"; //This key is generated by Bluedot Access UI when you register
    private static String bdApplicationApiKey = "d3161e80-38d1-11e4-b039-bc305bf60831"; //This apiKey is generated when you create an application
    private static String bdZoneId            = "24d9a245-2087-421b-9972-2af2ee0970f1"; //This is the id of the zone being updated. This can be fetched by calling GET Zones API
    private static String bdRestUrl           = "https://api.bluedotinnovation.com/1/actions";
     
    /**
     * @param args
     * @throws IOException
     * @throws ParseException
     * @throws NoSuchAlgorithmException
     * @throws KeyManagementException
     */
    public static void main(String[] args) throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException {
         
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
         
        JSONParser parser    = new JSONParser();
        JSONObject bdCustomActionJSONObject = (JSONObject) parser.parse(getJsonCustomAction()); //Custom application action json
         
        HttpPost postRequest = new HttpPost(bdRestUrl);                            
        postRequest.addHeader("content-type", "application/json");
        postRequest.setEntity(new StringEntity(bdCustomActionJSONObject.toJSONString(), Charset.defaultCharset()));
      
        HttpResponse response = httpRestClient.execute(postRequest);
                         
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println("Custom application action was added to your zone 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);
        }          
    }
     
    /**
     * Example of Custom Action.
     * @return json String
     */
    private static String getJsonCustomAction() {
        String customActionJson =
             "{" +
                "\"security\": {" +
                    "\"apiKey\":" + "\"" + bdApplicationApiKey +"\"," +
                    "\"customerApiKey\":" +"\"" + bdCustomerApiKey + "\""+
                "}," +
                "\"content\": {" +
                    "\"zone\": {" +
                        "\"zoneId\":"+ "\"" + bdZoneId +"\"," +
                        "\"actions\": {" +
                            "\"customActions\": [" +
                                "{" +
                                    "\"name\": \"A Custom Application action\"," +
                                    "\"customFields\":[" +
                                        "{" +
                                            "\"key\": \"type\"," +
                                            "\"value\": \"Coffee Shop\"" +
                                        "}," +
                                        "{" +
                                            "\"key\": \"name\"," +
                                            "\"value\": \"Blue Bottle Coffee\"" +
                                        "}," +
                                        "{" +
                                            "\"key \": \"id\"," +
                                            "\"value\": \"48707775-4991-434b-ba3a-f41ac1236c44\" " +
                                        "}" +
                                    "]" +
                                "}" +
                            "]" +
                        "}" +
                    "}" +
                "}" +
            "}";     
        return customActionJson;
    }
     
}

Custom Action

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.Security.Cryptography.X509Certificates;
/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Create Custom Action client demonstrates adding a custom action to an existing the customer's zone using .net http web api library
 */
namespace BluedotPublicApiClient.actionclient
{
    public class CreateCustomAction
    {
        private static String bdCustomerApiKey    = "bc199c80-5441-11e4-b7bb-a0481cdc3311"; //This key is generated by Bluedot Point Access UI when your account is created
        private static String bdApplicationApiKey = "d3161e80-38d1-11e4-b039-bc305bf60831"; //This apiKey is generated when you create an application
        private static String bdZoneId            = "24d9a245-2087-421b-9972-2af2ee0970f1"; //This is the id of the zone being updated. This can be fetched by calling GET Zones API
        private static String bdRestUrl           = "https://api.bluedotinnovation.com/1/actions";
        public void add()
        {
            postToService(getJsonCustomAction());
        }
        private void postToService(String json)
        {
            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(json);
            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);
            }
        }
        /*JSON Format for an application action*/
        private static String getJsonCustomAction()
        {
            String customActionJson =
                 "{" +
                    "\"security\": {" +
                        "\"apiKey\":" + "\"" + bdApplicationApiKey + "\"," +
                        "\"customerApiKey\":" + "\"" + bdCustomerApiKey + "\"" +
                    "}," +
                    "\"content\": {" +
                        "\"zone\": {" +
                            "\"zoneId\":" + "\"" + bdZoneId + "\"," +
                            "\"actions\": {" +
                                "\"customActions\": [" +
                                    "{" +
                                        "\"name\": \"A Custom Application action\"" +
                                    "}" +
                                "]" +
                            "}" +
                        "}" +
                    "}" +
                "}";
            return customActionJson;
        }
    }
}

Custom Action with conditions

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.Security.Cryptography.X509Certificates;
/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Create custom Action client demonstrates adding a Custom action with conditions to an existing the customer's zone using .net http web api library
 */
namespace BluedotPublicApiClient.actionclient
{
    public class CreateCustomActionWithConditions
    {
        private static String bdCustomerApiKey    = "a6598740-75f5-11e4-86ca-a0481cdc3311"; //This key is generated by Bluedot Access UI when you register
        private static String bdApplicationApiKey = "db15b9b5-f2cf-405d-920d-0a65ea227c0c"; //This apiKey is generated when you create an application
        private static String bdZoneId            = "7022428f-c852-487d-a9bc-7029adbf7245"; //This is the id of the zone being updated. This can be fetched by calling GET Zones API
        private static String bdRestUrl           = "https://api.bluedotinnovation.com/1/actions";
        public void createActionWithConditions()
        {
            postToService(getJsonCustomActionWithConditions());
        }
        private void postToService(String json)
        {
            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(json);
            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);
            }
        }
        private static String getJsonCustomActionWithConditions()
        {
            String action =
            "{" +
                "\"security\": {" +
                     "\"apiKey\":" + "\"" + bdApplicationApiKey + "\"," +
                      "\"customerApiKey\":" + "\"" + bdCustomerApiKey + "\"" +
                "}," +
                "\"content\": {" +
                    "\"zone\": {" +
                        "\"zoneId\":" + "\"" + bdZoneId + "\"," +
                        "\"actions\": {" +
                            "\"customActions\": [" +
                                "{" +
                                    "\"name\" : \"A custom action providing a callback to the application\"," +
                                    "\"conditions\": {" +
                                        "\"percentageCrossed\":" +
                                        "[" +
                                            "{" +
                                                "\"percentage\": 100," +
                                                "\"timeoutPeriod\": \"00:05\"" +
                                            "}" +
                                        "]" +                         
                                    "}" +
                                "}" +
                            "]" +
                        "}" +
                    "}" +
                "}" +
            "}";
            return action;
        }
    }
}

Custom Action with Custom Data Fields

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.Security.Cryptography.X509Certificates;
/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Create Custom Action client demonstrates adding a custom action with custom data fields to an existing the customer's zone using .net http web api library
 * Custom data fields can be used to receive custom metadata when a custom action is triggered.
 */
namespace BluedotPublicApiClient.actionclient
{
    public class CreateCustomActionWithCustomData
    {
        private static String bdCustomerApiKey    = "bc199c80-5441-11e4-b7bb-a0481cdc3311"; //This key is generated by Bluedot Access UI when you register
        private static String bdApplicationApiKey = "d3161e80-38d1-11e4-b039-bc305bf60831"; //This apiKey is generated when you create an application
        private static String bdZoneId            = "24d9a245-2087-421b-9972-2af2ee0970f1"; //This is the id of the zone being updated. This can be fetched by calling GET Zones API
        private static String bdRestUrl           = "https://api.bluedotinnovation.com/1/actions";
        public void add()
        {
            postToService(getJsonCustomActionWithCustomData());
        }
        private void postToService(String json)
        {
            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(json);
            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);
            }
        }
        /*JSON Format for an application action*/
        private static String getJsonCustomActionWithCustomData()
        {
            String customActionJson =
                 "{" +
                    "\"security\": {" +
                        "\"apiKey\":" + "\"" + bdApplicationApiKey + "\"," +
                        "\"customerApiKey\":" + "\"" + bdCustomerApiKey + "\"" +
                    "}," +
                    "\"content\": {" +
                        "\"zone\": {" +
                            "\"zoneId\":" + "\"" + bdZoneId + "\"," +
                            "\"actions\": {" +
                                "\"customActions\": [" +
                                    "{" +
                                        "\"name\": \"A Custom Application action\"," +
                                        "\"customFields\":[" +
                                            "{" +
                                                "\"key\": \"type\"," +
                                                "\"value\": \"Coffee Shop\"" +
                                            "}," +
                                            "{" +
                                                "\"key\": \"name\"," +
                                                "\"value\": \"Blue Bottle Coffee\"" +
                                            "}," +
                                            "{" +
                                                "\"key \": \"id\"," +
                                                "\"value\": \"48707775-4991-434b-ba3a-f41ac1236c44\" " +
                                            "}" +
                                        "]" +
                                    "}" +
                                "]" +
                            "}" +
                        "}" +
                    "}" +
                "}";
            return customActionJson;
        }
    }
}
Created by Bluedot DevOps on March 3, 2018

Start the discussion