SQL Server / Broker API / Document
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
-- 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', '{{api_key}}'
EXEC sp_OASetProperty @http, 'Password', '{{api_secret}}'
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- [
-- {
-- "document_type": "cip_result",
-- "content": "VGhlcmUgYXJlIG5vIHdpbGQgYWxwYWNhcy4=",
-- "mime_type": "application/pdf"
-- },
-- {
-- "document_type": "identity_verification",
-- "document_sub_type": "passport",
-- "content": "QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=",
-- "mime_type": "image/jpeg"
-- }
-- ]
DECLARE @jarr int
-- Use "Chilkat_9_5_0.JsonArray" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonArray', @jarr OUT
EXEC sp_OAMethod @jarr, 'AddObjectAt', @success OUT, -1
DECLARE @jsonObj_1 int
EXEC sp_OAGetProperty @jarr, 'Size', @iTmp0 OUT
EXEC sp_OAMethod @jarr, 'ObjectAt', @jsonObj_1 OUT, @iTmp0 - 1
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'document_type', 'cip_result'
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'content', 'VGhlcmUgYXJlIG5vIHdpbGQgYWxwYWNhcy4='
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'mime_type', 'application/pdf'
EXEC @hr = sp_OADestroy @jsonObj_1
EXEC sp_OAMethod @jarr, 'AddObjectAt', @success OUT, -1
EXEC sp_OAGetProperty @jarr, 'Size', @iTmp0 OUT
EXEC sp_OAMethod @jarr, 'ObjectAt', @jsonObj_1 OUT, @iTmp0 - 1
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'document_type', 'identity_verification'
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'document_sub_type', 'passport'
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'content', 'QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4='
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'mime_type', 'image/jpeg'
EXEC @hr = sp_OADestroy @jsonObj_1
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @jarr, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'POST', 'https://domain.com/v1/accounts/:account_id/documents/upload', @sbRequestBody, 'utf-8', 'application/json', 0, 0
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 @jarr
EXEC @hr = sp_OADestroy @sbRequestBody
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jarr
EXEC @hr = sp_OADestroy @sbRequestBody
END
GO
Curl Command
curl -X POST
-u '{{api_key}}:{{api_secret}}'
-d '[
{
"document_type": "cip_result",
"content": "VGhlcmUgYXJlIG5vIHdpbGQgYWxwYWNhcy4=",
"mime_type": "application/pdf"
},
{
"document_type": "identity_verification",
"document_sub_type": "passport",
"content": "QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=",
"mime_type": "image/jpeg"
}
]'
https://domain.com/v1/accounts/:account_id/documents/upload
Postman Collection Item JSON
{
"name": "Document",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "[\n {\n \"document_type\": \"cip_result\",\n \"content\": \"VGhlcmUgYXJlIG5vIHdpbGQgYWxwYWNhcy4=\",\n \"mime_type\": \"application/pdf\"\n },\n {\n \"document_type\": \"identity_verification\",\n \"document_sub_type\": \"passport\",\n \"content\": \"QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=\",\n \"mime_type\": \"image/jpeg\"\n }\n]",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{HOST}}/v1/accounts/:account_id/documents/upload",
"host": [
"{{HOST}}"
],
"path": [
"v1",
"accounts",
":account_id",
"documents",
"upload"
],
"variable": [
{
"key": "account_id",
"value": null
}
]
},
"description": "| Key | Value | Requirement |\n|-------------------|-----------------------|:-----------:|\n| `document_upload` | models.DocumentUpload | Required |"
},
"response": [
]
}