Chilkat Online Tools

unicodeC / EDS API / Amatpersonu saraksts.

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonArrayW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW queryParams;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonArrayW jarrResp;
    int respStatusCode;
    HCkJsonObjectW json;
    const wchar_t *VardsUzvards;
    const wchar_t *PersonasKods;
    const wchar_t *AmataKods;
    const wchar_t *AmataNosaukums;
    const wchar_t *DatumsNo;
    const wchar_t *DatumsLidz;
    BOOL Ierednis;
    BOOL Aizvieto;
    int i;
    int count_i;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    queryParams = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(queryParams,L"vardsUzvards",L"Lorem qui in");
    CkJsonObjectW_UpdateString(queryParams,L"personasKods",L"est i");
    CkJsonObjectW_UpdateString(queryParams,L"amats",L"nisi cillum sed");
    CkJsonObjectW_UpdateString(queryParams,L"datumsNoIntervalsNo",L"nisi cillum sed");
    CkJsonObjectW_UpdateString(queryParams,L"datumsNoIntervalsLidz",L"nisi cillum sed");
    CkJsonObjectW_UpdateString(queryParams,L"datumsLidzIntervalsNo",L"nisi cillum sed");
    CkJsonObjectW_UpdateString(queryParams,L"datumsLidzIntervalsLidz",L"nisi cillum sed");
    CkJsonObjectW_UpdateString(queryParams,L"ierednis",L"true");
    CkJsonObjectW_UpdateString(queryParams,L"aizvieto",L"true");
    CkJsonObjectW_UpdateString(queryParams,L"aktuals",L"true");
    CkJsonObjectW_UpdateInt(queryParams,L"izlaistIerakstus",25210683);
    CkJsonObjectW_UpdateInt(queryParams,L"atgrieztIerakstus",25210683);

    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");

    resp = CkHttpW_QuickRequestParams(http,L"GET",L"https://eds.vid.gov.lv/api/officials",queryParams);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(queryParams);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jarrResp = CkJsonArrayW_Create();
    CkJsonArrayW_LoadSb(jarrResp,sbResponseBody);
    CkJsonArrayW_putEmitCompact(jarrResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonArrayW_emit(jarrResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(queryParams);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonArrayW_Dispose(jarrResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

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

    // [
    //   {
    //     "VardsUzvards": "Ut",
    //     "PersonasKods": "consectetur ut",
    //     "AmataKods": "sunt",
    //     "AmataNosaukums": "commodo officia",
    //     "DatumsNo": "2000-01-31T00:00:00",
    //     "DatumsLidz": "2000-01-31T00:00:00",
    //     "Ierednis": true,
    //     "Aizvieto": true
    //   },
    //   {
    //     "VardsUzvards": "ex elit proident aliquip",
    //     "PersonasKods": "eiusmod do tempor",
    //     "AmataKods": "sed ut qui dolore",
    //     "AmataNosaukums": "Excepteur nostrud ut proident qui",
    //     "DatumsNo": "2000-01-31T00:00:00",
    //     "DatumsLidz": "2000-01-31T00:00:00",
    //     "Ierednis": false,
    //     "Aizvieto": false
    //   }
    // ]

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    i = 0;
    count_i = CkJsonArrayW_getSize(jarrResp);
    while (i < count_i) {
        json = CkJsonArrayW_ObjectAt(jarrResp,i);
        VardsUzvards = CkJsonObjectW_stringOf(json,L"VardsUzvards");
        PersonasKods = CkJsonObjectW_stringOf(json,L"PersonasKods");
        AmataKods = CkJsonObjectW_stringOf(json,L"AmataKods");
        AmataNosaukums = CkJsonObjectW_stringOf(json,L"AmataNosaukums");
        DatumsNo = CkJsonObjectW_stringOf(json,L"DatumsNo");
        DatumsLidz = CkJsonObjectW_stringOf(json,L"DatumsLidz");
        Ierednis = CkJsonObjectW_BoolOf(json,L"Ierednis");
        Aizvieto = CkJsonObjectW_BoolOf(json,L"Aizvieto");
        CkJsonObjectW_Dispose(json);
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(queryParams);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonArrayW_Dispose(jarrResp);

    }

Curl Command

curl -G -d "vardsUzvards=Lorem%20qui%20in"
	-d "personasKods=est%20i"
	-d "amats=nisi%20cillum%20sed"
	-d "datumsNoIntervalsNo=nisi%20cillum%20sed"
	-d "datumsNoIntervalsLidz=nisi%20cillum%20sed"
	-d "datumsLidzIntervalsNo=nisi%20cillum%20sed"
	-d "datumsLidzIntervalsLidz=nisi%20cillum%20sed"
	-d "ierednis=true"
	-d "aizvieto=true"
	-d "aktuals=true"
	-d "izlaistIerakstus=25210683"
	-d "atgrieztIerakstus=25210683"
	-H "Accept: application/json"
https://eds.vid.gov.lv/api/officials

Postman Collection Item JSON

{
  "name": "Amatpersonu saraksts.",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/officials?vardsUzvards=Lorem qui in&personasKods=est i&amats=nisi cillum sed&datumsNoIntervalsNo=nisi cillum sed&datumsNoIntervalsLidz=nisi cillum sed&datumsLidzIntervalsNo=nisi cillum sed&datumsLidzIntervalsLidz=nisi cillum sed&ierednis=true&aizvieto=true&aktuals=true&izlaistIerakstus=25210683&atgrieztIerakstus=25210683",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "officials"
      ],
      "query": [
        {
          "key": "vardsUzvards",
          "value": "Lorem qui in",
          "description": "Vārds, Uzvārds."
        },
        {
          "key": "personasKods",
          "value": "est i",
          "description": "Personas kods."
        },
        {
          "key": "amats",
          "value": "nisi cillum sed",
          "description": "Amata nosaukums."
        },
        {
          "key": "datumsNoIntervalsNo",
          "value": "nisi cillum sed",
          "description": "Amatā stāšanās datuma intervāla sākums."
        },
        {
          "key": "datumsNoIntervalsLidz",
          "value": "nisi cillum sed",
          "description": "Amatā stāšanās datuma intervāla beigas."
        },
        {
          "key": "datumsLidzIntervalsNo",
          "value": "nisi cillum sed",
          "description": "Beidzis pildīt amata pienākumus datuma intervāla sākums."
        },
        {
          "key": "datumsLidzIntervalsLidz",
          "value": "nisi cillum sed",
          "description": "Beidzis pildīt amata pienākumus datuma intervāla beigas."
        },
        {
          "key": "ierednis",
          "value": "true",
          "description": "Vai persona ir valsts civildienesta ierēdnis."
        },
        {
          "key": "aizvieto",
          "value": "true",
          "description": "Vai amatpersonas pienākumus pilda uz laiku (aizvieto)."
        },
        {
          "key": "aktuals",
          "value": "true",
          "description": "Atgriezt tikai aktuālos ierakstus."
        },
        {
          "key": "izlaistIerakstus",
          "value": "25210683",
          "description": "No rezultāta izlaižamo ierakstu skaits."
        },
        {
          "key": "atgrieztIerakstus",
          "value": "25210683",
          "description": "Atgriežamo ierakstu skaits (max 100)."
        }
      ]
    }
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/officials?vardsUzvards=Lorem qui in&personasKods=est i&amats=nisi cillum sed&datumsNoIntervalsNo=nisi cillum sed&datumsNoIntervalsLidz=nisi cillum sed&datumsLidzIntervalsNo=nisi cillum sed&datumsLidzIntervalsLidz=nisi cillum sed&ierednis=true&aizvieto=true&aktuals=true&izlaistIerakstus=25210683&atgrieztIerakstus=25210683",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "officials"
          ],
          "query": [
            {
              "key": "vardsUzvards",
              "value": "Lorem qui in"
            },
            {
              "key": "personasKods",
              "value": "est i"
            },
            {
              "key": "amats",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsNoIntervalsNo",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsNoIntervalsLidz",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsLidzIntervalsNo",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsLidzIntervalsLidz",
              "value": "nisi cillum sed"
            },
            {
              "key": "ierednis",
              "value": "true"
            },
            {
              "key": "aizvieto",
              "value": "true"
            },
            {
              "key": "aktuals",
              "value": "true"
            },
            {
              "key": "izlaistIerakstus",
              "value": "25210683"
            },
            {
              "key": "atgrieztIerakstus",
              "value": "25210683"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "[\n  {\n    \"VardsUzvards\": \"Ut\",\n    \"PersonasKods\": \"consectetur ut\",\n    \"AmataKods\": \"sunt\",\n    \"AmataNosaukums\": \"commodo officia\",\n    \"DatumsNo\": \"2000-01-31T00:00:00\",\n    \"DatumsLidz\": \"2000-01-31T00:00:00\",\n    \"Ierednis\": true,\n    \"Aizvieto\": true\n  },\n  {\n    \"VardsUzvards\": \"ex elit proident aliquip\",\n    \"PersonasKods\": \"eiusmod do tempor\",\n    \"AmataKods\": \"sed ut qui dolore\",\n    \"AmataNosaukums\": \"Excepteur nostrud ut proident qui\",\n    \"DatumsNo\": \"2000-01-31T00:00:00\",\n    \"DatumsLidz\": \"2000-01-31T00:00:00\",\n    \"Ierednis\": false,\n    \"Aizvieto\": false\n  }\n]"
    },
    {
      "name": "Lietotājs nav autentificēts.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/officials?vardsUzvards=Lorem qui in&personasKods=est i&amats=nisi cillum sed&datumsNoIntervalsNo=nisi cillum sed&datumsNoIntervalsLidz=nisi cillum sed&datumsLidzIntervalsNo=nisi cillum sed&datumsLidzIntervalsLidz=nisi cillum sed&ierednis=true&aizvieto=true&aktuals=true&izlaistIerakstus=25210683&atgrieztIerakstus=25210683",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "officials"
          ],
          "query": [
            {
              "key": "vardsUzvards",
              "value": "Lorem qui in"
            },
            {
              "key": "personasKods",
              "value": "est i"
            },
            {
              "key": "amats",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsNoIntervalsNo",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsNoIntervalsLidz",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsLidzIntervalsNo",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsLidzIntervalsLidz",
              "value": "nisi cillum sed"
            },
            {
              "key": "ierednis",
              "value": "true"
            },
            {
              "key": "aizvieto",
              "value": "true"
            },
            {
              "key": "aktuals",
              "value": "true"
            },
            {
              "key": "izlaistIerakstus",
              "value": "25210683"
            },
            {
              "key": "atgrieztIerakstus",
              "value": "25210683"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Lietotājam nav tiesību veikt šo darbību.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/officials?vardsUzvards=Lorem qui in&personasKods=est i&amats=nisi cillum sed&datumsNoIntervalsNo=nisi cillum sed&datumsNoIntervalsLidz=nisi cillum sed&datumsLidzIntervalsNo=nisi cillum sed&datumsLidzIntervalsLidz=nisi cillum sed&ierednis=true&aizvieto=true&aktuals=true&izlaistIerakstus=25210683&atgrieztIerakstus=25210683",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "officials"
          ],
          "query": [
            {
              "key": "vardsUzvards",
              "value": "Lorem qui in"
            },
            {
              "key": "personasKods",
              "value": "est i"
            },
            {
              "key": "amats",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsNoIntervalsNo",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsNoIntervalsLidz",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsLidzIntervalsNo",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsLidzIntervalsLidz",
              "value": "nisi cillum sed"
            },
            {
              "key": "ierednis",
              "value": "true"
            },
            {
              "key": "aizvieto",
              "value": "true"
            },
            {
              "key": "aktuals",
              "value": "true"
            },
            {
              "key": "izlaistIerakstus",
              "value": "25210683"
            },
            {
              "key": "atgrieztIerakstus",
              "value": "25210683"
            }
          ]
        }
      },
      "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/officials?vardsUzvards=Lorem qui in&personasKods=est i&amats=nisi cillum sed&datumsNoIntervalsNo=nisi cillum sed&datumsNoIntervalsLidz=nisi cillum sed&datumsLidzIntervalsNo=nisi cillum sed&datumsLidzIntervalsLidz=nisi cillum sed&ierednis=true&aizvieto=true&aktuals=true&izlaistIerakstus=25210683&atgrieztIerakstus=25210683",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "officials"
          ],
          "query": [
            {
              "key": "vardsUzvards",
              "value": "Lorem qui in"
            },
            {
              "key": "personasKods",
              "value": "est i"
            },
            {
              "key": "amats",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsNoIntervalsNo",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsNoIntervalsLidz",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsLidzIntervalsNo",
              "value": "nisi cillum sed"
            },
            {
              "key": "datumsLidzIntervalsLidz",
              "value": "nisi cillum sed"
            },
            {
              "key": "ierednis",
              "value": "true"
            },
            {
              "key": "aizvieto",
              "value": "true"
            },
            {
              "key": "aktuals",
              "value": "true"
            },
            {
              "key": "izlaistIerakstus",
              "value": "25210683"
            },
            {
              "key": "atgrieztIerakstus",
              "value": "25210683"
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}