Chilkat Online Tools

PureBasic / Broker API / Reverse Batch Journal Transaction

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    CkHttp::setCkBasicAuth(http, 1)
    CkHttp::setCkLogin(http, "{{api_key}}")
    CkHttp::setCkPassword(http, "{{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",
    ;   "to_account": "7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7",
    ;   "entries": [
    ;     {
    ;       "from_account": "b8abc578-35ed-4bc0-bb55-6dc846f932eb",
    ;       "amount": "10"
    ;     },
    ;     {
    ;       "from_account": "fce64594-8d8c-4cda-97d5-3f9cdafbf4ef",
    ;       "amount": "100"
    ;     }
    ;   ]
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"entry_type","JNLC")
    CkJsonObject::ckUpdateString(json,"to_account","7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7")
    CkJsonObject::ckUpdateString(json,"entries[0].from_account","b8abc578-35ed-4bc0-bb55-6dc846f932eb")
    CkJsonObject::ckUpdateString(json,"entries[0].amount","10")
    CkJsonObject::ckUpdateString(json,"entries[1].from_account","fce64594-8d8c-4cda-97d5-3f9cdafbf4ef")
    CkJsonObject::ckUpdateString(json,"entries[1].amount","100")

    resp.i = CkHttp::ckPostJson3(http,"https://domain.com/v1/journals/reverse_batch","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

Curl Command

curl -X POST
	-u '{{api_key}}:{{api_secret}}'
	-d '{
  "entry_type": "JNLC",
  "to_account": "7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7",
  "entries": [
    { "from_account": "b8abc578-35ed-4bc0-bb55-6dc846f932eb", "amount": "10" },
    { "from_account": "fce64594-8d8c-4cda-97d5-3f9cdafbf4ef", "amount": "100" }
  ]
}'
https://domain.com/v1/journals/reverse_batch

Postman Collection Item JSON

{
  "name": "Reverse Batch Journal Transaction",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"entry_type\": \"JNLC\",\n  \"to_account\": \"7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7\",\n  \"entries\": [\n    { \"from_account\": \"b8abc578-35ed-4bc0-bb55-6dc846f932eb\", \"amount\": \"10\" },\n    { \"from_account\": \"fce64594-8d8c-4cda-97d5-3f9cdafbf4ef\", \"amount\": \"100\" }\n  ]\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HOST}}/v1/journals/reverse_batch",
      "host": [
        "{{HOST}}"
      ],
      "path": [
        "v1",
        "journals",
        "reverse_batch"
      ]
    },
    "description": "| Attribute      | Type          | Requirement                           | Notes                                                            |\n| -------------- | ------------- | ------------------------------------- | ---------------------------------------------------------------- |\n| `entry_type`   | string        | Required | ENUM: `JNLC` or `JNLS`                                           |\n| `to_account`   | string        | Required | The destination of funds. Most likely is your Sweep Firm Account |\n| `from_account` | string        | Required | The ID of the `from_account` that you want to journal from       |\n| `amount`       | string/number | Required | Journal amount in `USD`                                          |\n| `description`  | string        | Optional   | Journal description, gets returned in the response               |"
  },
  "response": [
  ]
}