Chilkat Online Tools

SQL Server / Belvo API Docs / Register

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OASetProperty @http, 'BasicAuth', 1
    EXEC sp_OASetProperty @http, 'Login', '{{secretId}}'
    EXEC sp_OASetProperty @http, 'Password', '{{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="
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'institution', 'erebor_mx_retail'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'username', 'username'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'password', 'password'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'username2', 'secondusername'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'username3', 'thirdusername'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'password2', 'pin'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'token', '1234ab'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'access_mode', 'recurrent'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'username_type', '001'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'certificate', '1234567890abcd='
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'private_key', '1234567890abcd='

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/api/links/', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @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

    DECLARE @id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'id'
    DECLARE @institution nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @institution OUT, 'institution'
    DECLARE @access_mode nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @access_mode OUT, 'access_mode'
    DECLARE @last_accessed_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @last_accessed_at OUT, 'last_accessed_at'
    DECLARE @status nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'status'
    DECLARE @created_by nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @created_by OUT, 'created_by'
    DECLARE @refresh_rate nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @refresh_rate OUT, 'refresh_rate'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

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