## Prefeitura / MS / Calculadora de Fretes
Calcula o valor de frete com base na Pauta de frete definida pelo estado do Mato Grosso do Sul


### Site URL
- https://servicos.efazenda.ms.gov.br/calculafrete

### Request
POST endpoint: `https://api.infosimples.com/api/v2/consultas/pref/ms/calculadora-frete`



| Parameter        | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| token*           | The token that will authenticate and authorize the request.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| tipo_transporte* | Informe o número do tipo de transporte
        <ul>
          <li><strong>1</strong> AGRICULTURA</li>
          <li><strong>2</strong> PECUÁRIA</li>
          <li><strong>3</strong> EXTRATIVISMO M3</li>
          <li><strong>4</strong> EXTRATIVISMO MST</li>
          <li><strong>5</strong> REFRIGERADOS</li>
          <li><strong>6</strong> OUTRAS</li>
          <li><strong>7</strong> FRETAMENTO/TURISMO</li>
          <li><strong>8</strong> FRETAMENTO IDA</li>
          <li><strong>9</strong> FRETAMENTO IDA E VOLTA</li>
        </ul> |
| tipo_prestacao** | Informe o número do tipo de prestação
        <ul>
          <li><strong>1</strong> INTERNA</li>
          <li><strong>2</strong> INTERESTADUAL</li>
          <li><strong>3</strong> IMPORTAÇÃO</li>
          <li><strong>4</strong> EXPORTAÇÃO</li>
        </ul>                                                                                                                                                                                                                                                                                       |
| data_prestacao*  | Informe a data do transporte em formato de acordo com a ISO8601                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| quantidade**     | Informe apenas o valor numérico da quantidade a ser transportada (Peso em toneladas ou Volume).                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| distancia*       | Informe a distância que será percorrida em quilômetros (Km).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |

> * 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.22-20241106184556",
    "product": "Consultas",
    "service": "pref/ms/calculadora-frete",
    "parameters": {
      "data_prestacao": "11/11/1111",
      "distancia": "4500",
      "quantidade": "50,0",
      "tipo_prestacao": "4",
      "tipo_transporte": "3"
    },
    "client_name": "Minha Empresa",
    "token_name": "Token de Produção",
    "billable": true,
    "price": "0.2",
    "requested_at": "2024-11-07T15:34:06.000-03:00",
    "elapsed_time_in_milliseconds": 471,
    "remote_ip": "111.111.111.111",
    "signature": "U2FsdGVkX1/DOASvrP2N72dzbU0Ttq1Emo1RgpQI5roelmZUxF0qlFYO+Rg0aEQaR/8CJbpkZhiViJuva6ExeA=="
  },
  "data_count": 1,
  "data": [
    {
      "frete_minimo": "R$ 29.945,78",
      "frete_minimo_normalizado": 29945.78,
      "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

url = 'https://api.infosimples.com/api/v2/consultas/pref/ms/calculadora-frete'
args = {
  "tipo_transporte": "VALUE_OF_PARAMETER_TIPO_TRANSPORTE",
  "tipo_prestacao":  "VALUE_OF_PARAMETER_TIPO_PRESTACAO",
  "data_prestacao":  "VALUE_OF_PARAMETER_DATA_PRESTACAO",
  "quantidade":      "VALUE_OF_PARAMETER_QUANTIDADE",
  "distancia":       "VALUE_OF_PARAMETER_DISTANCIA",
  "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.
