SQL Server / Broker API / Batch Journal Transaction
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.
-- {
-- "entry_type": "JNLC",
-- "from_account": "7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7",
-- "entries": [
-- {
-- "to_account": "b8abc578-35ed-4bc0-bb55-6dc846f932eb",
-- "amount": "10"
-- },
-- {
-- "to_account": "fce64594-8d8c-4cda-97d5-3f9cdafbf4ef",
-- "amount": "100"
-- }
-- ]
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'entry_type', 'JNLC'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'from_account', '7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'entries[0].to_account', 'b8abc578-35ed-4bc0-bb55-6dc846f932eb'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'entries[0].amount', '10'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'entries[1].to_account', 'fce64594-8d8c-4cda-97d5-3f9cdafbf4ef'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'entries[1].amount', '100'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/v1/journals/batch', '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
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 @json
END
GO
Curl Command
curl -X POST
-u '{{api_key}}:{{api_secret}}'
-d '{
"entry_type": "JNLC",
"from_account": "7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7",
"entries": [
{
"to_account": "b8abc578-35ed-4bc0-bb55-6dc846f932eb",
"amount": "10"
},
{
"to_account": "fce64594-8d8c-4cda-97d5-3f9cdafbf4ef",
"amount": "100"
}
]
}'
https://domain.com/v1/journals/batch
Postman Collection Item JSON
{
"name": "Batch Journal Transaction",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"entry_type\": \"JNLC\",\n \"from_account\": \"7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7\",\n \"entries\": [\n {\n \"to_account\": \"b8abc578-35ed-4bc0-bb55-6dc846f932eb\",\n \"amount\": \"10\"\n },\n {\n \"to_account\": \"fce64594-8d8c-4cda-97d5-3f9cdafbf4ef\",\n \"amount\": \"100\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{HOST}}/v1/journals/batch",
"host": [
"{{HOST}}"
],
"path": [
"v1",
"journals",
"batch"
]
},
"description": "| Attribute | Type | Requirement | Notes |\n| -------------- | ------------- | ------------------------------------- | --------------------------------------------------------------- |\n| `entry_type` | string | Required | ENUM: `JNLC` or `JNLS` |\n| `from_account` | string | Required | The originator of funds. Most likely is your Sweep Firm Account |\n| `to_account` | string | Required | The ID of the `to_account` that you want to journal into |\n| `amount` | string/number | Required | Journal amount in `USD` |\n| `description` | string | Optional | Journal description, gets returned in the response |"
},
"response": [
]
}