Chilkat Online Tools

Android / Squadcast API V3 / Get All Services

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;

    CkJsonObject queryParams = new CkJsonObject();
    queryParams.UpdateString("name","");

    http.SetRequestHeader("Authorization","");

    CkHttpResponse resp = http.QuickRequestParams("GET","https://api.squadcast.com/v3/services",queryParams);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    resp.GetBodySb(sbResponseBody);

    CkJsonObject jResp = new CkJsonObject();
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    Log.i(TAG, "Response Body:");
    Log.i(TAG, jResp.emit());

    int respStatusCode = resp.get_StatusCode();
    Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Header:");
        Log.i(TAG, resp.header());
        Log.i(TAG, "Failed.");

        return;
        }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "data": [
    //     {
    //       "id": "5e8edb24668e003cb0b18ba1",
    //       "name": "Payment API Service",
    //       "slug": "payment-api-service",
    //       "email": "unique_string@gopherhut.incidents.squadcast.com",
    //       "escalation_policy_id": "5d81d9407000fb6b9def7e33",
    //       "organization_id": "5d81d9187000fb6b9def7e32",
    //       "api_key": "2f81ac8b2362990dd220f8bb4f7cd30ccc3dac43",
    //       "description": "Payment API Service monitor",
    //       "depends": null,
    //       "escalation_policy": {
    //         "id": "5d81d9407000fb6b9def7e33",
    //         "name": "Example Escalation Policy",
    //         "description": "On-Boarding Example",
    //         "slug": "example-escalation-policy"
    //       }
    //     },
    //     {
    //       "id": "5e8edb24668e003cb0b18ba2",
    //       "name": "Notification Service",
    //       "slug": "notification-api-service",
    //       "email": "unique_string@gopherhut.incidents.squadcast.com",
    //       "escalation_policy_id": "5d81d9407000fb6b9def7e33",
    //       "organization_id": "5d81d9187000fb6b9def7e32",
    //       "api_key": "2f81ac8b2362990dd220f8bb4f7cd30ccc3d43",
    //       "description": "Notification API Service monitor",
    //       "depends": null,
    //       "escalation_policy": {
    //         "id": "5d81d9407000fb6b9def7e33",
    //         "name": "Example Escalation Policy",
    //         "description": "On-Boarding Example",
    //         "slug": "example-escalation-policy"
    //       }
    //     }
    //   ]
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    String id;
    String name;
    String slug;
    String email;
    String escalation_policy_id;
    String organization_id;
    String api_key;
    String description;
    String depends;
    String Id;
    String Name;
    String Description;
    String Slug;

    int i = 0;
    int count_i = jResp.SizeOfArray("data");
    while (i < count_i) {
        jResp.put_I(i);
        id = jResp.stringOf("data[i].id");
        name = jResp.stringOf("data[i].name");
        slug = jResp.stringOf("data[i].slug");
        email = jResp.stringOf("data[i].email");
        escalation_policy_id = jResp.stringOf("data[i].escalation_policy_id");
        organization_id = jResp.stringOf("data[i].organization_id");
        api_key = jResp.stringOf("data[i].api_key");
        description = jResp.stringOf("data[i].description");
        depends = jResp.stringOf("data[i].depends");
        Id = jResp.stringOf("data[i].escalation_policy.id");
        Name = jResp.stringOf("data[i].escalation_policy.name");
        Description = jResp.stringOf("data[i].escalation_policy.description");
        Slug = jResp.stringOf("data[i].escalation_policy.slug");
        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 -G -d "name="
	-H "Authorization: "
https://api.squadcast.com/v3/services

Postman Collection Item JSON

{
  "name": "Get All Services",
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": ""
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/services?name=",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "services"
      ],
      "query": [
        {
          "key": "name",
          "value": ""
        }
      ]
    },
    "description": "Returns all the active services for the organization.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `read` scope.\n\nQuery Param:\n\n`name`: get a service by name"
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"data\": [\n  {\n   \"id\": \"5e8edb24668e003cb0b18ba1\",\n   \"name\": \"Payment API Service\",\n   \"slug\": \"payment-api-service\",\n   \"email\": \"unique_string@gopherhut.incidents.squadcast.com\",\n   \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n   \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n   \"api_key\": \"2f81ac8b2362990dd220f8bb4f7cd30ccc3dac43\",\n   \"description\": \"Payment API Service monitor\",\n   \"depends\": null,\n   \"escalation_policy\": {\n    \"id\": \"5d81d9407000fb6b9def7e33\",\n    \"name\": \"Example Escalation Policy\",\n    \"description\": \"On-Boarding Example\",\n    \"slug\": \"example-escalation-policy\"\n   }\n  },\n  {\n   \"id\": \"5e8edb24668e003cb0b18ba2\",\n   \"name\": \"Notification Service\",\n   \"slug\": \"notification-api-service\",\n   \"email\": \"unique_string@gopherhut.incidents.squadcast.com\",\n   \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n   \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n   \"api_key\": \"2f81ac8b2362990dd220f8bb4f7cd30ccc3d43\",\n   \"description\": \"Notification API Service monitor\",\n   \"depends\": null,\n   \"escalation_policy\": {\n    \"id\": \"5d81d9407000fb6b9def7e33\",\n    \"name\": \"Example Escalation Policy\",\n    \"description\": \"On-Boarding Example\",\n    \"slug\": \"example-escalation-policy\"\n   }\n  }\n ]\n}"
    }
  ]
}