Zig Requires Chilkat v11.0.0+
Zig
Banco Inter Obtendo uma lista de boletos
See more Banco Inter Examples
Get a list of tickets that match the search criteria.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// Implements the following CURL command:
// curl \
// -X GET \
// -H "Authorization: Bearer $TOKEN" \
// --cert <nome arquivo certificado>.crt \
// --key <nome arquivo chave privada>.key \
// --get \
// --data-urlencode "dataInicial=2022-04-01" \
// --data-urlencode "dataFinal=2022-04-03" \
// --data-urlencode "situacao=VENCIDO" \
// --data-urlencode "tipoOrdenacao=ASC" \
// --data-urlencode "itensPorPagina=10" \
// --data-urlencode "paginaAtual=2" \
// https://cdpj.partners.bancointer.com.br/cobranca/v2/boletos
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
const cert = try chilkat.Cert.init();
defer cert.deinit();
cert.loadFromFile("<nome arquivo certificado>.crt") catch {
std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
return;
};
const bd_priv_key = try chilkat.BinData.init();
defer bd_priv_key.deinit();
bd_priv_key.loadFile("<nome arquivo chave privada>.key") catch {
std.debug.print("Failed to load key\n", .{});
return;
};
// Note: If your private key file requires a password, then set it here.
// Otherwise pass the empty string.
const priv_key_password = "";
const priv_key = try chilkat.PrivateKey.init();
defer priv_key.deinit();
priv_key.loadAnyFormat(bd_priv_key, priv_key_password) catch {
std.debug.print("{s}\n", .{try priv_key.getLastErrorText(alloc)});
return;
};
cert.setPrivateKey(priv_key) catch {
std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
return;
};
http.setSslClientCert(cert) catch {};
const query_params = try chilkat.JsonObject.init();
defer query_params.deinit();
query_params.updateString("dataInicial", "2022-04-01") catch {};
query_params.updateString("dataFinal", "2022-04-03") catch {};
query_params.updateString("situacao", "VENCIDO") catch {};
query_params.updateString("tipoOrdenacao", "ASC") catch {};
query_params.updateInt("itensPorPagina", 10) catch {};
query_params.updateInt("paginaAtual", 2) catch {};
// Adds the "Authorization: Bearer $TOKEN" header.
http.setAuthToken("$TOKEN");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpParams("GET", "https://cdpj.partners.bancointer.com.br/cobranca/v2/boletos", query_params, resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
resp.getBodySb(sb_response_body) catch {};
const j_resp = try chilkat.JsonObject.init();
defer j_resp.deinit();
j_resp.loadSb(sb_response_body) catch {};
j_resp.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try j_resp.emit(alloc)});
const resp_status_code = resp.getStatusCode();
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
if (resp_status_code >= 400) {
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
std.debug.print("Failed.\n", .{});
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "totalPages": 1,
// "totalElements": 58,
// "last": true,
// "first": true,
// "size": 100,
// "numberOfElements": 58,
// "content": [
// {
// "nomeBeneficiario": "nome do beneficiario 1",
// "cnpjCpfBeneficiario": "CNPJ/CPF beneficiario 1"
// },
// {
// "nomeBeneficiario": "nome do beneficiario 2",
// "cnpjCpfBeneficiario": "CNPJ/CPF beneficiario 2"
// },
// {
// "nomeBeneficiario": "nome do beneficiario N",
// "cnpjCpfBeneficiario": "CNPJ/CPF beneficiario N"
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
var nome_beneficiario: [:0]const u8 = "";
var cnpj_cpf_beneficiario: [:0]const u8 = "";
_ = j_resp.intOf("totalPages");
_ = j_resp.intOf("totalElements");
_ = j_resp.boolOf("last");
_ = j_resp.boolOf("first");
_ = j_resp.intOf("size");
_ = j_resp.intOf("numberOfElements");
var i: i32 = 0;
const count_i = j_resp.sizeOfArray("content");
while (i < count_i) {
j_resp.setI(i);
nome_beneficiario = try j_resp.stringOf(alloc, "content[i].nomeBeneficiario");
cnpj_cpf_beneficiario = try j_resp.stringOf(alloc, "content[i].cnpjCpfBeneficiario");
i = i + 1;
}
}