Chilkat Online Tools

SQL Server / Belvo API Docs / Retrieve

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
    DECLARE @iTmp0 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_OASetProperty @http, 'BasicAuth', 1
    EXEC sp_OASetProperty @http, 'Login', '{{secretId}}'
    EXEC sp_OASetProperty @http, 'Password', '{{secretPassword}}'

    -- Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    -- The following JSON is sent in the request body.

    -- {
    --   "link": "d4617561-1c01-4b2f-83b6-a594f7b3bc57",
    --   "year_from": 2018,
    --   "year_to": 2019,
    --   "type": "yearly",
    --   "attach_pdf": false,
    --   "encryption_key": "customencryptionkey",
    --   "save_data": true
    -- }

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

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'link', 'd4617561-1c01-4b2f-83b6-a594f7b3bc57'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'year_from', 2018
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'year_to', 2019
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'type', 'yearly'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'attach_pdf', 0
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'encryption_key', 'customencryptionkey'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'save_data', 1

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/api/tax-returns/', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

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

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    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 @resp, 'StatusCode', @respStatusCode OUT

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

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

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

    -- {
    --   "link": "<uuid>",
    --   "collected_at": "<dateTime>",
    --   "informacion_general": "<object>",
    --   "sueldos_salarios": "<object>",
    --   "servicios_profesionales": "<object>",
    --   "deducciones_personales": "<object>",
    --   "determinacion_impuesto": "<object>",
    --   "retenciones": "<object>",
    --   "dividendos": "<object>",
    --   "datos_informativos": "<object>",
    --   "pdf": "<binary>"
    -- }

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

    DECLARE @link nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @link OUT, 'link'
    DECLARE @collected_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @collected_at OUT, 'collected_at'
    DECLARE @informacion_general nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @informacion_general OUT, 'informacion_general'
    DECLARE @sueldos_salarios nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sueldos_salarios OUT, 'sueldos_salarios'
    DECLARE @servicios_profesionales nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @servicios_profesionales OUT, 'servicios_profesionales'
    DECLARE @deducciones_personales nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @deducciones_personales OUT, 'deducciones_personales'
    DECLARE @determinacion_impuesto nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @determinacion_impuesto OUT, 'determinacion_impuesto'
    DECLARE @retenciones nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @retenciones OUT, 'retenciones'
    DECLARE @dividendos nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @dividendos OUT, 'dividendos'
    DECLARE @datos_informativos nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @datos_informativos OUT, 'datos_informativos'
    DECLARE @pdf nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @pdf OUT, 'pdf'

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


END
GO

Curl Command

curl -X POST
	-u '{{secretId}}:{{secretPassword}}'
	-H "Content-Type: application/json"
	-d '{
    "link": "d4617561-1c01-4b2f-83b6-a594f7b3bc57",
    "year_from": 2018,
    "year_to": 2019,
    "type": "yearly", // Note: Check the documentation to the right for more information.
    "attach_pdf": false,
    "encryption_key": "customencryptionkey",
    "save_data": true
}'
https://domain.com/api/tax-returns/

Postman Collection Item JSON

{
  "name": "Retrieve",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"link\": \"d4617561-1c01-4b2f-83b6-a594f7b3bc57\",\n    \"year_from\": 2018,\n    \"year_to\": 2019,\n    \"type\": \"yearly\", // Note: Check the documentation to the right for more information.\n    \"attach_pdf\": false,\n    \"encryption_key\": \"customencryptionkey\",\n    \"save_data\": true\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/tax-returns/",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "tax-returns",
        ""
      ]
    },
    "description": "Retrieve tax return information for a specific fiscal link.\n\nFor more information on how to use the `type` parameter, please see the full [documentation for the Tax Returns endpoint](https://docs.belvo.com/#operation/RetrieveTaxReturns)."
  },
  "response": [
    {
      "name": "Ok (when save_data=false)",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n\t\"link\": \"<uuid>\",\n\t\"collected_at\": \"<dateTime>\",\n\t\"informacion_general\": \"<object>\",\n\t\"sueldos_salarios\": \"<object>\",\n\t\"servicios_profesionales\": \"<object>\",\n\t\"deducciones_personales\": \"<object>\",\n\t\"determinacion_impuesto\": \"<object>\",\n\t\"retenciones\": \"<object>\",\n\t\"dividendos\": \"<object>\",\n\t\"datos_informativos\": \"<object>\",\n\t\"pdf\": \"<binary>\"\n}"
    },
    {
      "name": "Created (when save_data=true)",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "[\n\t{\n\t\t\"id\": \"<uuid>\",\n\t\t\"link\": \"<uuid>\",\n\t\t\"collected_at\": \"<dateTime>\",\n\t\t\"informacion_general\": \"<object>\",\n\t\t\"sueldos_salarios\": \"<object>\",\n\t\t\"servicios_profesionales\": \"<object>\",\n\t\t\"deducciones_personales\": \"<object>\",\n\t\t\"determinacion_impuesto\": \"<object>\",\n\t\t\"retenciones\": \"<object>\",\n\t\t\"dividendos\": \"<object>\",\n\t\t\"datos_informativos\": \"<object>\",\n\t\t\"pdf\": \"<binary>\"\n\t},\n\t{\n\t\t\"id\": \"<uuid>\",\n\t\t\"link\": \"<uuid>\",\n\t\t\"collected_at\": \"<dateTime>\",\n\t\t\"informacion_general\": \"<object>\",\n\t\t\"sueldos_salarios\": \"<object>\",\n\t\t\"servicios_profesionales\": \"<object>\",\n\t\t\"deducciones_personales\": \"<object>\",\n\t\t\"determinacion_impuesto\": \"<object>\",\n\t\t\"retenciones\": \"<object>\",\n\t\t\"dividendos\": \"<object>\",\n\t\t\"datos_informativos\": \"<object>\",\n\t\t\"pdf\": \"<binary>\"\n\t}\n]"
    },
    {
      "name": "Bad request error",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
    },
    {
      "name": "Unauthorized",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
    },
    {
      "name": "Request Timeout",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "status": "Request Timeout",
      "code": 408,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
    },
    {
      "name": "Unexpected Error",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "status": "Internal Server Error",
      "code": 500,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
    }
  ]
}