Chilkat Online Tools

C++ / Belvo API Docs / Retrieve

Back to Collection Items

#include <CkHttp.h>
#include <CkJsonObject.h>
#include <CkHttpResponse.h>
#include <CkStringBuilder.h>

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

    CkHttp http;
    bool success;

    http.put_BasicAuth(true);
    http.put_Login("{{secretId}}");
    http.put_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.

    // {
    //   "link": "d4617561-1c01-4b2f-83b6-a594f7b3bc57",
    //   "year_from": 2018,
    //   "year_to": 2019,
    //   "type": "yearly",
    //   "attach_pdf": false,
    //   "encryption_key": "customencryptionkey",
    //   "save_data": true
    // }

    CkJsonObject json;
    json.UpdateString("link","d4617561-1c01-4b2f-83b6-a594f7b3bc57");
    json.UpdateInt("year_from",2018);
    json.UpdateInt("year_to",2019);
    json.UpdateString("type","yearly");
    json.UpdateBool("attach_pdf",false);
    json.UpdateString("encryption_key","customencryptionkey");
    json.UpdateBool("save_data",true);

    http.SetRequestHeader("Content-Type","application/json");

    CkHttpResponse *resp = http.PostJson3("https://domain.com/api/tax-returns/","application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    CkStringBuilder sbResponseBody;
    resp->GetBodySb(sbResponseBody);

    CkJsonObject jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    std::cout << "Response Body:" << "\r\n";
    std::cout << jResp.emit() << "\r\n";

    int respStatusCode = resp->get_StatusCode();
    std::cout << "Response Status Code = " << respStatusCode << "\r\n";
    if (respStatusCode >= 400) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << resp->header() << "\r\n";
        std::cout << "Failed." << "\r\n";
        delete resp;
        return;
    }

    delete resp;

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

    // {
    //   "link": "<uuid>",
    //   "collected_at": "<dateTime>",
    //   "informacion_general": "<object>",
    //   "sueldos_salarios": "<object>",
    //   "servicios_profesionales": "<object>",
    //   "deducciones_personales": "<object>",
    //   "determinacion_impuesto": "<object>",
    //   "retenciones": "<object>",
    //   "dividendos": "<object>",
    //   "datos_informativos": "<object>",
    //   "pdf": "<binary>"
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    const char *link = jResp.stringOf("link");
    const char *collected_at = jResp.stringOf("collected_at");
    const char *informacion_general = jResp.stringOf("informacion_general");
    const char *sueldos_salarios = jResp.stringOf("sueldos_salarios");
    const char *servicios_profesionales = jResp.stringOf("servicios_profesionales");
    const char *deducciones_personales = jResp.stringOf("deducciones_personales");
    const char *determinacion_impuesto = jResp.stringOf("determinacion_impuesto");
    const char *retenciones = jResp.stringOf("retenciones");
    const char *dividendos = jResp.stringOf("dividendos");
    const char *datos_informativos = jResp.stringOf("datos_informativos");
    const char *pdf = jResp.stringOf("pdf");
    }

Curl Command

curl -X POST
	-u '{{secretId}}:{{secretPassword}}'
	-H "Content-Type: application/json"
	-d '{
    "link": "d4617561-1c01-4b2f-83b6-a594f7b3bc57",
    "year_from": 2018,
    "year_to": 2019,
    "type": "yearly", // Note: Check the documentation to the right for more information.
    "attach_pdf": false,
    "encryption_key": "customencryptionkey",
    "save_data": true
}'
https://domain.com/api/tax-returns/

Postman Collection Item JSON

{
  "name": "Retrieve",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"link\": \"d4617561-1c01-4b2f-83b6-a594f7b3bc57\",\n    \"year_from\": 2018,\n    \"year_to\": 2019,\n    \"type\": \"yearly\", // Note: Check the documentation to the right for more information.\n    \"attach_pdf\": false,\n    \"encryption_key\": \"customencryptionkey\",\n    \"save_data\": true\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/tax-returns/",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "tax-returns",
        ""
      ]
    },
    "description": "Retrieve tax return information for a specific fiscal link.\n\nFor more information on how to use the `type` parameter, please see the full [documentation for the Tax Returns endpoint](https://docs.belvo.com/#operation/RetrieveTaxReturns)."
  },
  "response": [
    {
      "name": "Ok (when save_data=false)",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n\t\"link\": \"<uuid>\",\n\t\"collected_at\": \"<dateTime>\",\n\t\"informacion_general\": \"<object>\",\n\t\"sueldos_salarios\": \"<object>\",\n\t\"servicios_profesionales\": \"<object>\",\n\t\"deducciones_personales\": \"<object>\",\n\t\"determinacion_impuesto\": \"<object>\",\n\t\"retenciones\": \"<object>\",\n\t\"dividendos\": \"<object>\",\n\t\"datos_informativos\": \"<object>\",\n\t\"pdf\": \"<binary>\"\n}"
    },
    {
      "name": "Created (when save_data=true)",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "[\n\t{\n\t\t\"id\": \"<uuid>\",\n\t\t\"link\": \"<uuid>\",\n\t\t\"collected_at\": \"<dateTime>\",\n\t\t\"informacion_general\": \"<object>\",\n\t\t\"sueldos_salarios\": \"<object>\",\n\t\t\"servicios_profesionales\": \"<object>\",\n\t\t\"deducciones_personales\": \"<object>\",\n\t\t\"determinacion_impuesto\": \"<object>\",\n\t\t\"retenciones\": \"<object>\",\n\t\t\"dividendos\": \"<object>\",\n\t\t\"datos_informativos\": \"<object>\",\n\t\t\"pdf\": \"<binary>\"\n\t},\n\t{\n\t\t\"id\": \"<uuid>\",\n\t\t\"link\": \"<uuid>\",\n\t\t\"collected_at\": \"<dateTime>\",\n\t\t\"informacion_general\": \"<object>\",\n\t\t\"sueldos_salarios\": \"<object>\",\n\t\t\"servicios_profesionales\": \"<object>\",\n\t\t\"deducciones_personales\": \"<object>\",\n\t\t\"determinacion_impuesto\": \"<object>\",\n\t\t\"retenciones\": \"<object>\",\n\t\t\"dividendos\": \"<object>\",\n\t\t\"datos_informativos\": \"<object>\",\n\t\t\"pdf\": \"<binary>\"\n\t}\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    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "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    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "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": "Request Timeout",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "status": "Request Timeout",
      "code": 408,
      "_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": "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    \"link\": \"<uuid>\",\n    \"year_from\": \"<number>\",\n    \"year_to\": \"<number>\",\n    \"attach_pdf\": false,\n    \"encryption_key\": \"<string>\",\n    \"save_data\": true\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/tax-returns",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "tax-returns"
          ]
        }
      },
      "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]"
    }
  ]
}