Lua Requires Chilkat v11.0.0+
Lua
Banco Inter Obtendo uma lista de boletos
See more Banco Inter Examples
Get a list of tickets that match the search criteria.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- 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
local cert = chilkat.Cert.new()
local success = cert:load_from_file("<nome arquivo certificado>.crt")
if not success then
print(cert.last_error_text)
return
end
local bdPrivKey = chilkat.BinData.new()
success = bdPrivKey:load_file("<nome arquivo chave privada>.key")
if not success then
print("Failed to load key")
return
end
-- Note: If your private key file requires a password, then set it here.
-- Otherwise pass the empty string.
local privKeyPassword = ""
local privKey = chilkat.PrivateKey.new()
success = privKey:load_any_format(bdPrivKey, privKeyPassword)
if not success then
print(privKey.last_error_text)
return
end
success = cert:set_private_key(privKey)
if not success then
print(cert.last_error_text)
return
end
http:set_ssl_client_cert(cert)
local queryParams = chilkat.JsonObject.new()
queryParams:update_string("dataInicial", "2022-04-01")
queryParams:update_string("dataFinal", "2022-04-03")
queryParams:update_string("situacao", "VENCIDO")
queryParams:update_string("tipoOrdenacao", "ASC")
queryParams:update_int("itensPorPagina", 10)
queryParams:update_int("paginaAtual", 2)
-- Adds the "Authorization: Bearer $TOKEN" header.
http.auth_token = "$TOKEN"
local resp = chilkat.HttpResponse.new()
success = http:http_params("GET", "https://cdpj.partners.bancointer.com.br/cobranca/v2/boletos", queryParams, resp)
if not success then
print(http.last_error_text)
return
end
local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(resp.header)
print("Failed.")
return
end
-- 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
local nomeBeneficiario = ""
local cnpjCpfBeneficiario = ""
local totalPages = jResp:int_of("totalPages")
local totalElements = jResp:int_of("totalElements")
local last = jResp:bool_of("last")
local first = jResp:bool_of("first")
local size = jResp:int_of("size")
local numberOfElements = jResp:int_of("numberOfElements")
local i = 0
local count_i = jResp:size_of_array("content")
while i < count_i do
jResp.i = i
nomeBeneficiario = jResp:string_of("content[i].nomeBeneficiario")
cnpjCpfBeneficiario = jResp:string_of("content[i].cnpjCpfBeneficiario")
i = i + 1
end