## ECAC / Caixa Postal
Consulta as mensagens da Caixa Postal do Centro Virtual de Atendimento (eCAC) de interesse geral e de interesse específico, enviadas pela Receita Federal.


### Site URL
- https://cav.receita.fazenda.gov.br/ecac/Aplicacao.aspx?id=00006

### Request
POST endpoint: `https://api.infosimples.com/api/v2/consultas/ecac/caixa-postal`



| Parameter                        | Description                                                                                                                                                                   |
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| token*                           | The token that will authenticate and authorize the request.                                                                                                                   |
| pkcs12_cert*                     | Content of the encrypted A1 digital certificate file following <a href="http://api.infosimples.com/consultas/docs/certificados#criptografia">the encryption instructions</a>. |
| pkcs12_pass*                     | Password of the encrypted A1 digital certificate following <a href="http://api.infosimples.com/consultas/docs/certificados#criptografia">the encryption instructions</a>.     |
| perfil_procurador_cnpj**         | Caso deseje alterar o perfil de acesso no eCAC como procurador de uma pessoa jurídica, informe neste campo o CNPJ da empresa.                                                 |
| perfil_sucessora_sucedida_cnpj** | Caso deseje alterar o perfil de acesso no eCAC como sucessora atuando como sucedida, informe neste campo o CNPJ da empresa.                                                   |
| ignora_nao_lidas**               | Se for informado o valor 1, a API não abre as mensagens não lidas da caixa postal. Por padrão o valor é 0 e abre as mensagens não lidas.                                      |
| ignora_lidas**                   | Se for informado o valor 1, a API não abre apenas as mensagens lidas da caixa postal. Por padrão o valor é 0 e abre as mensagens lidas.                                       |

> * Required parameter.

> ** Optional parameter. Sometimes it is necessary to set at least one of the optional parameters for the service to work properly.


### Response examples (OK)
```json
{
  "code": 200,
  "code_message": "A requisição foi processada com sucesso.",
  "errors": [],
  "header": {
    "api_version": "v2",
    "service": "ecac/caixa-postal",
    "parameters": {
      "pkcs12_hash": "11A11AA1A11A1A1A1AAA11AA11AAA11A"
    },
    "client_name": "Minha Empresa",
    "token_name": "Token de Produção",
    "billable": true,
    "price": "0.26",
    "requested_at": "2018-10-15T17:14:01.000-03:00",
    "elapsed_time_in_milliseconds": 4,
    "remote_ip": "111.111.111.111",
    "signature": "U2FsdGVkX18TdNkWowftSusODhfh9J4ItWSimnHkjDt0iGKAxlw8te1FzG6QKgs7Yecz87Zx0OK6/KAN7kmoSg=="
  },
  "data_count": 1,
  "data": [
    {
      "lidas": 1,
      "mensagens": [
        {
          "relevante": true,
          "lida": true,
          "remetente": "RECEITA FEDERAL DO BRASIL",
          "assunto": "Exemplo de Assunto",
          "envio_data": "20/05/2023",
          "exibicao_data": "16/05/2024",
          "leitura_data": "26/06/2024",
          "cnpj_destinatario": "11.111.111/1111-11",
          "id_mensagem": "111111111",
          "conteudo_html": "<p>Prezado Contribuinte,</p>  <p>Comunicamos que o ...",
          "conteudo_texto": "Prezado Contribuinte, Comunicamos que o ..."
        }
      ],
      "nao_lidas": 1,
      "site_receipt": "https://api.infosimples.com/receipt/exemplo-de-url"
    }
  ],
  "site_receipts": [
    "https://api.infosimples.com/receipt/exemplo-de-url"
  ]
}
```


### Preview file

The preview file (`site_receipts`) in the response JSON may be **synthesized by Infosimples** using data from the source (website/app) that processed the automation if the file generated by the source is not suitable for viewing.

### Code snippets


#### Python
```python
# Tested with: Python 3.10.19, Python 3.14.0
import requests
import base64
# pip install aes-bridge
import aes_bridge

url = 'https://api.infosimples.com/api/v2/consultas/ecac/caixa-postal'
args = {
  "pkcs12_cert":                    aes_bridge.encrypt(base64.b64encode(open("certificate.pfx", "rb").read()).decode(), "ENCRYPTION_KEY").decode("ascii").replace("+", "-").replace("/", "_").rstrip("="),
  "pkcs12_pass":                    aes_bridge.encrypt("CERTIFICATE_PASSWORD", "ENCRYPTION_KEY").decode("ascii").replace("+", "-").replace("/", "_").rstrip("="),
  "perfil_procurador_cnpj":         "VALUE_OF_PARAMETER_PERFIL_PROCURADOR_CNPJ",
  "perfil_sucessora_sucedida_cnpj": "VALUE_OF_PARAMETER_PERFIL_SUCESSORA_SUCEDIDA_CNPJ",
  "ignora_nao_lidas":               "VALUE_OF_PARAMETER_IGNORA_NAO_LIDAS",
  "ignora_lidas":                   "VALUE_OF_PARAMETER_IGNORA_LIDAS",
  "token":                          "WRITE_YOUR_TOKEN_HERE",
  "timeout":                        "300"
}

response = requests.post(url, args)
response_json = response.json()
response.close()

if response_json['code'] == 200:
  print("Retorno com sucesso: ", response_json['data'])
elif response_json['code'] in range(600, 799):
  mensagem = "Resultado sem sucesso. Leia para saber mais: \n"
  mensagem += "Código: {} ({})\n".format(response_json['code'], response_json['code_message'])
  mensagem += "; ".join(response_json['errors'])
  print(mensagem)

print("Cabeçalho da consulta: ", response_json['header'])
print("URLs com arquivos de visualização (HTML/PDF): ", response_json['site_receipts'])
```


## We are here to help
Do you still need to figure something out? Reach us at [suporte@infosimples.com.br](mailto:suporte@infosimples.com.br) and our highly qualified support team will be happy to help.
