Chilkat Online Tools

unicodeC / Broker API / Account

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    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.

    // {
    //   "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"
    //   }
    // }

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

    resp = CkHttpW_PostJson3(http,L"https://domain.com/v1/accounts",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

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