Chilkat Online Tools

Android / EDS API / Dokumenta pamatdati.

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://eds.vid.gov.lv/api/doc/: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)

    // {
    //   "ParbaudesRezultats": {
    //     "Kluda": [
    //       "dolor ad aliqua",
    //       "commodo enim est"
    //     ],
    //     "Bridinajums": [
    //       "aliqua adipisicing eiusmod incididunt",
    //       "Ut eiusmod laborum"
    //     ],
    //     "Informacija": [
    //       "exercitation inc",
    //       "irure amet ut"
    //     ],
    //     "Apstiprinajums": [
    //       "labore eu magna irure",
    //       "dolor laboris tempor"
    //     ]
    //   },
    //   "SanemtasAtbildes": [
    //     {
    //       "Tips": "ex dolore amet",
    //       "Datums": "2000-01-31T00:00:00",
    //       "Teksts": "commodo sint minim"
    //     },
    //     {
    //       "Tips": "in laborum",
    //       "Datums": "2000-01-31T00:00:00",
    //       "Teksts": "in fugiat"
    //     }
    //   ],
    //   "Id": -19950873,
    //   "Izveidots": "2000-01-31T00:00:00",
    //   "Iesniegts": "2000-01-31T00:00:00",
    //   "DokumentaVersija": "cillum ut magna adipisicing aliqua",
    //   "DokumentaVeids": "ex magna reprehenderit",
    //   "PeriodsNo": "2000-01-31T00:00:00",
    //   "PeriodsLidz": "2000-01-31T00:00:00",
    //   "Papildinformacija": "pariatur tempor occ",
    //   "StatussId": 94653878,
    //   "Statuss": "aliquip occaec",
    //   "IrBridinajumi": true,
    //   "VarIesniegt": true,
    //   "VarDzest": true,
    //   "IrSanemtasAtbildes": true,
    //   "Arhivets": false
    // }

    // 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 Tips;
    String Datums;
    String Teksts;

    int Id = jResp.IntOf("Id");
    String Izveidots = jResp.stringOf("Izveidots");
    String Iesniegts = jResp.stringOf("Iesniegts");
    String DokumentaVersija = jResp.stringOf("DokumentaVersija");
    String DokumentaVeids = jResp.stringOf("DokumentaVeids");
    String PeriodsNo = jResp.stringOf("PeriodsNo");
    String PeriodsLidz = jResp.stringOf("PeriodsLidz");
    String Papildinformacija = jResp.stringOf("Papildinformacija");
    int StatussId = jResp.IntOf("StatussId");
    String Statuss = jResp.stringOf("Statuss");
    boolean IrBridinajumi = jResp.BoolOf("IrBridinajumi");
    boolean VarIesniegt = jResp.BoolOf("VarIesniegt");
    boolean VarDzest = jResp.BoolOf("VarDzest");
    boolean IrSanemtasAtbildes = jResp.BoolOf("IrSanemtasAtbildes");
    boolean Arhivets = jResp.BoolOf("Arhivets");
    int i = 0;
    int count_i = jResp.SizeOfArray("ParbaudesRezultats.Kluda");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("ParbaudesRezultats.Kluda[i]");
        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("ParbaudesRezultats.Bridinajums");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("ParbaudesRezultats.Bridinajums[i]");
        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("ParbaudesRezultats.Informacija");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("ParbaudesRezultats.Informacija[i]");
        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("ParbaudesRezultats.Apstiprinajums");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("ParbaudesRezultats.Apstiprinajums[i]");
        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("SanemtasAtbildes");
    while (i < count_i) {
        jResp.put_I(i);
        Tips = jResp.stringOf("SanemtasAtbildes[i].Tips");
        Datums = jResp.stringOf("SanemtasAtbildes[i].Datums");
        Teksts = jResp.stringOf("SanemtasAtbildes[i].Teksts");
        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://eds.vid.gov.lv/api/doc/:id

Postman Collection Item JSON

{
  "name": "Dokumenta pamatdati.",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/doc/:id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "doc",
        ":id"
      ],
      "variable": [
        {
          "key": "id",
          "value": "25210683",
          "description": "(Required) Dokumenta id."
        }
      ]
    }
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/doc/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            ":id"
          ],
          "variable": [
            {
              "key": "id",
              "value": "25210683",
              "description": "(Required) Dokumenta id."
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"ParbaudesRezultats\": {\n    \"Kluda\": [\n      \"dolor ad aliqua\",\n      \"commodo enim est\"\n    ],\n    \"Bridinajums\": [\n      \"aliqua adipisicing eiusmod incididunt\",\n      \"Ut eiusmod laborum\"\n    ],\n    \"Informacija\": [\n      \"exercitation inc\",\n      \"irure amet ut\"\n    ],\n    \"Apstiprinajums\": [\n      \"labore eu magna irure\",\n      \"dolor laboris tempor\"\n    ]\n  },\n  \"SanemtasAtbildes\": [\n    {\n      \"Tips\": \"ex dolore amet\",\n      \"Datums\": \"2000-01-31T00:00:00\",\n      \"Teksts\": \"commodo sint minim\"\n    },\n    {\n      \"Tips\": \"in laborum\",\n      \"Datums\": \"2000-01-31T00:00:00\",\n      \"Teksts\": \"in fugiat\"\n    }\n  ],\n  \"Id\": -19950873,\n  \"Izveidots\": \"2000-01-31T00:00:00\",\n  \"Iesniegts\": \"2000-01-31T00:00:00\",\n  \"DokumentaVersija\": \"cillum ut magna adipisicing aliqua\",\n  \"DokumentaVeids\": \"ex magna reprehenderit\",\n  \"PeriodsNo\": \"2000-01-31T00:00:00\",\n  \"PeriodsLidz\": \"2000-01-31T00:00:00\",\n  \"Papildinformacija\": \"pariatur tempor occ\",\n  \"StatussId\": 94653878,\n  \"Statuss\": \"aliquip occaec\",\n  \"IrBridinajumi\": true,\n  \"VarIesniegt\": true,\n  \"VarDzest\": true,\n  \"IrSanemtasAtbildes\": true,\n  \"Arhivets\": false\n}"
    },
    {
      "name": "Lietotājs nav autentificēts.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/doc/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            ":id"
          ],
          "variable": [
            {
              "key": "id",
              "value": "25210683",
              "description": "(Required) Dokumenta id."
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Dokuments neeksistē vai lietotājam nav tiesību.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/doc/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            ":id"
          ],
          "variable": [
            {
              "key": "id",
              "value": "25210683",
              "description": "(Required) Dokumenta id."
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Pārsniegts izsaukumu skaita ierobežojums.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/doc/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            ":id"
          ],
          "variable": [
            {
              "key": "id",
              "value": "25210683",
              "description": "(Required) Dokumenta id."
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}