Chilkat Online Tools

SQL Server / Belvo API Docs / Detail

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

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

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://domain.com/api/statements/: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)

    -- {
    --   "id": "<uuid>",
    --   "link": "<string>",
    --   "account": {
    --     "id": "<uuid>",
    --     "name": "<string>",
    --     "category": "non consequat",
    --     "currency": "<string>"
    --   },
    --   "collected_at": "<dateTime>",
    --   "account_number": "<string>",
    --   "client_number": "<string>",
    --   "RFC": "<string>",
    --   "CLABE": "<string>",
    --   "period_start_date": "<date>",
    --   "period_end_date": "<date>",
    --   "cut_date": "<string>",
    --   "final_balance": "<number>",
    --   "previous_balance": "<number>",
    --   "total_inflow_amount": "<number>",
    --   "total_outflow_amount": "<number>",
    --   "total_inflow_transactions": "<number>",
    --   "total_outflow_transactions": "<number>",
    --   "transactions": [
    --     {
    --       "collected_at": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "accounting_date": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "value_date": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "reference": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "observations": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "additional_data": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "balance": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "status": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "type": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "currency": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "description": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "internal_identification": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "account": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       }
    --     },
    --     {
    --       "collected_at": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "accounting_date": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "value_date": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "reference": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "observations": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "additional_data": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "balance": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "status": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "type": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "currency": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "description": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "internal_identification": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "account": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       }
    --     }
    --   ],
    --   "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 @Value nvarchar(4000)

    DECLARE @accounting_dateValue nvarchar(4000)

    DECLARE @value_dateValue nvarchar(4000)

    DECLARE @referenceValue nvarchar(4000)

    DECLARE @observationsValue nvarchar(4000)

    DECLARE @additional_dataValue nvarchar(4000)

    DECLARE @balanceValue nvarchar(4000)

    DECLARE @statusValue nvarchar(4000)

    DECLARE @typeValue nvarchar(4000)

    DECLARE @currencyValue nvarchar(4000)

    DECLARE @descriptionValue nvarchar(4000)

    DECLARE @internal_identificationValue nvarchar(4000)

    DECLARE @accountValue nvarchar(4000)

    DECLARE @id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'id'
    DECLARE @link nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @link OUT, 'link'
    DECLARE @Id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'account.id'
    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'account.name'
    DECLARE @Category nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Category OUT, 'account.category'
    DECLARE @v_Currency nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Currency OUT, 'account.currency'
    DECLARE @collected_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @collected_at OUT, 'collected_at'
    DECLARE @account_number nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @account_number OUT, 'account_number'
    DECLARE @client_number nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @client_number OUT, 'client_number'
    DECLARE @RFC nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @RFC OUT, 'RFC'
    DECLARE @CLABE nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @CLABE OUT, 'CLABE'
    DECLARE @period_start_date nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @period_start_date OUT, 'period_start_date'
    DECLARE @period_end_date nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @period_end_date OUT, 'period_end_date'
    DECLARE @cut_date nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @cut_date OUT, 'cut_date'
    DECLARE @final_balance nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @final_balance OUT, 'final_balance'
    DECLARE @previous_balance nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @previous_balance OUT, 'previous_balance'
    DECLARE @total_inflow_amount nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @total_inflow_amount OUT, 'total_inflow_amount'
    DECLARE @total_outflow_amount nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @total_outflow_amount OUT, 'total_outflow_amount'
    DECLARE @total_inflow_transactions nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @total_inflow_transactions OUT, 'total_inflow_transactions'
    DECLARE @total_outflow_transactions nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @total_outflow_transactions OUT, 'total_outflow_transactions'
    DECLARE @pdf nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @pdf OUT, 'pdf'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'transactions'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @Value OUT, 'transactions[i].collected_at.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @accounting_dateValue OUT, 'transactions[i].accounting_date.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @value_dateValue OUT, 'transactions[i].value_date.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @referenceValue OUT, 'transactions[i].reference.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @observationsValue OUT, 'transactions[i].observations.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @additional_dataValue OUT, 'transactions[i].additional_data.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @balanceValue OUT, 'transactions[i].balance.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @statusValue OUT, 'transactions[i].status.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @typeValue OUT, 'transactions[i].type.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @currencyValue OUT, 'transactions[i].currency.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @descriptionValue OUT, 'transactions[i].description.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @internal_identificationValue OUT, 'transactions[i].internal_identification.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @accountValue OUT, 'transactions[i].account.value'
        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
	-u '{{secretId}}:{{secretPassword}}'
https://domain.com/api/statements/:id/

Postman Collection Item JSON

{
  "name": "Detail",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/statements/:id/",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "statements",
        ":id",
        ""
      ],
      "variable": [
        {
          "key": "id",
          "value": "consequa",
          "description": "(Required) The `statement.id` you want to get detailed information about."
        }
      ]
    },
    "description": "Get the details of a specific statement."
  },
  "response": [
    {
      "name": "Ok",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/statements/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "statements",
            ":id"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n\t\"id\": \"<uuid>\",\n\t\"link\": \"<string>\",\n\t\"account\": {\n\t\t\"id\": \"<uuid>\",\n\t\t\"name\": \"<string>\",\n\t\t\"category\": \"non consequat\",\n\t\t\"currency\": \"<string>\"\n\t},\n\t\"collected_at\": \"<dateTime>\",\n\t\"account_number\": \"<string>\",\n\t\"client_number\": \"<string>\",\n\t\"RFC\": \"<string>\",\n\t\"CLABE\": \"<string>\",\n\t\"period_start_date\": \"<date>\",\n\t\"period_end_date\": \"<date>\",\n\t\"cut_date\": \"<string>\",\n\t\"final_balance\": \"<number>\",\n\t\"previous_balance\": \"<number>\",\n\t\"total_inflow_amount\": \"<number>\",\n\t\"total_outflow_amount\": \"<number>\",\n\t\"total_inflow_transactions\": \"<number>\",\n\t\"total_outflow_transactions\": \"<number>\",\n\t\"transactions\": [\n\t\t{\n\t\t\t\"collected_at\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"accounting_date\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"value_date\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"reference\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"observations\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"additional_data\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"balance\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"status\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"type\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"currency\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"description\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"internal_identification\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"account\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t\"collected_at\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"accounting_date\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"value_date\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"reference\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"observations\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"additional_data\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"balance\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"status\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"type\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"currency\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"description\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"internal_identification\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t},\n\t\t\t\"account\": {\n\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t}\n\t\t}\n\t],\n\t\"pdf\": \"<binary>\"\n}"
    },
    {
      "name": "Unauthorized",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/statements/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "statements",
            ":id"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "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": "Too Many Sessions",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/statements/:id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "statements",
            ":id"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_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]"
    }
  ]
}