Chilkat Online Tools

Swift3 / Broker API / Document

Back to Collection Items

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

    let http = CkoHttp()!
    var success: Bool

    http.basicAuth = true
    http.login = "{{api_key}}"
    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"
    //   }
    // ]

    let jarr = CkoJsonArray()!

    jarr.addObject(at: -1)
    var jsonObj_1: CkoJsonObject? = jarr.object(at: jarr.size.intValue - 1)
    jsonObj_1!.update("document_type", value: "cip_result")
    jsonObj_1!.update("content", value: "VGhlcmUgYXJlIG5vIHdpbGQgYWxwYWNhcy4=")
    jsonObj_1!.update("mime_type", value: "application/pdf")
    jsonObj_1 = nil

    jarr.addObject(at: -1)
    jsonObj_1 = jarr.object(at: jarr.size.intValue - 1)
    jsonObj_1!.update("document_type", value: "identity_verification")
    jsonObj_1!.update("document_sub_type", value: "passport")
    jsonObj_1!.update("content", value: "QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=")
    jsonObj_1!.update("mime_type", value: "image/jpeg")
    jsonObj_1 = nil

    let sbRequestBody = CkoStringBuilder()!
    jarr.emitSb(sbRequestBody)

    var resp: CkoHttpResponse? = http.pTextSb("POST", url: "https://domain.com/v1/accounts/:account_id/documents/upload", textData: sbRequestBody, charset: "utf-8", contentType: "application/json", md5: false, gzip: false)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    print("\(resp!.statusCode.intValue)")
    print("\(resp!.bodyStr!)")
    resp = nil

}

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