Chilkat Online Tools

SQL Server / EDS API / Dokuments "Akcīzes nodokļa aprēķins (likmju maiņas gadījumā)".

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/aniav3/: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)

    -- {
    --   "Talrunis": "velit f",
    --   "Epasts": "voluptate in",
    --   "NmVeids": "enim ipsum et",
    --   "Sagatavotajs": "incididunt pariatur",
    --   "LikmesDatums": "2000-01-31T00:00:00",
    --   "PrecuGrupas": "mollit cillum sunt velit eiusmod",
    --   "InvDatums": "2000-01-31T00:00:00",
    --   "MaksTermins": "2000-01-31T00:00:00",
    --   "NmAkcNumuri": "consequat cupidatat magna fugiat",
    --   "Tabula": [
    --     {
    --       "LikmeId": -70310886,
    --       "Kods": "sunt exercitation esse irure",
    --       "K3": 9325482.159040317,
    --       "K4": 46466485.181491464
    --     },
    --     {
    --       "LikmeId": 61440397,
    --       "Kods": "officia sit dolore",
    --       "K3": 34522730.61346921,
    --       "K4": 51331912.60301468
    --     }
    --   ],
    --   "Pielikumi": [
    --     {
    --       "Dokuments": "in consequat incididunt",
    --       "Fails": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "Komentars": "quis in ad"
    --     },
    --     {
    --       "Dokuments": "conse",
    --       "Fails": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "Komentars": "Ut dolore magna do"
    --     }
    --   ],
    --   "Id": 8468076,
    --   "UID": "enim eiusmod",
    --   "NmrKods": "in ",
    --   "Precizejums": false,
    --   "PrecizejamaisDokuments": -23123385,
    --   "PrecizejumaPamatojums": "nisi magna deserunt reprehenderit"
    -- }

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

    DECLARE @LikmeId int

    DECLARE @Kods nvarchar(4000)

    DECLARE @K3 nvarchar(4000)

    DECLARE @K4 nvarchar(4000)

    DECLARE @Dokuments nvarchar(4000)

    DECLARE @Value nvarchar(4000)

    DECLARE @Komentars nvarchar(4000)

    DECLARE @Talrunis nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Talrunis OUT, 'Talrunis'
    DECLARE @Epasts nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Epasts OUT, 'Epasts'
    DECLARE @NmVeids nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @NmVeids OUT, 'NmVeids'
    DECLARE @Sagatavotajs nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Sagatavotajs OUT, 'Sagatavotajs'
    DECLARE @LikmesDatums nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @LikmesDatums OUT, 'LikmesDatums'
    DECLARE @PrecuGrupas nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @PrecuGrupas OUT, 'PrecuGrupas'
    DECLARE @InvDatums nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @InvDatums OUT, 'InvDatums'
    DECLARE @MaksTermins nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @MaksTermins OUT, 'MaksTermins'
    DECLARE @NmAkcNumuri nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @NmAkcNumuri OUT, 'NmAkcNumuri'
    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, 'Tabula'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'IntOf', @LikmeId OUT, 'Tabula[i].LikmeId'
        EXEC sp_OAMethod @jResp, 'StringOf', @Kods OUT, 'Tabula[i].Kods'
        EXEC sp_OAMethod @jResp, 'StringOf', @K3 OUT, 'Tabula[i].K3'
        EXEC sp_OAMethod @jResp, 'StringOf', @K4 OUT, 'Tabula[i].K4'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'Pielikumi'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @Dokuments OUT, 'Pielikumi[i].Dokuments'
        EXEC sp_OAMethod @jResp, 'StringOf', @Value OUT, 'Pielikumi[i].Fails.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @Komentars OUT, 'Pielikumi[i].Komentars'
        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/aniav3/:id

Postman Collection Item JSON

{
  "name": "Dokuments \"Akcīzes nodokļa aprēķins (likmju maiņas gadījumā)\".",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/doc/aniav3/:id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "doc",
        "aniav3",
        ":id"
      ],
      "variable": [
        {
          "key": "id",
          "value": "25210683",
          "description": "(Required) Dokumenta id."
        }
      ]
    }
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/doc/aniav3/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            "aniav3",
            ":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  \"Talrunis\": \"velit f\",\n  \"Epasts\": \"voluptate in\",\n  \"NmVeids\": \"enim ipsum et\",\n  \"Sagatavotajs\": \"incididunt pariatur\",\n  \"LikmesDatums\": \"2000-01-31T00:00:00\",\n  \"PrecuGrupas\": \"mollit cillum sunt velit eiusmod\",\n  \"InvDatums\": \"2000-01-31T00:00:00\",\n  \"MaksTermins\": \"2000-01-31T00:00:00\",\n  \"NmAkcNumuri\": \"consequat cupidatat magna fugiat\",\n  \"Tabula\": [\n    {\n      \"LikmeId\": -70310886,\n      \"Kods\": \"sunt exercitation esse irure\",\n      \"K3\": 9325482.159040317,\n      \"K4\": 46466485.181491464\n    },\n    {\n      \"LikmeId\": 61440397,\n      \"Kods\": \"officia sit dolore\",\n      \"K3\": 34522730.61346921,\n      \"K4\": 51331912.60301468\n    }\n  ],\n  \"Pielikumi\": [\n    {\n      \"Dokuments\": \"in consequat incididunt\",\n      \"Fails\": {\n        \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n      },\n      \"Komentars\": \"quis in ad\"\n    },\n    {\n      \"Dokuments\": \"conse\",\n      \"Fails\": {\n        \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n      },\n      \"Komentars\": \"Ut dolore magna do\"\n    }\n  ],\n  \"Id\": 8468076,\n  \"UID\": \"enim eiusmod\",\n  \"NmrKods\": \"in \",\n  \"Precizejums\": false,\n  \"PrecizejamaisDokuments\": -23123385,\n  \"PrecizejumaPamatojums\": \"nisi magna deserunt reprehenderit\"\n}"
    },
    {
      "name": "Lietotājs nav autentificēts.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/api/doc/aniav3/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            "aniav3",
            ":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/aniav3/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            "aniav3",
            ":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/aniav3/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "doc",
            "aniav3",
            ":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": ""
    }
  ]
}