C / EDS API / Dokumenta pamatdati.
Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *strVal;
const char *Tips;
const char *Datums;
const char *Teksts;
int Id;
const char *Izveidots;
const char *Iesniegts;
const char *DokumentaVersija;
const char *DokumentaVeids;
const char *PeriodsNo;
const char *PeriodsLidz;
const char *Papildinformacija;
int StatussId;
const char *Statuss;
BOOL IrBridinajumi;
BOOL VarIesniegt;
BOOL VarDzest;
BOOL IrSanemtasAtbildes;
BOOL Arhivets;
int i;
int count_i;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
CkHttp_SetRequestHeader(http,"Accept","application/json");
sbResponseBody = CkStringBuilder_Create();
success = CkHttp_QuickGetSb(http,"https://eds.vid.gov.lv/api/doc/:id",sbResponseBody);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttp_getLastStatus(http);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttp_lastHeader(http));
printf("Failed.\n");
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
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
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
Id = CkJsonObject_IntOf(jResp,"Id");
Izveidots = CkJsonObject_stringOf(jResp,"Izveidots");
Iesniegts = CkJsonObject_stringOf(jResp,"Iesniegts");
DokumentaVersija = CkJsonObject_stringOf(jResp,"DokumentaVersija");
DokumentaVeids = CkJsonObject_stringOf(jResp,"DokumentaVeids");
PeriodsNo = CkJsonObject_stringOf(jResp,"PeriodsNo");
PeriodsLidz = CkJsonObject_stringOf(jResp,"PeriodsLidz");
Papildinformacija = CkJsonObject_stringOf(jResp,"Papildinformacija");
StatussId = CkJsonObject_IntOf(jResp,"StatussId");
Statuss = CkJsonObject_stringOf(jResp,"Statuss");
IrBridinajumi = CkJsonObject_BoolOf(jResp,"IrBridinajumi");
VarIesniegt = CkJsonObject_BoolOf(jResp,"VarIesniegt");
VarDzest = CkJsonObject_BoolOf(jResp,"VarDzest");
IrSanemtasAtbildes = CkJsonObject_BoolOf(jResp,"IrSanemtasAtbildes");
Arhivets = CkJsonObject_BoolOf(jResp,"Arhivets");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"ParbaudesRezultats.Kluda");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"ParbaudesRezultats.Kluda[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"ParbaudesRezultats.Bridinajums");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"ParbaudesRezultats.Bridinajums[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"ParbaudesRezultats.Informacija");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"ParbaudesRezultats.Informacija[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"ParbaudesRezultats.Apstiprinajums");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"ParbaudesRezultats.Apstiprinajums[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"SanemtasAtbildes");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
Tips = CkJsonObject_stringOf(jResp,"SanemtasAtbildes[i].Tips");
Datums = CkJsonObject_stringOf(jResp,"SanemtasAtbildes[i].Datums");
Teksts = CkJsonObject_stringOf(jResp,"SanemtasAtbildes[i].Teksts");
i = i + 1;
}
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
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": ""
}
]
}