Android / Broker API / Document
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.
// [
// {
// "document_type": "cip_result",
// "content": "VGhlcmUgYXJlIG5vIHdpbGQgYWxwYWNhcy4=",
// "mime_type": "application/pdf"
// },
// {
// "document_type": "identity_verification",
// "document_sub_type": "passport",
// "content": "QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=",
// "mime_type": "image/jpeg"
// }
// ]
CkJsonArray jarr = new CkJsonArray();
jarr.AddObjectAt(-1);
CkJsonObject jsonObj_1 = jarr.ObjectAt(jarr.get_Size() - 1);
jsonObj_1.UpdateString("document_type","cip_result");
jsonObj_1.UpdateString("content","VGhlcmUgYXJlIG5vIHdpbGQgYWxwYWNhcy4=");
jsonObj_1.UpdateString("mime_type","application/pdf");
jarr.AddObjectAt(-1);
jsonObj_1 = jarr.ObjectAt(jarr.get_Size() - 1);
jsonObj_1.UpdateString("document_type","identity_verification");
jsonObj_1.UpdateString("document_sub_type","passport");
jsonObj_1.UpdateString("content","QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=");
jsonObj_1.UpdateString("mime_type","image/jpeg");
CkStringBuilder sbRequestBody = new CkStringBuilder();
jarr.EmitSb(sbRequestBody);
CkHttpResponse resp = http.PTextSb("POST","https://domain.com/v1/accounts/:account_id/documents/upload",sbRequestBody,"utf-8","application/json",false,false);
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 '[
{
"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": [
]
}