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/: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)
-- {
-- "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 @tax nvarchar(4000)
DECLARE @retained_tax_amount nvarchar(4000)
DECLARE @description nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'description'
DECLARE @product_identification nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @product_identification OUT, 'product_identification'
DECLARE @quantity nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @quantity OUT, 'quantity'
DECLARE @unit_code nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @unit_code OUT, 'unit_code'
DECLARE @unit_description nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @unit_description OUT, 'unit_description'
DECLARE @unit_amount nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @unit_amount OUT, 'unit_amount'
DECLARE @pre_tax_amount nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @pre_tax_amount OUT, 'pre_tax_amount'
DECLARE @tax_percentage nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @tax_percentage OUT, 'tax_percentage'
DECLARE @tax_amount nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @tax_amount OUT, 'tax_amount'
DECLARE @total_amount nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @total_amount OUT, 'total_amount'
DECLARE @collected_at nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @collected_at OUT, 'collected_at'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'retained_taxes'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @collected_at OUT, 'retained_taxes[i].collected_at'
EXEC sp_OAMethod @jResp, 'StringOf', @tax OUT, 'retained_taxes[i].tax'
EXEC sp_OAMethod @jResp, 'StringOf', @tax_percentage OUT, 'retained_taxes[i].tax_percentage'
EXEC sp_OAMethod @jResp, 'StringOf', @retained_tax_amount OUT, 'retained_taxes[i].retained_tax_amount'
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/:id/
Postman Collection Item JSON
{
"name": "Detail",
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/api/invoices/:id/",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"invoices",
":id",
""
],
"variable": [
{
"key": "id",
"value": "consequa",
"description": "(Required) The `invoice.id` you want to get detailed information about."
}
]
},
"description": "Get the details of a specific invoice."
},
"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/:id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"invoices",
":id"
],
"variable": [
{
"key": "id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n\t\"description\": \"<string>\",\n\t\"product_identification\": \"<string>\",\n\t\"quantity\": \"<integer>\",\n\t\"unit_code\": \"<string>\",\n\t\"unit_description\": \"<string>\",\n\t\"unit_amount\": \"<number>\",\n\t\"pre_tax_amount\": \"<number>\",\n\t\"tax_percentage\": \"<number>\",\n\t\"tax_amount\": \"<number>\",\n\t\"total_amount\": \"<number>\",\n\t\"retained_taxes\": [\n\t\t{\n\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\"tax\": \"<string>\",\n\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\"retained_tax_amount\": \"<number>\"\n\t\t},\n\t\t{\n\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\"tax\": \"<string>\",\n\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\"retained_tax_amount\": \"<number>\"\n\t\t}\n\t],\n\t\"collected_at\": \"<dateTime>\"\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/:id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"invoices",
":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/invoices/:id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"invoices",
":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]"
}
]
}