Chilkat Online Tools

Android / Broker API / Batch Journal Transaction

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    CkHttp http = new CkHttp();
    boolean success;

    http.put_BasicAuth(true);
    http.put_Login("{{api_key}}");
    http.put_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"
    //     }
    //   ]
    // }

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

    CkHttpResponse resp = http.PostJson3("https://domain.com/v1/journals/batch","application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    Log.i(TAG, String.valueOf(resp.get_StatusCode()));
    Log.i(TAG, resp.bodyStr());


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

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": [
  ]
}