Chilkat Online Tools

SQL Server / Belvo API Docs / List

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}}'

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

    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'page', 1

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://domain.com/api/owners/', @queryParams
    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 @queryParams
        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 @queryParams
        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)

    -- {
    --   "count": "<integer>",
    --   "next": "<string>",
    --   "previous": "<string>",
    --   "results": [
    --     {
    --       "id": "<uuid>",
    --       "link": "<uuid>",
    --       "collected_at": "<dateTime>",
    --       "display_name": "<string>",
    --       "first_name": "<string>",
    --       "last_name": "<string>",
    --       "second_last_name": "<string>",
    --       "address": "<string>",
    --       "email": "<email>",
    --       "phone_number": "<string>",
    --       "accounts": [
    --         {
    --           "value": "<Error: Too many levels of nesting to fake this schema>"
    --         },
    --         {
    --           "value": "<Error: Too many levels of nesting to fake this schema>"
    --         }
    --       ],
    --       "gig_data": {
    --         "collected_at": "<dateTime>",
    --         "status": "<string>",
    --         "acceptance_rate": "<number>"
    --       }
    --     },
    --     {
    --       "id": "<uuid>",
    --       "link": "<uuid>",
    --       "collected_at": "<dateTime>",
    --       "display_name": "<string>",
    --       "first_name": "<string>",
    --       "last_name": "<string>",
    --       "second_last_name": "<string>",
    --       "address": "<string>",
    --       "email": "<email>",
    --       "phone_number": "<string>",
    --       "accounts": [
    --         {
    --           "value": "<Error: Too many levels of nesting to fake this schema>"
    --         },
    --         {
    --           "value": "<Error: Too many levels of nesting to fake this schema>"
    --         }
    --       ],
    --       "gig_data": {
    --         "collected_at": "<dateTime>",
    --         "status": "<string>",
    --         "acceptance_rate": "<number>"
    --       }
    --     }
    --   ]
    -- }

    -- 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)

    DECLARE @link nvarchar(4000)

    DECLARE @collected_at nvarchar(4000)

    DECLARE @display_name nvarchar(4000)

    DECLARE @first_name nvarchar(4000)

    DECLARE @last_name nvarchar(4000)

    DECLARE @second_last_name nvarchar(4000)

    DECLARE @address nvarchar(4000)

    DECLARE @email nvarchar(4000)

    DECLARE @phone_number nvarchar(4000)

    DECLARE @Collected_at nvarchar(4000)

    DECLARE @Status nvarchar(4000)

    DECLARE @Acceptance_rate nvarchar(4000)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @value nvarchar(4000)

    DECLARE @count nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @count OUT, 'count'
    DECLARE @v_next nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_next OUT, 'next'
    DECLARE @previous nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @previous OUT, 'previous'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'results'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'results[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @link OUT, 'results[i].link'
        EXEC sp_OAMethod @jResp, 'StringOf', @collected_at OUT, 'results[i].collected_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @display_name OUT, 'results[i].display_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @first_name OUT, 'results[i].first_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @last_name OUT, 'results[i].last_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @second_last_name OUT, 'results[i].second_last_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @address OUT, 'results[i].address'
        EXEC sp_OAMethod @jResp, 'StringOf', @email OUT, 'results[i].email'
        EXEC sp_OAMethod @jResp, 'StringOf', @phone_number OUT, 'results[i].phone_number'
        EXEC sp_OAMethod @jResp, 'StringOf', @Collected_at OUT, 'results[i].gig_data.collected_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @Status OUT, 'results[i].gig_data.status'
        EXEC sp_OAMethod @jResp, 'StringOf', @Acceptance_rate OUT, 'results[i].gig_data.acceptance_rate'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'results[i].accounts'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @value OUT, 'results[i].accounts[j].value'
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END

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


END
GO

Curl Command

curl -G -d "page=1"
	-u '{{secretId}}:{{secretPassword}}'
https://domain.com/api/owners/

Postman Collection Item JSON

{
  "name": "List",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/owners/?page=1",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "owners",
        ""
      ],
      "query": [
        {
          "key": "page",
          "value": "1",
          "description": "A page number within the paginated result set."
        }
      ]
    },
    "description": "Get a paginated list of all existing owners in your Belvo account. We return up to 100 results per page."
  },
  "response": [
    {
      "name": "Ok",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/owners?page=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "owners"
          ],
          "query": [
            {
              "key": "page",
              "value": "<integer>"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n\t\"count\": \"<integer>\",\n\t\"next\": \"<string>\",\n\t\"previous\": \"<string>\",\n\t\"results\": [\n\t\t{\n\t\t\t\"id\": \"<uuid>\",\n\t\t\t\"link\": \"<uuid>\",\n\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\"display_name\": \"<string>\",\n\t\t\t\"first_name\": \"<string>\",\n\t\t\t\"last_name\": \"<string>\",\n\t\t\t\"second_last_name\": \"<string>\",\n\t\t\t\"address\": \"<string>\",\n\t\t\t\"email\": \"<email>\",\n\t\t\t\"phone_number\": \"<string>\",\n\t\t\t\"accounts\": [\n\t\t\t\t{\n\t\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"gig_data\": {\n\t\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\t\"status\": \"<string>\",\n\t\t\t\t\"acceptance_rate\": \"<number>\"\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t\"id\": \"<uuid>\",\n\t\t\t\"link\": \"<uuid>\",\n\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\"display_name\": \"<string>\",\n\t\t\t\"first_name\": \"<string>\",\n\t\t\t\"last_name\": \"<string>\",\n\t\t\t\"second_last_name\": \"<string>\",\n\t\t\t\"address\": \"<string>\",\n\t\t\t\"email\": \"<email>\",\n\t\t\t\"phone_number\": \"<string>\",\n\t\t\t\"accounts\": [\n\t\t\t\t{\n\t\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"gig_data\": {\n\t\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\t\"status\": \"<string>\",\n\t\t\t\t\"acceptance_rate\": \"<number>\"\n\t\t\t}\n\t\t}\n\t]\n}"
    },
    {
      "name": "Unauthorized",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/owners?page=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "owners"
          ],
          "query": [
            {
              "key": "page",
              "value": "<integer>"
            }
          ]
        }
      },
      "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]"
    }
  ]
}