Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

Banco Inter Obtendo uma lista de boletos

See more Banco Inter Examples

Get a list of tickets that match the search criteria.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.BinData;
import com.chilkatsoft.chilkat2.Cert;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.PrivateKey;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example assumes the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Http http = new Http();

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

        Cert cert = new Cert();
        try {
            cert.loadFromFile("<nome arquivo certificado>.crt");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        BinData bdPrivKey = new BinData();
        try {
            bdPrivKey.loadFile("<nome arquivo chave privada>.key");
        } catch (ChilkatException e) {
            System.out.println("Failed to load key");
            return;
        }

        // Note: If your private key file requires a password, then set it here.
        // Otherwise pass the empty string.
        String privKeyPassword = "";
        PrivateKey privKey = new PrivateKey();
        try {
            privKey.loadAnyFormat(bdPrivKey, privKeyPassword);

            cert.setPrivateKey(privKey);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        http.setSslClientCert(cert);

        JsonObject queryParams = new JsonObject();
        queryParams.updateString("dataInicial", "2022-04-01");
        queryParams.updateString("dataFinal", "2022-04-03");
        queryParams.updateString("situacao", "VENCIDO");
        queryParams.updateString("tipoOrdenacao", "ASC");
        queryParams.updateInt("itensPorPagina", 10);
        queryParams.updateInt("paginaAtual", 2);

        // Adds the "Authorization: Bearer $TOKEN" header.
        http.setAuthToken("$TOKEN");

        HttpResponse resp = new HttpResponse();
        try {
            http.httpParams("GET", "https://cdpj.partners.bancointer.com.br/cobranca/v2/boletos", queryParams, resp);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        StringBuilder sbResponseBody = new StringBuilder();
        resp.getBodySb(sbResponseBody);

        JsonObject jResp = new JsonObject();
        jResp.loadSb(sbResponseBody);
        jResp.setEmitCompact(false);

        System.out.println("Response Body:");
        System.out.println(jResp.emit());

        int respStatusCode = resp.getStatusCode();
        System.out.println("Response Status Code = " + respStatusCode);
        if (respStatusCode >= 400) {
            System.out.println("Response Header:");
            System.out.println(resp.getHeader());
            System.out.println("Failed.");
            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

        String nomeBeneficiario = "";
        String cnpjCpfBeneficiario = "";

        int totalPages = jResp.intOf("totalPages");
        int totalElements = jResp.intOf("totalElements");
        boolean last = jResp.boolOf("last");
        boolean first = jResp.boolOf("first");
        int size = jResp.intOf("size");
        int numberOfElements = jResp.intOf("numberOfElements");
        int i = 0;
        int count_i = jResp.sizeOfArray("content");
        while (i < count_i) {
            jResp.setI(i);
            nomeBeneficiario = jResp.stringOf("content[i].nomeBeneficiario");
            cnpjCpfBeneficiario = jResp.stringOf("content[i].cnpjCpfBeneficiario");
            i = i + 1;
        }
    }
}