Chilkat Online Tools

SQL Server / EDS API / Dokumenta pamatdati.

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://eds.vid.gov.lv/api/doc/:id', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

    -- 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

    DECLARE @strVal nvarchar(4000)

    DECLARE @Tips nvarchar(4000)

    DECLARE @Datums nvarchar(4000)

    DECLARE @Teksts nvarchar(4000)

    DECLARE @Id int
    EXEC sp_OAMethod @jResp, 'IntOf', @Id OUT, 'Id'
    DECLARE @Izveidots nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Izveidots OUT, 'Izveidots'
    DECLARE @Iesniegts nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Iesniegts OUT, 'Iesniegts'
    DECLARE @DokumentaVersija nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @DokumentaVersija OUT, 'DokumentaVersija'
    DECLARE @DokumentaVeids nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @DokumentaVeids OUT, 'DokumentaVeids'
    DECLARE @PeriodsNo nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @PeriodsNo OUT, 'PeriodsNo'
    DECLARE @PeriodsLidz nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @PeriodsLidz OUT, 'PeriodsLidz'
    DECLARE @Papildinformacija nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Papildinformacija OUT, 'Papildinformacija'
    DECLARE @StatussId int
    EXEC sp_OAMethod @jResp, 'IntOf', @StatussId OUT, 'StatussId'
    DECLARE @Statuss nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Statuss OUT, 'Statuss'
    DECLARE @IrBridinajumi int
    EXEC sp_OAMethod @jResp, 'BoolOf', @IrBridinajumi OUT, 'IrBridinajumi'
    DECLARE @VarIesniegt int
    EXEC sp_OAMethod @jResp, 'BoolOf', @VarIesniegt OUT, 'VarIesniegt'
    DECLARE @VarDzest int
    EXEC sp_OAMethod @jResp, 'BoolOf', @VarDzest OUT, 'VarDzest'
    DECLARE @IrSanemtasAtbildes int
    EXEC sp_OAMethod @jResp, 'BoolOf', @IrSanemtasAtbildes OUT, 'IrSanemtasAtbildes'
    DECLARE @Arhivets int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Arhivets OUT, 'Arhivets'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'ParbaudesRezultats.Kluda'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'ParbaudesRezultats.Kluda[i]'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'ParbaudesRezultats.Bridinajums'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'ParbaudesRezultats.Bridinajums[i]'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'ParbaudesRezultats.Informacija'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'ParbaudesRezultats.Informacija[i]'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'ParbaudesRezultats.Apstiprinajums'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'ParbaudesRezultats.Apstiprinajums[i]'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'SanemtasAtbildes'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @Tips OUT, 'SanemtasAtbildes[i].Tips'
        EXEC sp_OAMethod @jResp, 'StringOf', @Datums OUT, 'SanemtasAtbildes[i].Datums'
        EXEC sp_OAMethod @jResp, 'StringOf', @Teksts OUT, 'SanemtasAtbildes[i].Teksts'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

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": ""
    }
  ]
}