## Receita Federal / PGFN (CND Federal) - Segunda Via
Emite a segunda via de uma Certidão de Débitos Relativos a Créditos Tributários Federais e à Dívida Ativa da União a partir do número de CNPJ ou CPF. Quando uma Pessoa (Física ou Jurídica) possui certidão Positiva com efeitos de negativa, o portal da PGFN não é capaz de emitir uma nova certidão. Para você recuperar uma certidão válida dessa Pessoa, você pode localizar uma certidão emitida anteriormente e que continua válida através desta API.


### Sites URLs
- https://solucoes.receita.fazenda.gov.br/Servicos/CertidaoInternet/PJ/Consultar/
- https://solucoes.receita.fazenda.gov.br/Servicos/CertidaoInternet/PF/Consultar/

### Request
POST endpoint: `https://api.infosimples.com/api/v2/consultas/receita-federal/pgfn/2via`



| Parameter   | Description                                                                                                                                                                                                                                                              |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| token*      | The token that will authenticate and authorize the request.                                                                                                                                                                                                              |
| cnpj**      | CNPJ of the company to be queried.                                                                                                                                                                                                                                       |
| cpf**       | CPF of the individual to be queried.                                                                                                                                                                                                                                     |
| birthdate** | Data de nascimento no formato ISO 8601. Por exemplo, 22 de Abril de 1985 é representado em ISO 8601 da forma '1985-04-22'. Preste atenção que é necessário incluir zeros, o formato '1985-4-22' seria inválido. Obrigatório caso a consulta seja feita através de um CPF |

> * 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": "receita-federal/pgfn/2via",
    "parameters": {
      "cnpj": "11111111111111"
    },
    "client_name": "Minha Empresa",
    "token_name": "Token de Produção",
    "billable": true,
    "price": "0.24",
    "requested_at": "2021-05-31T12:54:22.000-03:00",
    "elapsed_time_in_milliseconds": 380,
    "remote_ip": "111.111.111.111",
    "signature": "U2FsdGVkX19GSD5Yb6wbCG4R/77wZbDkLZ2ATK/tJT/bizpQ8Y68UdAwoo1zdfIoQXCwd3YkiG/Apy7f18QD5A=="
  },
  "data_count": 1,
  "data": [
    {
      "certidao": "CERTIDÃO POSITIVA COM EFEITOS DE NEGATIVA DE DÉBITOS RELATIVOS AOS TRIBUTOS FEDERAIS E À DÍVIDA ATIVA DA UNIÃO",
      "certidao_codigo": "AA11.1111.1111.A111",
      "cnpj": "11.111.111/1111-11",
      "cnpj_situacao": "Válida",
      "comprovante_tipo": "pdf",
      "conseguiu_emitir_certidao_negativa": true,
      "consulta_comprovante": "AA11.1111.1111.A111",
      "consulta_datahora": "11/11/1111 11:11:11",
      "cpf": "",
      "debitos_pgfn": false,
      "debitos_rfb": true,
      "descricao": "Exemplo de texto",
      "emissao_data": "11/11/1111",
      "mensagem": "CERTIDÃO POSITIVA COM EFEITOS DE NEGATIVA DE DÉBITOS RELATIVOS AOS TRIBUTOS FEDERAIS E À DÍVIDA ATIVA DA UNIÃO",
      "nome": "Nome de Exemplo",
      "normalizado_cnpj": "11111111111111",
      "normalizado_consulta_datahora": "11/11/1111 11:11:11",
      "normalizado_cpf": "",
      "observacoes": "Exemplo de texto",
      "razao_social": "Empresa XYZ",
      "situacao": "Válida",
      "tipo": "Positiva com efeitos de negativa",
      "validade": "11/11/1111",
      "validade_data": "11/11/1111",
      "validade_prorrogada": "11/11/1111",
      "site_receipt": null
    }
  ],
  "site_receipts": []
}
```


### 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/receita-federal/pgfn/2via'
args = {
  "cnpj":      "VALUE_OF_PARAMETER_CNPJ",
  "cpf":       "VALUE_OF_PARAMETER_CPF",
  "birthdate": "VALUE_OF_PARAMETER_BIRTHDATE",
  "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.
