Chilkat Online Tools

PowerBuilder / Belvo API Docs / List

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Description
string ls_Product_identification
string ls_Quantity
string ls_Unit_code
string ls_Unit_description
string ls_Unit_amount
string ls_Pre_tax_amount
string ls_Tax_percentage
string ls_Tax_amount
string ls_Total_amount
string ls_Collected_at
integer j
integer li_Count_j
string ls_Tax
string ls_Retained_tax_amount
string ls_Count
string ls_V_next
string ls_Previous
integer i
integer li_Count_i

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Http.BasicAuth = 1
loo_Http.Login = "{{secretId}}"
loo_Http.Password = "{{secretPassword}}"

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://domain.com/api/invoices/",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

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

ls_Count = loo_JResp.StringOf("count")
ls_V_next = loo_JResp.StringOf("next")
ls_Previous = loo_JResp.StringOf("previous")
i = 0
li_Count_i = loo_JResp.SizeOfArray("results")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Description = loo_JResp.StringOf("results[i].description")
    ls_Product_identification = loo_JResp.StringOf("results[i].product_identification")
    ls_Quantity = loo_JResp.StringOf("results[i].quantity")
    ls_Unit_code = loo_JResp.StringOf("results[i].unit_code")
    ls_Unit_description = loo_JResp.StringOf("results[i].unit_description")
    ls_Unit_amount = loo_JResp.StringOf("results[i].unit_amount")
    ls_Pre_tax_amount = loo_JResp.StringOf("results[i].pre_tax_amount")
    ls_Tax_percentage = loo_JResp.StringOf("results[i].tax_percentage")
    ls_Tax_amount = loo_JResp.StringOf("results[i].tax_amount")
    ls_Total_amount = loo_JResp.StringOf("results[i].total_amount")
    ls_Collected_at = loo_JResp.StringOf("results[i].collected_at")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("results[i].retained_taxes")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_Collected_at = loo_JResp.StringOf("results[i].retained_taxes[j].collected_at")
        ls_Tax = loo_JResp.StringOf("results[i].retained_taxes[j].tax")
        ls_Tax_percentage = loo_JResp.StringOf("results[i].retained_taxes[j].tax_percentage")
        ls_Retained_tax_amount = loo_JResp.StringOf("results[i].retained_taxes[j].retained_tax_amount")
        j = j + 1
    loop
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp

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