unicodeC / Broker API / Document
Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonArrayW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonArrayW jarr;
HCkJsonObjectW jsonObj_1;
HCkStringBuilderW sbRequestBody;
HCkHttpResponseW resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
CkHttpW_putBasicAuth(http,TRUE);
CkHttpW_putLogin(http,L"{{api_key}}");
CkHttpW_putPassword(http,L"{{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"
// }
// ]
jarr = CkJsonArrayW_Create();
CkJsonArrayW_AddObjectAt(jarr,-1);
jsonObj_1 = CkJsonArrayW_ObjectAt(jarr,CkJsonArrayW_getSize(jarr) - 1);
CkJsonObjectW_UpdateString(jsonObj_1,L"document_type",L"cip_result");
CkJsonObjectW_UpdateString(jsonObj_1,L"content",L"VGhlcmUgYXJlIG5vIHdpbGQgYWxwYWNhcy4=");
CkJsonObjectW_UpdateString(jsonObj_1,L"mime_type",L"application/pdf");
CkJsonObjectW_Dispose(jsonObj_1);
CkJsonArrayW_AddObjectAt(jarr,-1);
jsonObj_1 = CkJsonArrayW_ObjectAt(jarr,CkJsonArrayW_getSize(jarr) - 1);
CkJsonObjectW_UpdateString(jsonObj_1,L"document_type",L"identity_verification");
CkJsonObjectW_UpdateString(jsonObj_1,L"document_sub_type",L"passport");
CkJsonObjectW_UpdateString(jsonObj_1,L"content",L"QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=");
CkJsonObjectW_UpdateString(jsonObj_1,L"mime_type",L"image/jpeg");
CkJsonObjectW_Dispose(jsonObj_1);
sbRequestBody = CkStringBuilderW_Create();
CkJsonArrayW_EmitSb(jarr,sbRequestBody);
resp = CkHttpW_PTextSb(http,L"POST",L"https://domain.com/v1/accounts/:account_id/documents/upload",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonArrayW_Dispose(jarr);
CkStringBuilderW_Dispose(sbRequestBody);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonArrayW_Dispose(jarr);
CkStringBuilderW_Dispose(sbRequestBody);
}
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": [
]
}