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_OASetProperty @http, 'BasicAuth', 1
EXEC sp_OASetProperty @http, 'Login', '{{secretId}}'
EXEC sp_OASetProperty @http, 'Password', '{{secretPassword}}'
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://domain.com/api/invoices/', @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)
-- {
-- "count": "<integer>",
-- "next": "<string>",
-- "previous": "<string>",
-- "results": [
-- {
-- "description": "<string>",
-- "product_identification": "<string>",
-- "quantity": "<integer>",
-- "unit_code": "<string>",
-- "unit_description": "<string>",
-- "unit_amount": "<number>",
-- "pre_tax_amount": "<number>",
-- "tax_percentage": "<number>",
-- "tax_amount": "<number>",
-- "total_amount": "<number>",
-- "retained_taxes": [
-- {
-- "collected_at": "<dateTime>",
-- "tax": "<string>",
-- "tax_percentage": "<number>",
-- "retained_tax_amount": "<number>"
-- },
-- {
-- "collected_at": "<dateTime>",
-- "tax": "<string>",
-- "tax_percentage": "<number>",
-- "retained_tax_amount": "<number>"
-- }
-- ],
-- "collected_at": "<dateTime>"
-- },
-- {
-- "description": "<string>",
-- "product_identification": "<string>",
-- "quantity": "<integer>",
-- "unit_code": "<string>",
-- "unit_description": "<string>",
-- "unit_amount": "<number>",
-- "pre_tax_amount": "<number>",
-- "tax_percentage": "<number>",
-- "tax_amount": "<number>",
-- "total_amount": "<number>",
-- "retained_taxes": [
-- {
-- "collected_at": "<dateTime>",
-- "tax": "<string>",
-- "tax_percentage": "<number>",
-- "retained_tax_amount": "<number>"
-- },
-- {
-- "collected_at": "<dateTime>",
-- "tax": "<string>",
-- "tax_percentage": "<number>",
-- "retained_tax_amount": "<number>"
-- }
-- ],
-- "collected_at": "<dateTime>"
-- }
-- ]
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @description nvarchar(4000)
DECLARE @product_identification nvarchar(4000)
DECLARE @quantity nvarchar(4000)
DECLARE @unit_code nvarchar(4000)
DECLARE @unit_description nvarchar(4000)
DECLARE @unit_amount nvarchar(4000)
DECLARE @pre_tax_amount nvarchar(4000)
DECLARE @tax_percentage nvarchar(4000)
DECLARE @tax_amount nvarchar(4000)
DECLARE @total_amount nvarchar(4000)
DECLARE @collected_at nvarchar(4000)
DECLARE @j int
DECLARE @count_j int
DECLARE @tax nvarchar(4000)
DECLARE @retained_tax_amount nvarchar(4000)
DECLARE @count nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @count OUT, 'count'
DECLARE @v_next nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @v_next OUT, 'next'
DECLARE @previous nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @previous OUT, 'previous'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'results'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'results[i].description'
EXEC sp_OAMethod @jResp, 'StringOf', @product_identification OUT, 'results[i].product_identification'
EXEC sp_OAMethod @jResp, 'StringOf', @quantity OUT, 'results[i].quantity'
EXEC sp_OAMethod @jResp, 'StringOf', @unit_code OUT, 'results[i].unit_code'
EXEC sp_OAMethod @jResp, 'StringOf', @unit_description OUT, 'results[i].unit_description'
EXEC sp_OAMethod @jResp, 'StringOf', @unit_amount OUT, 'results[i].unit_amount'
EXEC sp_OAMethod @jResp, 'StringOf', @pre_tax_amount OUT, 'results[i].pre_tax_amount'
EXEC sp_OAMethod @jResp, 'StringOf', @tax_percentage OUT, 'results[i].tax_percentage'
EXEC sp_OAMethod @jResp, 'StringOf', @tax_amount OUT, 'results[i].tax_amount'
EXEC sp_OAMethod @jResp, 'StringOf', @total_amount OUT, 'results[i].total_amount'
EXEC sp_OAMethod @jResp, 'StringOf', @collected_at OUT, 'results[i].collected_at'
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'results[i].retained_taxes'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @collected_at OUT, 'results[i].retained_taxes[j].collected_at'
EXEC sp_OAMethod @jResp, 'StringOf', @tax OUT, 'results[i].retained_taxes[j].tax'
EXEC sp_OAMethod @jResp, 'StringOf', @tax_percentage OUT, 'results[i].retained_taxes[j].tax_percentage'
EXEC sp_OAMethod @jResp, 'StringOf', @retained_tax_amount OUT, 'results[i].retained_taxes[j].retained_tax_amount'
SELECT @j = @j + 1
END
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/invoices/
Postman Collection Item JSON
{
"name": "List",
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/api/invoices/",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"invoices",
""
],
"query": [
{
"key": "page",
"value": "1",
"description": "A page number within the paginated result set.",
"disabled": true
}
]
},
"description": "Get a paginated list of all existing invoices in your Belvo account. We return up to 100 results per page."
},
"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/invoices?page=<integer>",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"invoices"
],
"query": [
{
"key": "page",
"value": "<integer>"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n\t\"count\": \"<integer>\",\n\t\"next\": \"<string>\",\n\t\"previous\": \"<string>\",\n\t\"results\": [\n\t\t{\n\t\t\t\"description\": \"<string>\",\n\t\t\t\"product_identification\": \"<string>\",\n\t\t\t\"quantity\": \"<integer>\",\n\t\t\t\"unit_code\": \"<string>\",\n\t\t\t\"unit_description\": \"<string>\",\n\t\t\t\"unit_amount\": \"<number>\",\n\t\t\t\"pre_tax_amount\": \"<number>\",\n\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\"tax_amount\": \"<number>\",\n\t\t\t\"total_amount\": \"<number>\",\n\t\t\t\"retained_taxes\": [\n\t\t\t\t{\n\t\t\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\t\t\"tax\": \"<string>\",\n\t\t\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\t\t\"retained_tax_amount\": \"<number>\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\t\t\"tax\": \"<string>\",\n\t\t\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\t\t\"retained_tax_amount\": \"<number>\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"collected_at\": \"<dateTime>\"\n\t\t},\n\t\t{\n\t\t\t\"description\": \"<string>\",\n\t\t\t\"product_identification\": \"<string>\",\n\t\t\t\"quantity\": \"<integer>\",\n\t\t\t\"unit_code\": \"<string>\",\n\t\t\t\"unit_description\": \"<string>\",\n\t\t\t\"unit_amount\": \"<number>\",\n\t\t\t\"pre_tax_amount\": \"<number>\",\n\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\"tax_amount\": \"<number>\",\n\t\t\t\"total_amount\": \"<number>\",\n\t\t\t\"retained_taxes\": [\n\t\t\t\t{\n\t\t\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\t\t\"tax\": \"<string>\",\n\t\t\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\t\t\"retained_tax_amount\": \"<number>\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\t\t\"tax\": \"<string>\",\n\t\t\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\t\t\"retained_tax_amount\": \"<number>\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"collected_at\": \"<dateTime>\"\n\t\t}\n\t]\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/invoices?page=<integer>",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"invoices"
],
"query": [
{
"key": "page",
"value": "<integer>"
}
]
}
},
"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]"
}
]
}