Chilkat Online Tools

PureBasic / Broker API / Journal

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.

    ; {
    ;   "from_account": "7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7",
    ;   "entry_type": "JNLC",
    ;   "to_account": "b8abc578-35ed-4bc0-bb55-6dc846f932eb",
    ;   "amount": "51",
    ;   "description": "test text /fixtures/status=rejected/fixtures/"
    ; }

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

    CkJsonObject::ckUpdateString(json,"from_account","7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7")
    CkJsonObject::ckUpdateString(json,"entry_type","JNLC")
    CkJsonObject::ckUpdateString(json,"to_account","b8abc578-35ed-4bc0-bb55-6dc846f932eb")
    CkJsonObject::ckUpdateString(json,"amount","51")
    CkJsonObject::ckUpdateString(json,"description","test text /fixtures/status=rejected/fixtures/")

    resp.i = CkHttp::ckPostJson3(http,"https://domain.com/v1/journals","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 '{
  "from_account": "7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7",
  "entry_type": "JNLC",
  "to_account": "b8abc578-35ed-4bc0-bb55-6dc846f932eb",
  "amount": "51",
  "description": "test text /fixtures/status=rejected/fixtures/"
}'
https://domain.com/v1/journals

Postman Collection Item JSON

{
  "name": "Journal",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"from_account\": \"7a9e91a4-ed56-44cf-8e10-f6c1aeed05d7\",\n  \"entry_type\": \"JNLC\",\n  \"to_account\": \"b8abc578-35ed-4bc0-bb55-6dc846f932eb\",\n  \"amount\": \"51\",\n  \"description\": \"test text /fixtures/status=rejected/fixtures/\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HOST}}/v1/journals",
      "host": [
        "{{HOST}}"
      ],
      "path": [
        "v1",
        "journals"
      ]
    },
    "description": "| Attribute                         | Type           | Requirement | Notes |\n|-----------------------------------|----------------|-------------|:-----:|\n| `to_account`                        | string         | Required    | The `account_id` you wish to journal to |\n| `from_account`                      | string         | Required    | the `account_id you` wish to journal from |\n| `entry_type`                        | string         | Required    | ENUM: `JNLC` or `JNLS` |\n| `amount`                            | string/numeric | Required    | Required if `entry_type = JNLC` |\n| `symbol`                            | string         | Required    | Required if `entry_type = JNLS` |\n| `qty`                               | string/numeric | Required    | Required if `entry_type = JNLS` |\n| `description`                       | string         | Optional    | Max 1024 characters. Can include fixtures for amounts that are above the transaction limit |\n| `transmitter_name`                  | string         | Optional    | Max 255 characters. See more details about Travel Rule. |\n| `transmitter_account_number`        | string         | Optional    | Max 255 characters. See more details about Travel Rule. |\n| `transmitter_address`               | string         | Optional    | Max 255 characters. See more details about Travel Rule. |\n| `transmitter_financial_institution` | string         | Optional    | Max 255 characters. See more details about Travel Rule. |\n| `transmitter_timestamp`             | string         | Optional    | RFC 3339 format. See more details about Travel Rule. |"
  },
  "response": [
  ]
}