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

Dart
import 'package:chilkat/chilkat.dart';

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

  final http = CkHttp();

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

  final cert = CkCert();
  try {
    cert.loadFromFile('<nome arquivo certificado>.crt');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final bdPrivKey = CkBinData();
  try {
    bdPrivKey.loadFile('<nome arquivo chave privada>.key');
  } on ChilkatException {
    print('Failed to load key');
    return;
  }

  // Note: If your private key file requires a password, then set it here.
  // Otherwise pass the empty string.
  final privKeyPassword = '';
  final privKey = CkPrivateKey();
  try {
    privKey.loadAnyFormat(bdPrivKey, privKeyPassword);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  try {
    cert.setPrivateKey(privKey);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  http.setSslClientCert(cert);

  final queryParams = CkJsonObject();
  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';

  final resp = CkHttpResponse();
  try {
    http.httpParams('GET', 'https://cdpj.partners.bancointer.com.br/cobranca/v2/boletos', queryParams, resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final sbResponseBody = CkStringBuilder();
  resp.getBodySb(sbResponseBody);

  final jResp = CkJsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  print('Response Body:');
  print(jResp.emit());

  final respStatusCode = resp.statusCode;
  print('Response Status Code = $respStatusCode');
  if (respStatusCode >= 400) {
    print('Response Header:');
    print(resp.header);
    print('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

  var nomeBeneficiario = '';
  var cnpjCpfBeneficiario = '';

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