Chilkat Online Tools

PowerBuilder / Broker API / Document

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Jarr
oleobject loo_JsonObj_1
oleobject loo_SbRequestBody
oleobject loo_Resp

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Http.BasicAuth = 1
loo_Http.Login = "{{api_key}}"
loo_Http.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"
//   }
// ]

loo_Jarr = create oleobject
li_rc = loo_Jarr.ConnectToNewObject("Chilkat_9_5_0.JsonArray")

loo_Jarr.AddObjectAt(-1)
loo_JsonObj_1 = loo_Jarr.ObjectAt(loo_Jarr.Size - 1)
loo_JsonObj_1.UpdateString("document_type","cip_result")
loo_JsonObj_1.UpdateString("content","VGhlcmUgYXJlIG5vIHdpbGQgYWxwYWNhcy4=")
loo_JsonObj_1.UpdateString("mime_type","application/pdf")
destroy loo_JsonObj_1

loo_Jarr.AddObjectAt(-1)
loo_JsonObj_1 = loo_Jarr.ObjectAt(loo_Jarr.Size - 1)
loo_JsonObj_1.UpdateString("document_type","identity_verification")
loo_JsonObj_1.UpdateString("document_sub_type","passport")
loo_JsonObj_1.UpdateString("content","QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=")
loo_JsonObj_1.UpdateString("mime_type","image/jpeg")
destroy loo_JsonObj_1

loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Jarr.EmitSb(loo_SbRequestBody)

loo_Resp = loo_Http.PTextSb("POST","https://domain.com/v1/accounts/:account_id/documents/upload",loo_SbRequestBody,"utf-8","application/json",0,0)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Jarr
    destroy loo_SbRequestBody
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp


destroy loo_Http
destroy loo_Jarr
destroy loo_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": [
  ]
}