Java

This tutorial provides you with a step-by-step walkthrough on how to interact with the IoT Connect 365 API

This is not a production-ready application. Please take your time to make it meet your business requirements and production standards.

Steps

Code

keyboard_arrow_down
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// _Step_1
applicationToken = apptoken
baseUrl = https://sapiotconnect365.sapdigitalinterconnect.com

setProxy = false

http.proxyHost = 10.125.30.15
http.proxyPort = 8080
https.proxyHost = 10.125.30.15
https.proxyPort = 8080
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
package com.sinch.iot;

import com.google.gson.*;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import javax.naming.AuthenticationException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.util.Map;

public class MakeIOTJson {

    private static MakeIOTJson instance = null;
    private static String ApplicationToken = null;
    private static String BaseUrl = null;
    public static String Token = null;

    protected MakeIOTJson() {

    }

    public static MakeIOTJson getInstnace() {
        if (instance == null)
            instance = new MakeIOTJson();

        return instance;
    }

    public static void setBaseUrl(String url) {
        BaseUrl = url;
    }

    public static void setAppToken(String token) {
        ApplicationToken = token;
    }

    // _Step_2
    public static void authenticate() throws AuthenticationException, IOException {
        String jsonText =
                "{\n" +
                "    \"application_token\": \"" + ApplicationToken + "\"\n" +
                "}";

        try {
            String url = BaseUrl + "/api/v1/authenticate";

            HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
            HttpPost postRequest = new HttpPost(url);

            StringEntity input = new StringEntity(jsonText);
            input.setContentType("application/json");
            postRequest.setEntity(input);

            System.out.println("Client Header:" + input.toString());
            System.out.println("Client Data:" + jsonText);
            HttpResponse response = httpClient.execute(postRequest);

            if (response.getStatusLine().getStatusCode() != 200) {
                throw new RuntimeException("Failed : HTTP error code : "
                        + response.getStatusLine().getStatusCode());
            }

            BufferedReader br = new BufferedReader(
                    new InputStreamReader((response.getEntity().getContent())));

            String output;
            StringBuffer resp = new StringBuffer();
            System.out.println("Output from Server .... \n");

            while ((output = br.readLine()) != null) {
                resp.append(output);
            }

            //print result
            System.out.println(toPrettyFormat(resp.toString()));
            //parsing the result
            JSONObject jsonObject = (JSONObject) JSONValue.parse(resp.toString());

            Token = (String) jsonObject.get("auth_token");
            System.out.println("token :" + Token);
            System.out.println("\n\n");

            if (Token == null)
                throw new AuthenticationException();

        } catch (MalformedURLException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        }

    }

    public static void GetRequest(String name, String param) throws AuthenticationException, IOException {

        try {
            String url = BaseUrl + "/api/v1/" + name + "" + param;

            HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
            HttpGet getRequest = new HttpGet(url);

            getRequest.addHeader("accept", "application/json");
            getRequest.addHeader("Authorization", "Bearer " + Token);

            System.out.println("Sending Data:" + getRequest.toString());
            HttpResponse response = httpClient.execute(getRequest);

            if (response.getStatusLine().getStatusCode() == 401)
                throw new AuthenticationException();

            BufferedReader br = new BufferedReader(
                    new InputStreamReader((response.getEntity().getContent())));

            String output;
            StringBuffer resp = new StringBuffer();
            System.out.println("Output from Server .... \n");

            while ((output = br.readLine()) != null) {
                resp.append(output);
            }
            //print result
            System.out.println(toPrettyFormat(resp.toString()));
            System.out.println("\n\n");

        } catch (MalformedURLException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        }
    }

    public static void DeleteRequest(String name, String param) throws AuthenticationException, IOException {

        try {
            String url = BaseUrl + "/api/v1/" + name + "/" + param;
            System.out.println("url :" + url);

            HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
            HttpDelete getRequest = new HttpDelete(url);

            getRequest.addHeader("Content-Type", "application/json");
            getRequest.addHeader("Authorization", "Bearer " + Token);

            System.out.println("Sending Data:" + getRequest.toString());
            HttpResponse response = httpClient.execute(getRequest);

            if (response.getStatusLine().getStatusCode() == 401)
                throw new AuthenticationException();

            System.out.println(response.getStatusLine().getStatusCode());
            System.out.println("\n\n");

        } catch (MalformedURLException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        }
    }


    public static void PatchRequest(String name, String param, Map<String, String> NVPair) throws AuthenticationException, IOException {
        StringBuffer jsonRequest = new StringBuffer();

        jsonRequest.append("{\n");
        for (Map.Entry<String, String> entry : NVPair.entrySet()) {
            jsonRequest.append("\"").append(entry.getKey()).append("\": ").append(entry.getValue()).append(",");
        }
        jsonRequest.deleteCharAt(jsonRequest.length() - 1);
        jsonRequest.append("\n}");

        System.out.println("JsonData:" + jsonRequest.toString());
        try {
            String url = BaseUrl + "/api/v1/" + name + "/" + param;
            HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
            HttpPatch patchRequest = new HttpPatch(url);

            patchRequest.addHeader("Authorization", "Bearer " + Token);
            StringEntity input = new StringEntity(jsonRequest.toString());
            input.setContentType("application/json");
            patchRequest.setEntity(input);

            System.out.println("Sending Data:" + patchRequest.toString());
            HttpResponse response = httpClient.execute(patchRequest);

            if (response.getStatusLine().getStatusCode() == 401)
                throw new AuthenticationException();

            System.out.println(response.getStatusLine().getStatusCode());
            System.out.println("\n\n");

        } catch (MalformedURLException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        }
    }

    public static void PatchRequest(String name, String param) throws AuthenticationException, IOException {
        try {
            String url = BaseUrl + "/api/v1/" + name + "/" + param;
            HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
            HttpPatch patchRequest = new HttpPatch(url);

            patchRequest.addHeader("Authorization", "Bearer " + Token);
            StringEntity input = new StringEntity("");
            input.setContentType("application/json");
            patchRequest.setEntity(input);

            System.out.println("Sending Data:" + patchRequest.toString());
            HttpResponse response = httpClient.execute(patchRequest);

            if (response.getStatusLine().getStatusCode() == 401)
                throw new AuthenticationException();

            System.out.println(response.getStatusLine().getStatusCode());
            BufferedReader br = new BufferedReader(
                    new InputStreamReader((response.getEntity().getContent())));

            String output;
            StringBuffer resp = new StringBuffer();
            System.out.println("Output from Server .... \n");

            while ((output = br.readLine()) != null) {
                resp.append(output);
            }
            //print result
            System.out.println(toPrettyFormat(resp.toString()));
            System.out.println("\n\n");

        } catch (MalformedURLException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        }
    }

    public static void PostRequest(String name, Map<String, String> NVPair) throws AuthenticationException, IOException {
        StringBuffer jsonRequest = new StringBuffer();

        jsonRequest.append("{\n");
        for (Map.Entry<String, String> entry : NVPair.entrySet()) {
            jsonRequest.append("\"").append(entry.getKey()).append("\": ").append(entry.getValue()).append(",");
        }

        jsonRequest.deleteCharAt(jsonRequest.length() - 1);
        jsonRequest.append("\n}");

        System.out.println("JsonData:" + jsonRequest.toString());

        try {
            String url = BaseUrl + "/api/v1/" + name;
            HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
            HttpPost postRequest = new HttpPost(url);

            postRequest.addHeader("Authorization", "Bearer " + Token);
            StringEntity input = new StringEntity(jsonRequest.toString());
            input.setContentType("application/json");
            postRequest.setEntity(input);

            System.out.println("Sending Data:" + postRequest.toString());
            HttpResponse response = httpClient.execute(postRequest);

            if (response.getStatusLine().getStatusCode() == 401)
                throw new AuthenticationException();

            System.out.println(response.getStatusLine().getStatusCode());

            BufferedReader br = new BufferedReader(
                    new InputStreamReader((response.getEntity().getContent())));

            String output;
            StringBuffer resp = new StringBuffer();
            System.out.println("Output from Server .... \n");

            while ((output = br.readLine()) != null) {
                resp.append(output);
            }

            //print result
            System.out.println(toPrettyFormat(resp.toString()));
            System.out.println("\n\n");

            //get all headers
            Header[] headers = response.getAllHeaders();
            for (Header header : headers) {
                System.out.println("Name : " + header.getName() + " ,Value : " + header.getValue());
            }

        } catch (MalformedURLException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        }

    }

    /**
     * Convert a JSON string to pretty print version
     *
     * @param jsonString
     * @return
     */
    public static String toPrettyFormat(String jsonString) {
        try {
            StringBuilder sb = new StringBuilder();
            if (jsonString.startsWith("[")) {
                sb.append("[");
                JsonParser parser = new JsonParser();
                JsonElement Element = parser.parse(jsonString);
                JsonArray jarray = Element.getAsJsonArray();
                for (int i = 0; i < jarray.size(); i++) {
                    JsonObject json = jarray.get(i).getAsJsonObject();
                    Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
                    String prettyJson = gson.toJson(json);
                    sb.append(prettyJson);
                    if (i != (jarray.size() - 1))
                        sb.append(",").append("\n");
                }
                sb.append("]");
                return sb.toString();

            } else {

                JsonParser parser = new JsonParser();
                JsonObject json = parser.parse(jsonString).getAsJsonObject();

                Gson gson = new GsonBuilder().setPrettyPrinting().create();
                String prettyJson = gson.toJson(json);

                return prettyJson;
            }
        } catch (Exception ex) {
            System.err.println("Error Occurred while PrettyFormat. " + jsonString);
            return jsonString;
        }
    }
}
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
package com.sinch.iot;


import javax.naming.AuthenticationException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class IOTConsole {


    public static final void main(String... aArgs) throws IOException {

        Properties prop = new Properties();
        InputStream input = null;

        try {

            String filename = "app.properties";
            input = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
            if (input == null) {
                System.out.println("Sorry, unable to find " + filename);
            }

            //load a properties file from class path, inside static method
            prop.load(input);
            if (prop.getProperty("setProxy").equalsIgnoreCase("true")) {
                // HTTP/HTTPS Proxy
                System.setProperty("http.proxyHost", prop.getProperty("http.proxyHost"));
                System.setProperty("http.proxyPort", prop.getProperty("http.proxyPort"));
                System.setProperty("https.proxyHost", prop.getProperty("https.proxyHost"));
                System.setProperty("https.proxyPort", prop.getProperty("https.proxyPort"));

                System.setProperty("java.net.useSystemProxies", "true");
                System.out.println("Use the proxy");
            }
            MakeIOTJson.setAppToken(prop.getProperty("applicationToken"));
            MakeIOTJson.setBaseUrl(prop.getProperty("baseUrl"));

        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        // _Step_3
        while (true) {
            BufferedReader standardInput
                    = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("---------Main Menu--------");
            System.out.println("1. Endpoint");
            System.out.println("2. SIM");
            System.out.println("3. Events");
            System.out.println("4. ServiceLookup");
            System.out.println("5. Exit\n");

            System.out.print("Enter your choice: ");

            String choice = standardInput.readLine();

            if (choice.trim().equals("1")) {
                EndpointOp();
            } else if (choice.trim().equals("2")) {
                SimOp();
            } else if (choice.trim().equals("3")) {
                EventOp();
            } else if (choice.trim().equals("4")) {
                LookupOp();
            } else if (choice.trim().equals("5")) {
                System.exit(0);
            }
        }
    }

    // _Step_4
    private static void EndpointOp() {

        Boolean loop = true;

        while (loop) {
            BufferedReader standardInput
                    = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("------------Endpoint---------------");
            System.out.println("1. Create Endpoint");
            System.out.println("2. Delete Endpoint By ID");
            System.out.println("3. Retrive Endpoint By ID");
            System.out.println("4. Retrive Endpoint By Name");
            System.out.println("5. Update Endpoint By ID");
            System.out.println("6. Goto Main Menu\n");

            System.out.print("Endpoint :: Enter your choice: ");


            String choice;
            try {
                choice = standardInput.readLine();

                if (choice.trim().equals("1")) {
                    Map<String, String> NVPare = new HashMap<String, String>();
                    System.out.print("Enter the name (required):");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String name = makeValue(standardInput.readLine(), false);
                    if (name != null) {
                        NVPare.put("name", name);
                    }

                    System.out.print("Enter the status (required) 0 Enable, 1 Disable:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String status = standardInput.readLine();
                    if (status != null && !status.trim().isEmpty()) {
                        status = "{ \"id\":" + status + " }";
                        NVPare.put("status", status);
                    }

                    System.out.print("Enter the service profile (required):");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String service_profile = makeValue(standardInput.readLine(), true);
                    if (service_profile != null) {
                        NVPare.put("service_profile", service_profile);
                    }

                    System.out.print("Enter the tariff profile (required):");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String tariff_profile = makeValue(standardInput.readLine(), true);
                    if (tariff_profile != null) {
                        NVPare.put("tariff_profile", tariff_profile);
                    }

                    System.out.print("Enter the SIM ID:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String sim = makeValue(standardInput.readLine(), true);
                    if (sim != null) {
                        NVPare.put("sim", sim);
                    }

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.PostRequest("endpoint", NVPare);
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }

                } else if (choice.trim().equals("2")) {
                    System.out.print("Enter the EndpointID:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    choice = standardInput.readLine();

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.DeleteRequest("endpoint", choice);
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("3")) {
                    System.out.print("Enter the EndpointID:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    choice = standardInput.readLine();

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("endpoint/", choice);
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("4")) {
                    System.out.print("Enter the Endpoint Name:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String name = standardInput.readLine();

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("endpoint?", "q=name:" + URLEncoder.encode(name, "UTF-8"));
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("5")) {
                    System.out.print("Enter the Endpoint ID:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String endpointID = standardInput.readLine();

                    Map<String, String> NVPare = new HashMap<String, String>();
                    System.out.print("Enter the name:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String name = makeValue(standardInput.readLine(), false);
                    if (name != null) {
                        NVPare.put("name", name);
                    }

                    System.out.print("Enter the status (0: Enable, 1: Disalbe):");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String status = standardInput.readLine();
                    if (status != null && !status.trim().isEmpty()) {
                        status = "{ \"id\":" + status + " }";
                        NVPare.put("status", status);
                    }
                    System.out.print("Enter the sevice profile:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String service_profile = makeValue(standardInput.readLine(), true);
                    if (service_profile != null) {
                        NVPare.put("service_profile", service_profile);
                    }
                    System.out.print("Enter the tariff profile:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String tariff_profile = makeValue(standardInput.readLine(), true);
                    if (tariff_profile != null) {
                        NVPare.put("tariff_profile", tariff_profile);
                    }

                    System.out.print("Enter the SIM ID:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String sim = makeValue(standardInput.readLine(), true);
                    if (sim != null) {
                        NVPare.put("sim", sim);
                    }

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.PatchRequest("endpoint", endpointID, NVPare);
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("6")) {
                    loop = false;

                }

            } catch (IOException e) {

                e.printStackTrace();
            }
        }
    }


    private static void SimOp() {

        Boolean loop = true;

        while (loop) {
            BufferedReader standardInput
                    = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("------------SIM---------------");
            System.out.println("1. Retrive SIM By ICCID");
            System.out.println("2. Retrive SIM By ID");
            System.out.println("3. Activate SIM By ID");
            System.out.println("4. Suspend SIM By ID");
            System.out.println("5. Register SIM");
            System.out.println("6. Goto Main Menu\n");
            System.out.print("SIM :: Enter your choice: ");

            String choice;
            try {
                choice = standardInput.readLine();

                if (choice.trim().equals("1")) {
                    System.out.print("Enter the iccid#:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String iccid = standardInput.readLine();

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("sim?", "q=iccid:" + iccid);
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }

                } else if (choice.trim().equals("2")) {
                    System.out.print("Enter the SIM ID:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    choice = standardInput.readLine();

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("sim/", choice);
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("3")) {
                    System.out.print("Enter the SIM ID:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    choice = standardInput.readLine();

                    Map<String, String> NVPair = new HashMap<String, String>();
                    String retrunValue = "{ \"id\": 1 }";
                    NVPair.put("status", retrunValue);
                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.PatchRequest("sim", choice, NVPair);
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("4")) {
                    System.out.print("Enter the SIM ID:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    choice = standardInput.readLine();

                    Map<String, String> NVPair = new HashMap<String, String>();
                    String retrunValue = "{ \"id\": 2 }";
                    NVPair.put("status", retrunValue);
                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.PatchRequest("sim", choice, NVPair);
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("5")) {
                    System.out.print("Enter the BIC Code without hyphen:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    choice = standardInput.readLine();

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.PatchRequest("sim_batch/bic/", choice);
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("6")) {
                    loop = false;
                }

            } catch (IOException e) {

                e.printStackTrace();
            }
        }

    }


    private static void EventOp() {
        Boolean loop = true;
        while (loop) {
            BufferedReader standardInput
                    = new BufferedReader(new InputStreamReader(System.in));

            System.out.println("----------------Event--------------------");
            System.out.println("1. Retrive Events By Endpoint");
            System.out.println("2. Retrive Events By ICCID");
            System.out.println("3. Retrive EventTypes");
            System.out.println("4. Retrive Events By Type");
            System.out.println("5. Retrive Event By Event ID");
            System.out.println("6. Goto Main Menu\n");

            System.out.print("Event :: Enter your choice: ");


            String choice;
            try {
                choice = standardInput.readLine();

                if (choice.trim().equals("1")) {
                    System.out.print("Enter the Endpoint Name:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String name = standardInput.readLine();
                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("event?", "q=endpoint:" + URLEncoder.encode(name, "UTF-8"));

                    } catch (AuthenticationException e) {
                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("2")) {
                    System.out.print("Enter the ICCID:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String iccid = standardInput.readLine();

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("event?", "q=iccid:" + iccid);
                    } catch (AuthenticationException e) {
                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("3")) {

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("event/", "type");
                    } catch (AuthenticationException e) {
                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("4")) {
                    System.out.print("Enter the EventType (0 - 10):");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String type = standardInput.readLine();

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("event?", "q=type:" + type);
                    } catch (AuthenticationException e) {
                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("5")) {
                    System.out.print("Enter the EventID:");
                    standardInput = new BufferedReader(new InputStreamReader(System.in));
                    String id = standardInput.readLine();

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("event?", "q=id:" + id);
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }

                } else if (choice.trim().equals("6")) {
                    loop = false;
                }
            } catch (IOException e) {

                e.printStackTrace();
            }
        }

    }

    private static void LookupOp() {

        boolean loop = true;
        while (loop) {
            BufferedReader standardInput
                    = new BufferedReader(new InputStreamReader(System.in));

            System.out.println("---------------Lookup-----------------");

            System.out.println("1. Lookup Available Countries");
            System.out.println("2. Lookup Available Currencies");
            System.out.println("3. Lookup Available Data Blocksizes");
            System.out.println("4. Lookup Available Data Throttles");
            System.out.println("5. Lookup Available Operators");
            System.out.println("6. Goto Main Menu\n");

            System.out.print("Lookup :: Enter your choice: ");


            String choice;
            try {
                choice = standardInput.readLine();

                if (choice.trim().equals("1")) {

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("country", "");

                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("2")) {
                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("currency", "");

                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("3")) {

                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("data_blocksize", "");
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("4")) {
                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("data_throttle", "");
                    } catch (AuthenticationException e) {

                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("5")) {
                    try {
                        if (MakeIOTJson.Token == null)
                            MakeIOTJson.authenticate();

                        MakeIOTJson.GetRequest("operator", "");
                    } catch (AuthenticationException e) {
                        e.printStackTrace();
                    }
                } else if (choice.trim().equals("6")) {
                    loop = false;
                }

            } catch (IOException e) {

                e.printStackTrace();
            }
        }

    }

    private static String makeValue(String value, Boolean isInt) {

        String retrunValue = null;
        if (value != null && !value.trim().isEmpty()) {

            if (isInt)
                retrunValue = "{ \"id\":" + value + " }";
            else
                retrunValue = "\"" + value + "\"";
        }
        return retrunValue;

    }
}