Back to Collection Items
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
boolean success;
http.SetRequestHeader("Accept","application/json");
CkStringBuilder sbResponseBody = new CkStringBuilder();
success = http.QuickGetSb("https://api.app.ddog-gov.com/api/v1/events/:event_id",sbResponseBody);
if (success == false) {
Log.i(TAG, http.lastErrorText());
return;
}
CkJsonObject jResp = new CkJsonObject();
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
Log.i(TAG, "Response Body:");
Log.i(TAG, jResp.emit());
int respStatusCode = http.get_LastStatus();
Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
if (respStatusCode >= 400) {
Log.i(TAG, "Response Header:");
Log.i(TAG, http.lastHeader());
Log.i(TAG, "Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "event": {
// "alert_type": "info",
// "date_happened": -7687934,
// "device_name": "labore aliquip dolor",
// "host": "incididunt sunt",
// "id": -98412440,
// "id_str": "incididunt laborum",
// "payload": "{}",
// "priority": "normal",
// "source_type_name": "commodo cupidatat ea",
// "tags": [
// "environment:test"
// ],
// "text": "Oh boy!",
// "title": "Did you hear the news today?",
// "url": "non"
// },
// "status": "sit in"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
String strVal;
String Alert_type = jResp.stringOf("event.alert_type");
int Date_happened = jResp.IntOf("event.date_happened");
String Device_name = jResp.stringOf("event.device_name");
String Host = jResp.stringOf("event.host");
int Id = jResp.IntOf("event.id");
String Id_str = jResp.stringOf("event.id_str");
String Payload = jResp.stringOf("event.payload");
String Priority = jResp.stringOf("event.priority");
String Source_type_name = jResp.stringOf("event.source_type_name");
String Text = jResp.stringOf("event.text");
String Title = jResp.stringOf("event.title");
String v_Url = jResp.stringOf("event.url");
String status = jResp.stringOf("status");
int i = 0;
int count_i = jResp.SizeOfArray("event.tags");
while (i < count_i) {
jResp.put_I(i);
strVal = jResp.stringOf("event.tags[i]");
i = i + 1;
}
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}
Curl Command
curl -X GET
-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/events/:event_id
Postman Collection Item JSON
{
"name": "Get an event",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/events/:event_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"events",
":event_id"
],
"variable": [
{
"key": "event_id",
"value": "-62147425"
}
]
},
"description": "This endpoint allows you to query for event details.\n\n**Note**: If the event you’re querying contains markdown formatting of any kind,\nyou may see characters such as `%`,`\\`,`n` in your output."
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/events/:event_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"events",
":event_id"
],
"variable": [
{
"key": "event_id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"event\": {\n \"alert_type\": \"info\",\n \"date_happened\": -7687934,\n \"device_name\": \"labore aliquip dolor\",\n \"host\": \"incididunt sunt\",\n \"id\": -98412440,\n \"id_str\": \"incididunt laborum\",\n \"payload\": \"{}\",\n \"priority\": \"normal\",\n \"source_type_name\": \"commodo cupidatat ea\",\n \"tags\": [\n \"environment:test\"\n ],\n \"text\": \"Oh boy!\",\n \"title\": \"Did you hear the news today?\",\n \"url\": \"non\"\n },\n \"status\": \"sit in\"\n}"
},
{
"name": "Authentication Error",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/events/:event_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"events",
":event_id"
],
"variable": [
{
"key": "event_id"
}
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Item Not Found",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/events/:event_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"events",
":event_id"
],
"variable": [
{
"key": "event_id"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Too many requests",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/events/:event_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"events",
":event_id"
],
"variable": [
{
"key": "event_id"
}
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
}
]
}