Chilkat Online Tools

SQL Server / EDS API / Dokuments "Mikrouzņēmumu nodokļa deklarācija".

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
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.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
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://eds.vid.gov.lv/api/doc/mnv4/: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
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.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)

    -- {
    --   "Epasts": "enim amet non ",
    --   "Talrunis": "id c",
    --   "Gads": 64835712,
    --   "Ceturksnis": 1,
    --   "Sagatavotajs": "nisi",
    --   "InformacijaPielasita": "2000-01-31T00:00:00",
    --   "JurForma": 88603509,
    --   "IenakumiVaiApgrozijums": "sint cillum",
    --   "R1_1": 31349873.20691654,
    --   "R1_2": -37608797.88134388,
    --   "R1_3": 82418688.5669148,
    --   "R1": 2542464.1702338904,
    --   "R2_1": 46996023.13942307,
    --   "R2_2": -17110660.40645033,
    --   "R2_3": -5204022.378950328,
    --   "R2_4": -18264132.106288895,
    --   "R2": -90810971.90093508,
    --   "R3": [
    --     {
    --       "Kods": "anim ut",
    --       "VardsUzvards": "Duis aute id eu",
    --       "IrIpasnieks": false,
    --       "IenakMen1": 38815983.25991592,
    --       "IenakMen2": -84487767.18798548,
    --       "IenakMen3": 16457643.991805598
    --     },
    --     {
    --       "Kods": "adipisicing ipsum",
    --       "VardsUzvards": "nostrud voluptate enim",
    --       "IrIpasnieks": true,
    --       "IenakMen1": -18313320.85834609,
    --       "IenakMen2": -89228798.3221939,
    --       "IenakMen3": -86944379.0592796
    --     }
    --   ],
    --   "Id": -51804961,
    --   "UID": "culpa esse nostrud",
    --   "NmrKods": "officia s",
    --   "Precizejums": true,
    --   "PrecizejamaisDokuments": 23637004,
    --   "PrecizejumaPamatojums": "Lorem ad ut magna"
    -- }

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

    DECLARE @Kods nvarchar(4000)

    DECLARE @VardsUzvards nvarchar(4000)

    DECLARE @IrIpasnieks int

    DECLARE @IenakMen1 nvarchar(4000)

    DECLARE @IenakMen2 nvarchar(4000)

    DECLARE @IenakMen3 nvarchar(4000)

    DECLARE @Epasts nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Epasts OUT, 'Epasts'
    DECLARE @Talrunis nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Talrunis OUT, 'Talrunis'
    DECLARE @Gads int
    EXEC sp_OAMethod @jResp, 'IntOf', @Gads OUT, 'Gads'
    DECLARE @Ceturksnis int
    EXEC sp_OAMethod @jResp, 'IntOf', @Ceturksnis OUT, 'Ceturksnis'
    DECLARE @Sagatavotajs nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Sagatavotajs OUT, 'Sagatavotajs'
    DECLARE @InformacijaPielasita nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @InformacijaPielasita OUT, 'InformacijaPielasita'
    DECLARE @JurForma int
    EXEC sp_OAMethod @jResp, 'IntOf', @JurForma OUT, 'JurForma'
    DECLARE @IenakumiVaiApgrozijums nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @IenakumiVaiApgrozijums OUT, 'IenakumiVaiApgrozijums'
    DECLARE @R1_1 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @R1_1 OUT, 'R1_1'
    DECLARE @R1_2 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @R1_2 OUT, 'R1_2'
    DECLARE @R1_3 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @R1_3 OUT, 'R1_3'
    DECLARE @R1 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @R1 OUT, 'R1'
    DECLARE @R2_1 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @R2_1 OUT, 'R2_1'
    DECLARE @R2_2 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @R2_2 OUT, 'R2_2'
    DECLARE @R2_3 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @R2_3 OUT, 'R2_3'
    DECLARE @R2_4 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @R2_4 OUT, 'R2_4'
    DECLARE @R2 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @R2 OUT, 'R2'
    DECLARE @Id int
    EXEC sp_OAMethod @jResp, 'IntOf', @Id OUT, 'Id'
    DECLARE @UID nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @UID OUT, 'UID'
    DECLARE @NmrKods nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @NmrKods OUT, 'NmrKods'
    DECLARE @Precizejums int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Precizejums OUT, 'Precizejums'
    DECLARE @PrecizejamaisDokuments int
    EXEC sp_OAMethod @jResp, 'IntOf', @PrecizejamaisDokuments OUT, 'PrecizejamaisDokuments'
    DECLARE @PrecizejumaPamatojums nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @PrecizejumaPamatojums OUT, 'PrecizejumaPamatojums'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'R3'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @Kods OUT, 'R3[i].Kods'
        EXEC sp_OAMethod @jResp, 'StringOf', @VardsUzvards OUT, 'R3[i].VardsUzvards'
        EXEC sp_OAMethod @jResp, 'BoolOf', @IrIpasnieks OUT, 'R3[i].IrIpasnieks'
        EXEC sp_OAMethod @jResp, 'StringOf', @IenakMen1 OUT, 'R3[i].IenakMen1'
        EXEC sp_OAMethod @jResp, 'StringOf', @IenakMen2 OUT, 'R3[i].IenakMen2'
        EXEC sp_OAMethod @jResp, 'StringOf', @IenakMen3 OUT, 'R3[i].IenakMen3'
        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/mnv4/:id

Postman Collection Item JSON

{
  "name": "Dokuments \"Mikrouzņēmumu nodokļa deklarācija\".",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/doc/mnv4/:id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "doc",
        "mnv4",
        ":id"
      ],
      "variable": [
        {
          "key": "id",
          "value": "25210683",
          "description": "(Required) Dokumenta id."
        }
      ]
    }
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/doc/mnv4/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            "mnv4",
            ":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  \"Epasts\": \"enim amet non \",\n  \"Talrunis\": \"id c\",\n  \"Gads\": 64835712,\n  \"Ceturksnis\": 1,\n  \"Sagatavotajs\": \"nisi\",\n  \"InformacijaPielasita\": \"2000-01-31T00:00:00\",\n  \"JurForma\": 88603509,\n  \"IenakumiVaiApgrozijums\": \"sint cillum\",\n  \"R1_1\": 31349873.20691654,\n  \"R1_2\": -37608797.88134388,\n  \"R1_3\": 82418688.5669148,\n  \"R1\": 2542464.1702338904,\n  \"R2_1\": 46996023.13942307,\n  \"R2_2\": -17110660.40645033,\n  \"R2_3\": -5204022.378950328,\n  \"R2_4\": -18264132.106288895,\n  \"R2\": -90810971.90093508,\n  \"R3\": [\n    {\n      \"Kods\": \"anim ut\",\n      \"VardsUzvards\": \"Duis aute id eu\",\n      \"IrIpasnieks\": false,\n      \"IenakMen1\": 38815983.25991592,\n      \"IenakMen2\": -84487767.18798548,\n      \"IenakMen3\": 16457643.991805598\n    },\n    {\n      \"Kods\": \"adipisicing ipsum\",\n      \"VardsUzvards\": \"nostrud voluptate enim\",\n      \"IrIpasnieks\": true,\n      \"IenakMen1\": -18313320.85834609,\n      \"IenakMen2\": -89228798.3221939,\n      \"IenakMen3\": -86944379.0592796\n    }\n  ],\n  \"Id\": -51804961,\n  \"UID\": \"culpa esse nostrud\",\n  \"NmrKods\": \"officia s\",\n  \"Precizejums\": true,\n  \"PrecizejamaisDokuments\": 23637004,\n  \"PrecizejumaPamatojums\": \"Lorem ad ut magna\"\n}"
    },
    {
      "name": "Lietotājs nav autentificēts.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/doc/mnv4/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            "mnv4",
            ":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/mnv4/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            "mnv4",
            ":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/mnv4/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            "mnv4",
            ":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": ""
    }
  ]
}