## SENATRAN / Infrações
Retorna as infrações de um veículo na posse de um usuário do SENATRAN/gov.br, em um intervalo de 12 meses, presente em até 3 anos através da placa e renavam informados.


### Site URL
- https://portalservicos.senatran.serpro.gov.br/#/veiculos/meus-veiculos

### Request
POST endpoint: `https://api.infosimples.com/api/v2/consultas/senatran/infracoes`



| Parameter     | Description                                                                                                                                                                                                                                                                |
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| token*        | The token that will authenticate and authorize the request.                                                                                                                                                                                                                |
| placa*        | License plate of the vehicle to be queried.                                                                                                                                                                                                                                |
| cnpj**        | CNPJ of the company to be queried.                                                                                                                                                                                                                                         |
| login_cpf**   | Deve ser informado o CPF para fazer login no GOV.BR.                                                                                                                                                                                                                       |
| login_senha** | Deve ser informada a senha para fazer login no GOV.BR.                                                                                                                                                                                                                     |
| pkcs12_cert** | Este parâmetro é necessário caso o login no GOV.BR seja feito com certificado digital. Conteúdo do arquivo do certificado digital A1 encriptado seguindo <a href="https://api.infosimples.com/consultas/docs/certificados#criptografia">as instruções de criptografia</a>. |
| pkcs12_pass** | Este parâmetro é necessário caso o login no GOV.BR seja feito com certificado digital. Senha do certificado digital A1 encriptada seguindo <a href="https://api.infosimples.com/consultas/docs/certificados#criptografia">as instruções de criptografia</a>.               |
| data_inicio** | Start date in ISO 8601 format. For example, April 22, 1985 is represented as "1985-04-22". Make sure to include leading zeros; the format "1985-4-22" is invalid.                                                                                                          |
| data_fim**    | End date in ISO 8601 format. For example, April 22, 1985 is represented as "1985-04-22". Make sure to include leading zeros; the format "1985-4-22" is invalid.                                                                                                            |

> * 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",
    "api_version_full": "2.2.16-20240208134313",
    "product": "Consultas",
    "service": "senatran/infracoes",
    "parameters": {
      "cnpj": "12.345.678/9012-34",
      "pkcs12_cert_md5": "aa25eae9298a43740f9a763477c20a1f",
      "pkcs12_pass_md5": "c9c59c5246576b81c3f2712100204dec",
      "placa": "AAA1111"
    },
    "client_name": "Minha Empresa",
    "token_name": "Token de Produção",
    "billable": true,
    "price": "0.32",
    "requested_at": "2024-02-15T13:21:02.000-03:00",
    "elapsed_time_in_milliseconds": 738,
    "remote_ip": "111.111.111.111",
    "signature": "U2FsdGVkX1+13TxMmHjVg8ixvGNtJ9kF/OCH3ukrceLv6OUPjs7KffFqW/S41EmRl+kPc2CKoIhXNmhveRvrmg=="
  },
  "data_count": 1,
  "data": [
    {
      "infracoes": [
        {
          "placa": "AAA1111",
          "codigo_orgao_autuador": "000300",
          "auto_infracao": "ABC1111111",
          "codigo_infracao": "7455",
          "descricao": "Exemplo de descrição",
          "valor_total": 130.16,
          "data_vencimento": "11/11/1111",
          "chave_infracao": "000300S0111111111111",
          "situacao": "NAO_PAGAS_A_VENCER"
        },
        {
          "placa": "AAA1111",
          "codigo_orgao_autuador": "000300",
          "auto_infracao": "ABC1111111",
          "codigo_infracao": "5002",
          "descricao": "Exemplo de descrição",
          "valor_total": 260.32,
          "data_vencimento": "11/11/1111",
          "chave_infracao": "000300S0111111111111",
          "situacao": "NAO_PAGAS_VENCIDAS"
        },
        {
          "placa": "AAA1111",
          "codigo_orgao_autuador": "000300",
          "auto_infracao": "ABC1111111",
          "codigo_infracao": "7463",
          "descricao": "Exemplo de descrição",
          "valor_total": 195.23,
          "data_vencimento": "11/11/1111",
          "chave_infracao": "000300S0111111111111",
          "situacao": "NAO_PAGAS_A_VENCER"
        },
        {
          "placa": "AAA1111",
          "codigo_orgao_autuador": "000300",
          "auto_infracao": "ABC1111111",
          "codigo_infracao": "7455",
          "descricao": "Exemplo de descrição",
          "valor_total": 130.16,
          "data_vencimento": "11/11/1111",
          "chave_infracao": "000300S0111111111111",
          "situacao": "NAO_PAGAS_VENCIDAS"
        }
      ],
      "total_infracoes": 4,
      "site_receipt": "https://www.exemplo.com/exemplo-de-url"
    }
  ],
  "site_receipts": [
    "https://www.exemplo.com/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/senatran/infracoes'
args = {
  "placa":       "VALUE_OF_PARAMETER_PLACA",
  "cnpj":        "VALUE_OF_PARAMETER_CNPJ",
  "login_cpf":   "VALUE_OF_PARAMETER_LOGIN_CPF",
  "login_senha": "VALUE_OF_PARAMETER_LOGIN_SENHA",
  "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("="),
  "data_inicio": "VALUE_OF_PARAMETER_DATA_INICIO",
  "data_fim":    "VALUE_OF_PARAMETER_DATA_FIM",
  "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.
