Chilkat Online Tools

Swift / Broker API / Account

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.

    // {
    //   "contact": {
    //     "email_address": "cool_alpaca@example.com",
    //     "phone_number": "555-666-7788",
    //     "street_address": [
    //       "20 N San Mateo Dr"
    //     ],
    //     "city": "San Mateo",
    //     "state": "CA",
    //     "postal_code": "94401",
    //     "country": "USA"
    //   },
    //   "identity": {
    //     "given_name": "John",
    //     "family_name": "Doe",
    //     "date_of_birth": "1990-01-01",
    //     "tax_id": "666-55-4321",
    //     "tax_id_type": "USA_SSN",
    //     "country_of_citizenship": "USA",
    //     "country_of_birth": "USA",
    //     "country_of_tax_residence": "USA",
    //     "funding_source": [
    //       "employment_income"
    //     ]
    //   },
    //   "disclosures": {
    //     "is_control_person": false,
    //     "is_affiliated_exchange_or_finra": false,
    //     "is_politically_exposed": false,
    //     "immediate_family_exposed": false
    //   },
    //   "agreements": [
    //     {
    //       "agreement": "margin_agreement",
    //       "signed_at": "2020-09-11T18:09:33Z",
    //       "ip_address": "185.13.21.99"
    //     },
    //     {
    //       "agreement": "account_agreement",
    //       "signed_at": "2020-09-11T18:13:44Z",
    //       "ip_address": "185.13.21.99"
    //     },
    //     {
    //       "agreement": "customer_agreement",
    //       "signed_at": "2020-09-11T18:13:44Z",
    //       "ip_address": "185.13.21.99"
    //     }
    //   ],
    //   "documents": [
    //     {
    //       "document_type": "identity_verification",
    //       "document_sub_type": "passport",
    //       "content": "QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=",
    //       "mime_type": "image/jpeg"
    //     }
    //   ],
    //   "trusted_contact": {
    //     "given_name": "Jane",
    //     "family_name": "Doe",
    //     "email_address": "jane.doe@example.com"
    //   }
    // }

    let json = CkoJsonObject()
    json.UpdateString("contact.email_address", value: "cool_alpaca@example.com")
    json.UpdateString("contact.phone_number", value: "555-666-7788")
    json.UpdateString("contact.street_address[0]", value: "20 N San Mateo Dr")
    json.UpdateString("contact.city", value: "San Mateo")
    json.UpdateString("contact.state", value: "CA")
    json.UpdateString("contact.postal_code", value: "94401")
    json.UpdateString("contact.country", value: "USA")
    json.UpdateString("identity.given_name", value: "John")
    json.UpdateString("identity.family_name", value: "Doe")
    json.UpdateString("identity.date_of_birth", value: "1990-01-01")
    json.UpdateString("identity.tax_id", value: "666-55-4321")
    json.UpdateString("identity.tax_id_type", value: "USA_SSN")
    json.UpdateString("identity.country_of_citizenship", value: "USA")
    json.UpdateString("identity.country_of_birth", value: "USA")
    json.UpdateString("identity.country_of_tax_residence", value: "USA")
    json.UpdateString("identity.funding_source[0]", value: "employment_income")
    json.UpdateBool("disclosures.is_control_person", value: false)
    json.UpdateBool("disclosures.is_affiliated_exchange_or_finra", value: false)
    json.UpdateBool("disclosures.is_politically_exposed", value: false)
    json.UpdateBool("disclosures.immediate_family_exposed", value: false)
    json.UpdateString("agreements[0].agreement", value: "margin_agreement")
    json.UpdateString("agreements[0].signed_at", value: "2020-09-11T18:09:33Z")
    json.UpdateString("agreements[0].ip_address", value: "185.13.21.99")
    json.UpdateString("agreements[1].agreement", value: "account_agreement")
    json.UpdateString("agreements[1].signed_at", value: "2020-09-11T18:13:44Z")
    json.UpdateString("agreements[1].ip_address", value: "185.13.21.99")
    json.UpdateString("agreements[2].agreement", value: "customer_agreement")
    json.UpdateString("agreements[2].signed_at", value: "2020-09-11T18:13:44Z")
    json.UpdateString("agreements[2].ip_address", value: "185.13.21.99")
    json.UpdateString("documents[0].document_type", value: "identity_verification")
    json.UpdateString("documents[0].document_sub_type", value: "passport")
    json.UpdateString("documents[0].content", value: "QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=")
    json.UpdateString("documents[0].mime_type", value: "image/jpeg")
    json.UpdateString("trusted_contact.given_name", value: "Jane")
    json.UpdateString("trusted_contact.family_name", value: "Doe")
    json.UpdateString("trusted_contact.email_address", value: "jane.doe@example.com")

    var resp: CkoHttpResponse? = http.PostJson3("https://domain.com/v1/accounts", contentType: "application/json", json: json)
    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 '{
  "contact": {
    "email_address": "cool_alpaca@example.com",
    "phone_number": "555-666-7788",
    "street_address": ["20 N San Mateo Dr"],
    "city": "San Mateo",
    "state": "CA",
    "postal_code": "94401",
    "country": "USA"
  },
  "identity": {
    "given_name": "John",
    "family_name": "Doe",
    "date_of_birth": "1990-01-01",
    "tax_id": "666-55-4321",
    "tax_id_type": "USA_SSN",
    "country_of_citizenship": "USA",
    "country_of_birth": "USA",
    "country_of_tax_residence": "USA",
    "funding_source": ["employment_income"]
  },
  "disclosures": {
    "is_control_person": false,
    "is_affiliated_exchange_or_finra": false,
    "is_politically_exposed": false,
    "immediate_family_exposed": false
  },
  "agreements": [
    {
      "agreement": "margin_agreement",
      "signed_at": "2020-09-11T18:09:33Z",
      "ip_address": "185.13.21.99"
    },
    {
      "agreement": "account_agreement",
      "signed_at": "2020-09-11T18:13:44Z",
      "ip_address": "185.13.21.99"
    },
    {
      "agreement": "customer_agreement",
      "signed_at": "2020-09-11T18:13:44Z",
      "ip_address": "185.13.21.99"
    }
  ],
  "documents": [
    {
      "document_type": "identity_verification",
      "document_sub_type": "passport",
      "content": "QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=",
      "mime_type": "image/jpeg"
    }
  ],
  "trusted_contact": {
    "given_name": "Jane",
    "family_name": "Doe",
    "email_address": "jane.doe@example.com"
  }
}'
https://domain.com/v1/accounts

Postman Collection Item JSON

{
  "name": "Account",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"contact\": {\n    \"email_address\": \"cool_alpaca@example.com\",\n    \"phone_number\": \"555-666-7788\",\n    \"street_address\": [\"20 N San Mateo Dr\"],\n    \"city\": \"San Mateo\",\n    \"state\": \"CA\",\n    \"postal_code\": \"94401\",\n    \"country\": \"USA\"\n  },\n  \"identity\": {\n    \"given_name\": \"John\",\n    \"family_name\": \"Doe\",\n    \"date_of_birth\": \"1990-01-01\",\n    \"tax_id\": \"666-55-4321\",\n    \"tax_id_type\": \"USA_SSN\",\n    \"country_of_citizenship\": \"USA\",\n    \"country_of_birth\": \"USA\",\n    \"country_of_tax_residence\": \"USA\",\n    \"funding_source\": [\"employment_income\"]\n  },\n  \"disclosures\": {\n    \"is_control_person\": false,\n    \"is_affiliated_exchange_or_finra\": false,\n    \"is_politically_exposed\": false,\n    \"immediate_family_exposed\": false\n  },\n  \"agreements\": [\n    {\n      \"agreement\": \"margin_agreement\",\n      \"signed_at\": \"2020-09-11T18:09:33Z\",\n      \"ip_address\": \"185.13.21.99\"\n    },\n    {\n      \"agreement\": \"account_agreement\",\n      \"signed_at\": \"2020-09-11T18:13:44Z\",\n      \"ip_address\": \"185.13.21.99\"\n    },\n    {\n      \"agreement\": \"customer_agreement\",\n      \"signed_at\": \"2020-09-11T18:13:44Z\",\n      \"ip_address\": \"185.13.21.99\"\n    }\n  ],\n  \"documents\": [\n    {\n      \"document_type\": \"identity_verification\",\n      \"document_sub_type\": \"passport\",\n      \"content\": \"QWxwYWNhcyBjYW5ub3QgbGl2ZSBhbG9uZS4=\",\n      \"mime_type\": \"image/jpeg\"\n    }\n  ],\n  \"trusted_contact\": {\n    \"given_name\": \"Jane\",\n    \"family_name\": \"Doe\",\n    \"email_address\": \"jane.doe@example.com\"\n  }\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HOST}}/v1/accounts",
      "host": [
        "{{HOST}}"
      ],
      "path": [
        "v1",
        "accounts"
      ]
    },
    "description": "| Attribute         | Requirement     |\n| -------------     |:-------------:  |\n| `contact`         | Required        |\n| `identity`        | Required        |\n| `disclosures`     | Required        |\n| `documents`       | Optional        |\n| `trusted_contact` | Optional        |"
  },
  "response": [
  ]
}