Chilkat Online Tools

PureBasic / Belvo API Docs / List

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    CkHttp::setCkBasicAuth(http, 1)
    CkHttp::setCkLogin(http, "{{secretId}}")
    CkHttp::setCkPassword(http, "{{secretPassword}}")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckQuickGetSb(http,"https://domain.com/api/invoices/",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

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

    ; {
    ;   "count": "<integer>",
    ;   "next": "<string>",
    ;   "previous": "<string>",
    ;   "results": [
    ;     {
    ;       "description": "<string>",
    ;       "product_identification": "<string>",
    ;       "quantity": "<integer>",
    ;       "unit_code": "<string>",
    ;       "unit_description": "<string>",
    ;       "unit_amount": "<number>",
    ;       "pre_tax_amount": "<number>",
    ;       "tax_percentage": "<number>",
    ;       "tax_amount": "<number>",
    ;       "total_amount": "<number>",
    ;       "retained_taxes": [
    ;         {
    ;           "collected_at": "<dateTime>",
    ;           "tax": "<string>",
    ;           "tax_percentage": "<number>",
    ;           "retained_tax_amount": "<number>"
    ;         },
    ;         {
    ;           "collected_at": "<dateTime>",
    ;           "tax": "<string>",
    ;           "tax_percentage": "<number>",
    ;           "retained_tax_amount": "<number>"
    ;         }
    ;       ],
    ;       "collected_at": "<dateTime>"
    ;     },
    ;     {
    ;       "description": "<string>",
    ;       "product_identification": "<string>",
    ;       "quantity": "<integer>",
    ;       "unit_code": "<string>",
    ;       "unit_description": "<string>",
    ;       "unit_amount": "<number>",
    ;       "pre_tax_amount": "<number>",
    ;       "tax_percentage": "<number>",
    ;       "tax_amount": "<number>",
    ;       "total_amount": "<number>",
    ;       "retained_taxes": [
    ;         {
    ;           "collected_at": "<dateTime>",
    ;           "tax": "<string>",
    ;           "tax_percentage": "<number>",
    ;           "retained_tax_amount": "<number>"
    ;         },
    ;         {
    ;           "collected_at": "<dateTime>",
    ;           "tax": "<string>",
    ;           "tax_percentage": "<number>",
    ;           "retained_tax_amount": "<number>"
    ;         }
    ;       ],
    ;       "collected_at": "<dateTime>"
    ;     }
    ;   ]
    ; }

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

    description.s
    product_identification.s
    quantity.s
    unit_code.s
    unit_description.s
    unit_amount.s
    pre_tax_amount.s
    tax_percentage.s
    tax_amount.s
    total_amount.s
    collected_at.s
    j.i
    count_j.i
    tax.s
    retained_tax_amount.s

    count.s = CkJsonObject::ckStringOf(jResp,"count")
    v_next.s = CkJsonObject::ckStringOf(jResp,"next")
    previous.s = CkJsonObject::ckStringOf(jResp,"previous")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"results")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        description = CkJsonObject::ckStringOf(jResp,"results[i].description")
        product_identification = CkJsonObject::ckStringOf(jResp,"results[i].product_identification")
        quantity = CkJsonObject::ckStringOf(jResp,"results[i].quantity")
        unit_code = CkJsonObject::ckStringOf(jResp,"results[i].unit_code")
        unit_description = CkJsonObject::ckStringOf(jResp,"results[i].unit_description")
        unit_amount = CkJsonObject::ckStringOf(jResp,"results[i].unit_amount")
        pre_tax_amount = CkJsonObject::ckStringOf(jResp,"results[i].pre_tax_amount")
        tax_percentage = CkJsonObject::ckStringOf(jResp,"results[i].tax_percentage")
        tax_amount = CkJsonObject::ckStringOf(jResp,"results[i].tax_amount")
        total_amount = CkJsonObject::ckStringOf(jResp,"results[i].total_amount")
        collected_at = CkJsonObject::ckStringOf(jResp,"results[i].collected_at")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"results[i].retained_taxes")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            collected_at = CkJsonObject::ckStringOf(jResp,"results[i].retained_taxes[j].collected_at")
            tax = CkJsonObject::ckStringOf(jResp,"results[i].retained_taxes[j].tax")
            tax_percentage = CkJsonObject::ckStringOf(jResp,"results[i].retained_taxes[j].tax_percentage")
            retained_tax_amount = CkJsonObject::ckStringOf(jResp,"results[i].retained_taxes[j].retained_tax_amount")
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl -X GET
	-u '{{secretId}}:{{secretPassword}}'
https://domain.com/api/invoices/

Postman Collection Item JSON

{
  "name": "List",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/invoices/",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "invoices",
        ""
      ],
      "query": [
        {
          "key": "page",
          "value": "1",
          "description": "A page number within the paginated result set.",
          "disabled": true
        }
      ]
    },
    "description": "Get a paginated list of all existing invoices 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/invoices?page=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "invoices"
          ],
          "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\"description\": \"<string>\",\n\t\t\t\"product_identification\": \"<string>\",\n\t\t\t\"quantity\": \"<integer>\",\n\t\t\t\"unit_code\": \"<string>\",\n\t\t\t\"unit_description\": \"<string>\",\n\t\t\t\"unit_amount\": \"<number>\",\n\t\t\t\"pre_tax_amount\": \"<number>\",\n\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\"tax_amount\": \"<number>\",\n\t\t\t\"total_amount\": \"<number>\",\n\t\t\t\"retained_taxes\": [\n\t\t\t\t{\n\t\t\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\t\t\"tax\": \"<string>\",\n\t\t\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\t\t\"retained_tax_amount\": \"<number>\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\t\t\"tax\": \"<string>\",\n\t\t\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\t\t\"retained_tax_amount\": \"<number>\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"collected_at\": \"<dateTime>\"\n\t\t},\n\t\t{\n\t\t\t\"description\": \"<string>\",\n\t\t\t\"product_identification\": \"<string>\",\n\t\t\t\"quantity\": \"<integer>\",\n\t\t\t\"unit_code\": \"<string>\",\n\t\t\t\"unit_description\": \"<string>\",\n\t\t\t\"unit_amount\": \"<number>\",\n\t\t\t\"pre_tax_amount\": \"<number>\",\n\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\"tax_amount\": \"<number>\",\n\t\t\t\"total_amount\": \"<number>\",\n\t\t\t\"retained_taxes\": [\n\t\t\t\t{\n\t\t\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\t\t\"tax\": \"<string>\",\n\t\t\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\t\t\"retained_tax_amount\": \"<number>\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"collected_at\": \"<dateTime>\",\n\t\t\t\t\t\"tax\": \"<string>\",\n\t\t\t\t\t\"tax_percentage\": \"<number>\",\n\t\t\t\t\t\"retained_tax_amount\": \"<number>\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"collected_at\": \"<dateTime>\"\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/invoices?page=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "invoices"
          ],
          "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]"
    }
  ]
}