Chilkat Online Tools

unicodeC / Belvo API Docs / Register

Back to Collection Items

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

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *id;
    const wchar_t *institution;
    const wchar_t *access_mode;
    const wchar_t *last_accessed_at;
    const wchar_t *status;
    const wchar_t *created_by;
    const wchar_t *refresh_rate;

    // 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"{{secretId}}");
    CkHttpW_putPassword(http,L"{{secretPassword}}");

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "institution": "erebor_mx_retail",
    //   "username": "username",
    //   "password": "password",
    //   "username2": "secondusername",
    //   "username3": "thirdusername",
    //   "password2": "pin",
    //   "token": "1234ab",
    //   "access_mode": "recurrent",
    //   "username_type": "001",
    //   "certificate": "1234567890abcd=",
    //   "private_key": "1234567890abcd="
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"institution",L"erebor_mx_retail");
    CkJsonObjectW_UpdateString(json,L"username",L"username");
    CkJsonObjectW_UpdateString(json,L"password",L"password");
    CkJsonObjectW_UpdateString(json,L"username2",L"secondusername");
    CkJsonObjectW_UpdateString(json,L"username3",L"thirdusername");
    CkJsonObjectW_UpdateString(json,L"password2",L"pin");
    CkJsonObjectW_UpdateString(json,L"token",L"1234ab");
    CkJsonObjectW_UpdateString(json,L"access_mode",L"recurrent");
    CkJsonObjectW_UpdateString(json,L"username_type",L"001");
    CkJsonObjectW_UpdateString(json,L"certificate",L"1234567890abcd=");
    CkJsonObjectW_UpdateString(json,L"private_key",L"1234567890abcd=");

    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");

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

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "id": "<uuid>",
    //   "institution": "<string>",
    //   "access_mode": "<string>",
    //   "last_accessed_at": "<dateTime>",
    //   "status": "<string>",
    //   "created_by": "<uuid>",
    //   "refresh_rate": "<string>"
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    id = CkJsonObjectW_stringOf(jResp,L"id");
    institution = CkJsonObjectW_stringOf(jResp,L"institution");
    access_mode = CkJsonObjectW_stringOf(jResp,L"access_mode");
    last_accessed_at = CkJsonObjectW_stringOf(jResp,L"last_accessed_at");
    status = CkJsonObjectW_stringOf(jResp,L"status");
    created_by = CkJsonObjectW_stringOf(jResp,L"created_by");
    refresh_rate = CkJsonObjectW_stringOf(jResp,L"refresh_rate");


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -X POST
	-u '{{secretId}}:{{secretPassword}}'
	-H "Content-Type: application/json"
	-d '{
    "institution": "erebor_mx_retail",
    "username": "username",
    "password": "password",
    "username2": "secondusername",
    "username3": "thirdusername",
    "password2": "pin",
    "token": "1234ab",
    "access_mode": "recurrent",
    "username_type": "001",
    "certificate": "1234567890abcd=",
    "private_key": "1234567890abcd="
}'
https://domain.com/api/links/

Postman Collection Item JSON

{
  "name": "Register",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"institution\": \"erebor_mx_retail\",\n    \"username\": \"username\",\n    \"password\": \"password\",\n    \"username2\": \"secondusername\",\n    \"username3\": \"thirdusername\",\n    \"password2\": \"pin\",\n    \"token\": \"1234ab\",\n    \"access_mode\": \"recurrent\",\n    \"username_type\": \"001\",\n    \"certificate\": \"1234567890abcd=\",\n    \"private_key\": \"1234567890abcd=\"\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/links/",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "links",
        ""
      ]
    },
    "description": "Register a new link with your Belvo account."
  },
  "response": [
    {
      "name": "Created",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"institution\": \"<string>\",\n    \"username\": \"<string>\",\n    \"password\": \"<string>\",\n    \"username2\": \"<string>\",\n    \"username3\": \"<string>\",\n    \"password2\": \"<string>\",\n    \"token\": \"<string>\",\n    \"encryption_key\": \"<string>\",\n    \"access_mode\": \"recurrent\",\n    \"username_type\": \"<string>\",\n    \"certificate\": \"<string>\",\n    \"private_key\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/links",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "links"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n\t\"id\": \"<uuid>\",\n\t\"institution\": \"<string>\",\n\t\"access_mode\": \"<string>\",\n\t\"last_accessed_at\": \"<dateTime>\",\n\t\"status\": \"<string>\",\n\t\"created_by\": \"<uuid>\",\n\t\"refresh_rate\": \"<string>\"\n}"
    },
    {
      "name": "Bad request error",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"institution\": \"<string>\",\n    \"username\": \"<string>\",\n    \"password\": \"<string>\",\n    \"username2\": \"<string>\",\n    \"username3\": \"<string>\",\n    \"password2\": \"<string>\",\n    \"token\": \"<string>\",\n    \"encryption_key\": \"<string>\",\n    \"access_mode\": \"recurrent\",\n    \"username_type\": \"<string>\",\n    \"certificate\": \"<string>\",\n    \"private_key\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/links",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "links"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
    },
    {
      "name": "Unauthorized",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"institution\": \"<string>\",\n    \"username\": \"<string>\",\n    \"password\": \"<string>\",\n    \"username2\": \"<string>\",\n    \"username3\": \"<string>\",\n    \"password2\": \"<string>\",\n    \"token\": \"<string>\",\n    \"encryption_key\": \"<string>\",\n    \"access_mode\": \"recurrent\",\n    \"username_type\": \"<string>\",\n    \"certificate\": \"<string>\",\n    \"private_key\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/links",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "links"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
    },
    {
      "name": "MFA Token Required",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"institution\": \"<string>\",\n    \"username\": \"<string>\",\n    \"password\": \"<string>\",\n    \"username2\": \"<string>\",\n    \"username3\": \"<string>\",\n    \"password2\": \"<string>\",\n    \"token\": \"<string>\",\n    \"encryption_key\": \"<string>\",\n    \"access_mode\": \"recurrent\",\n    \"username_type\": \"<string>\",\n    \"certificate\": \"<string>\",\n    \"private_key\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/links",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "links"
          ]
        }
      },
      "status": "Precondition Required",
      "code": 428,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n\t\"code\": \"<string>\",\n\t\"message\": \"<string>\",\n\t\"request_id\": \"<uuid>\",\n\t\"session\": \"<uuid>\",\n\t\"expiry\": \"<integer>\",\n\t\"link\": \"<uuid>\",\n\t\"token_generation_data\": {\n\t\t\"instructions\": \"<string>\",\n\t\t\"type\": \"<string>\",\n\t\t\"value\": \"<string>\"\n\t}\n}"
    },
    {
      "name": "Unexpected Error",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"institution\": \"<string>\",\n    \"username\": \"<string>\",\n    \"password\": \"<string>\",\n    \"username2\": \"<string>\",\n    \"username3\": \"<string>\",\n    \"password2\": \"<string>\",\n    \"token\": \"<string>\",\n    \"encryption_key\": \"<string>\",\n    \"access_mode\": \"recurrent\",\n    \"username_type\": \"<string>\",\n    \"certificate\": \"<string>\",\n    \"private_key\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/links",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "links"
          ]
        }
      },
      "status": "Internal Server Error",
      "code": 500,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "[\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t},\n\t{\n\t\t\"code\": \"<string>\",\n\t\t\"message\": \"<string>\",\n\t\t\"request_id\": \"<string>\"\n\t}\n]"
    }
  ]
}