Sample code for 30+ languages & platforms
React Native 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 React Native Downloads

React Native
import { BinData, Cert, Http, HttpResponse, JsonObject, PrivateKey, StringBuilder } from '@chilkat/react-native'

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

  const 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

  const cert = new Cert();
  try {
    cert.loadFromFile('<nome arquivo certificado>.crt');
  } catch {
    console.log(cert.lastErrorText);
    return;
  }

  const bdPrivKey = new BinData();
  try {
    bdPrivKey.loadFile('<nome arquivo chave privada>.key');
  } catch {
    console.log('Failed to load key');
    return;
  }

  // Note: If your private key file requires a password, then set it here.
  // Otherwise pass the empty string.
  const privKeyPassword = '';
  const privKey = new PrivateKey();
  try {
    privKey.loadAnyFormat(bdPrivKey, privKeyPassword);
  } catch {
    console.log(privKey.lastErrorText);
    return;
  }

  try {
    cert.setPrivateKey(privKey);
  } catch {
    console.log(cert.lastErrorText);
    return;
  }

  http.setSslClientCert(cert);

  const 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.authToken = '$TOKEN';

  const resp = new HttpResponse();
  try {
    await http.httpParamsAsync('GET', 'https://cdpj.partners.bancointer.com.br/cobranca/v2/boletos', queryParams, resp);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

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

  const jResp = new JsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  console.log('Response Body:');
  console.log(jResp.emit());

  const respStatusCode = resp.statusCode;
  console.log(`Response Status Code = ${respStatusCode}`);
  if (respStatusCode >= 400) {
    console.log('Response Header:');
    console.log(resp.header);
    console.log('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

  let nomeBeneficiario = '';
  let cnpjCpfBeneficiario = '';

  const totalPages = jResp.intOf('totalPages');
  const totalElements = jResp.intOf('totalElements');
  const size = jResp.intOf('size');
  const numberOfElements = jResp.intOf('numberOfElements');
  let i = 0;
  const countI = jResp.sizeOfArray('content');
  while (i < countI) {
    jResp.i = i;
    nomeBeneficiario = jResp.stringOf('content[i].nomeBeneficiario');
    cnpjCpfBeneficiario = jResp.stringOf('content[i].cnpjCpfBeneficiario');
    i++;
  }
}