Chilkat Online Tools

DataFlex / Belvo API Docs / List

Back to Collection Items

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sDescription
    String sProduct_identification
    String sQuantity
    String sUnit_code
    String sUnit_description
    String sUnit_amount
    String sPre_tax_amount
    String sTax_percentage
    String sTax_amount
    String sTotal_amount
    String sCollected_at
    Integer j
    Integer iCount_j
    String sTax
    String sRetained_tax_amount
    String sCount
    String sV_next
    String sPrevious
    Integer i
    Integer iCount_i
    String sTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Set ComBasicAuth Of hoHttp To True
    Set ComLogin Of hoHttp To "{{secretId}}"
    Set ComPassword Of hoHttp To "{{secretPassword}}"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComQuickGetSb Of hoHttp "https://domain.com/api/invoices/" vSbResponseBody To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComLastStatus Of hoHttp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComLastHeader Of hoHttp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Procedure_Return
    End

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

    Get ComStringOf Of hoJResp "count" To sCount
    Get ComStringOf Of hoJResp "next" To sV_next
    Get ComStringOf Of hoJResp "previous" To sPrevious
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "results" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "results[i].description" To sDescription
        Get ComStringOf Of hoJResp "results[i].product_identification" To sProduct_identification
        Get ComStringOf Of hoJResp "results[i].quantity" To sQuantity
        Get ComStringOf Of hoJResp "results[i].unit_code" To sUnit_code
        Get ComStringOf Of hoJResp "results[i].unit_description" To sUnit_description
        Get ComStringOf Of hoJResp "results[i].unit_amount" To sUnit_amount
        Get ComStringOf Of hoJResp "results[i].pre_tax_amount" To sPre_tax_amount
        Get ComStringOf Of hoJResp "results[i].tax_percentage" To sTax_percentage
        Get ComStringOf Of hoJResp "results[i].tax_amount" To sTax_amount
        Get ComStringOf Of hoJResp "results[i].total_amount" To sTotal_amount
        Get ComStringOf Of hoJResp "results[i].collected_at" To sCollected_at
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "results[i].retained_taxes" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "results[i].retained_taxes[j].collected_at" To sCollected_at
            Get ComStringOf Of hoJResp "results[i].retained_taxes[j].tax" To sTax
            Get ComStringOf Of hoJResp "results[i].retained_taxes[j].tax_percentage" To sTax_percentage
            Get ComStringOf Of hoJResp "results[i].retained_taxes[j].retained_tax_amount" To sRetained_tax_amount
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop



End_Procedure

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