### Make CPF Consulta API Request using cURL Source: https://apicenter.estaleiro.serpro.gov.br/documentacao/consulta-cpf/pt/quick_start This snippet demonstrates how to make a GET request to the CPF Trial API to retrieve CPF information. It requires an Authorization token and specifies the Accept header for JSON responses. The base URL and endpoint are provided, along with an example of the expected JSON response. ```shell curl -X GET "https://gateway.apiserpro.serpro.gov.br/consulta-cpf-df-trial/v1/cpf/40442820135" \ -H "accept: application/json" \ -H "Authorization: Bearer 4e1a1858bdd584fdc077fb7d80f39283" \ ``` -------------------------------- ### GET /consulta-cpf-df-trial/v1/cpf/{cpf} Source: https://apicenter.estaleiro.serpro.gov.br/documentacao/consulta-cpf/pt/quick_start This endpoint allows you to query CPF information using a trial version of the API. Ensure you have a valid Bearer token for authorization. ```APIDOC ## GET /consulta-cpf-df-trial/v1/cpf/{cpf} ### Description Queries CPF information using the trial API endpoint. This is a demonstration environment with sample data. ### Method GET ### Endpoint https://gateway.apiserpro.serpro.gov.br/consulta-cpf-df-trial/v1/cpf/{cpf} ### Parameters #### Path Parameters - **cpf** (string) - Required - The CPF number to query (e.g., "40442820135"). #### Query Parameters None #### Request Body None ### Request Example ```curl curl -X GET "https://gateway.apiserpro.serpro.gov.br/consulta-cpf-df-trial/v1/cpf/40442820135" \ -H "accept: application/json" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" ``` ### Response #### Success Response (200) - **ni** (string) - The CPF number. - **nome** (string) - The name associated with the CPF. - **situacao** (object) - An object containing the CPF's status code and description. - **codigo** (string) - The status code (e.g., "0" for Regular). - **descricao** (string) - The description of the status (e.g., "Regular"). - **nascimento** (string) - The birth date in MMDDYYYY format. #### Response Example ```json { "ni":"40442820135", "nome":"Nome do CPF 404.428.201-35", "situacao": { "codigo":"0", "descricao":"Regular" }, "nascimento":"14111970" } ``` ``` -------------------------------- ### Estrutura da Resposta do Token de Acesso Source: https://apicenter.estaleiro.serpro.gov.br/documentacao/consulta-cpf/pt/quick_start Exemplo da estrutura JSON retornada pela API ao solicitar um Bearer Token. Contém informações como o tipo de token, tempo de expiração e o próprio access_token. ```json { "scope": "am_application_scope default", "token_type": "Bearer", "expires_in": 3295, "access_token": "c66a7def1c96f7008a0c397dc588b6d7" } ``` -------------------------------- ### Codificar Credenciais para Bearer Token Source: https://apicenter.estaleiro.serpro.gov.br/documentacao/consulta-cpf/pt/quick_start Este comando shell mostra como codificar a combinação de Consumer Key e Consumer Secret em Base64, que é necessária para a autenticação ao solicitar um Bearer Token. ```shell echo -n "djaR21PGoYp1iyK2n2ACOH9REdUb:ObRsAJWOL4fv2Tp27D1vd8fB3Ote" | base64 ``` -------------------------------- ### API Consulta CPF Authentication and Token Generation Source: https://apicenter.estaleiro.serpro.gov.br/documentacao/consulta-cpf/pt/quick_start This section details the steps required to authenticate with the API Consulta CPF and obtain a Bearer Token for making requests. ```APIDOC ## Authentication and Token Generation for API Consulta CPF ### Description This guide explains how to authenticate with the API Consulta CPF using OAuth2. It covers obtaining Consumer Key and Secret, requesting a Bearer Token, and handling token renewal. ### 1. Obtain Consumer Key and Consumer Secret * **Purpose**: To identify your contract with SERPRO. * **Source**: Obtained from the SERPRO customer area. * **Example Credentials**: ``` Consumer Key: djaR21PGoYp1iyK2n2ACOH9REdUb Consumer Secret: ObRsAJWOL4fv2Tp27D1vd8fB3Ote ``` * **Security**: Keep these credentials protected. ### 2. Request Bearer Token * **Purpose**: To obtain a temporary access token (Bearer Token) required for API calls. The token is valid for 1 hour. * **Method**: HTTP POST * **Endpoint**: `https://gateway.apiserpro.serpro.gov.br/token` * **Headers**: * `Authorization`: `Basic ` * `Content-Type`: `application/x-www-form-urlencoded` * **Request Body**: * `grant_type`: `client_credentials` #### Generating the Authorization Header Concatenate your Consumer Key and Consumer Secret with a colon (`:`), then encode the result in Base64. * **Example (using echo and base64)**: ```bash echo -n "djaR21PGoYp1iyK2n2ACOH9REdUb:ObRsAJWOL4fv2Tp27D1vd8fB3Ote" | base64 ``` * **Example Base64 Output**: ``` ZGphUjIxUEdvWXAxaXlLMm4yQUNPSDlSRWRVYjpPYlJzQUpXT0w0ZnYyVHAyN0QxdmQ4ZkIzT3RlCg ``` #### cUrl Example Request ```bash curl -k -d "grant_type=client_credentials" \ -H "Authorization: Basic ZGphUjIxUEdvWXAxaXlLMm4yQUNPSDlSRWRVYjpPYlJzQUpXT0w0ZnYyVHAyN0QxdmQ4ZkIzT3RlCg" \ https://gateway.apiserpro.serpro.gov.br/token ``` ### 3. Receive the Token * **Response Body (Success)**: ```json { "scope": "am_application_scope default", "token_type": "Bearer", "expires_in": 3295, "access_token": "c66a7def1c96f7008a0c397dc588b6d7" } ``` * **`access_token`**: The Bearer Token to be used in subsequent API requests. * **`expires_in`**: The token's validity period in seconds. ### Token Renewal * **Validity**: 1 hour. * **Recommendation**: Generate a new token every hour or when an HTTP 401 error is received. * **Renewal Process**: Repeat Step 2 (Request Bearer Token). ``` -------------------------------- ### Obter Bearer Token com cURL Source: https://apicenter.estaleiro.serpro.gov.br/documentacao/consulta-cpf/pt/quick_start Este snippet demonstra como obter um Bearer Token para autenticação na API Consulta CPF usando cURL. Ele inclui a configuração do tipo de conteúdo e a autorização Basic com o token codificado em Base64. ```shell curl -k -d "grant_type=client_credentials" \ -H "Authorization: Basic ZGphUjIxUEdvWXAxaXlLMm4yQUNPSDlSRWRVYjpPYlJzQUpXT0w0ZnYyVHAyN0QxdmQ4ZkIzT3RlCg" \ https://gateway.apiserpro.serpro.gov.br/token ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.