## ECAC / PER/DCOMP
Consulta a lista de PER/DCOMP (Pedido Eletrônico de Restituição, Ressarcimento ou Reembolso e Declaração de Compensação) no eCAC (Centro Virtual de Atendimento) da Receita Federal. Retorna os itens da primeira página de resultados.


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

### Request
POST endpoint: `https://api.infosimples.com/api/v2/consultas/ecac/perdcomp`



| 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.                                                 |
| perdcomp**               | Número do PERDCOMP. Informar este parâmetro para retornar os PERDCOMP relacionados                                                                                            |

> * 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/perdcomp",
    "parameters": {
      "perdcomp": "",
      "pkcs12_cert_md5": "aa15e1e9298a43740f9a763477d20a1f",
      "pkcs12_pass_md5": "29d5925246576b81c3f2712100204de7"
    },
    "client_name": "Minha Empresa",
    "token_name": "Token de Produção",
    "billable": true,
    "price": "0.26",
    "requested_at": "2021-05-18T15:47:17.000-03:00",
    "elapsed_time_in_milliseconds": 4280,
    "remote_ip": "111.111.111.111",
    "signature": "U2FsdGVkX18R2klmfkvZXhiQ5VMpHVyngIMC+4qZXW1qjz+BrWxyEgYJBrvAq6XSKqvzBnRxeiFKz9v93tgxsw=="
  },
  "data_count": 1,
  "data": [
    {
      "lista": [
        {
          "perdcomp": "1111.11111.11111.1.1.11-1111",
          "data_transmissao": "12/09/2011",
          "tipo_credito": "Pagamento Indevido ou a Maior",
          "tipo_documento": "Declaração de Compensação",
          "situacao": "Em análise",
          "relacionados":     []
        }
      ],
      "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 is **generated by the source (website/app)** that processed the automation.

### 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/perdcomp'
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",
  "perdcomp":               "VALUE_OF_PARAMETER_PERDCOMP",
  "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.
