# Configure Census Connection

The objective of this service is to be able to configure the connection with a census through the administration panel without having to modify the application code.

It should be noted that to properly configure this connection, a technical profile that knows the WebService with which we want to connect will be required.

## Enabling the feature

To enable the feature you have to access from the administration panel to the **Settings > Global settings > Features** section and enable the **Configure connection to the remote census (SOAP)** module.

## Configuration

Once the feature is activated, we can access the section **Settings > Global settings** and click on the tab **Remote Census Configuration** to be able to configure the connection with the census.

The information to be filled in is divided into three sections:

### General Information

* **Endpoint**: Host name where the census service is available (wsdl).

### Request data

In this section we will fill in all the necessary fields to be able to make a request to verify a user through a census.

To help you understand how to fill in each of the fields, we will rely on a supposed WebService that receives a method called `:get_habita_datos` with the following structure:

```ruby
{
  request: {
    codigo_institucion: 12,        # Static Value
    codigo_portal:      5,         # Static Value
    codigo_usuario:     10,        # Static Value
    documento:          12345678Z, # Dynamic value related to Document Number
    tipo_documento:     1,         # Dynamic value related to Document Type
    nivel:              3          # Static Value
  }
}
```

Required fields for the request:

* **Request method name**: Request method name accepted by the census WebService.

  ![Request data - Request method name is filled in with get\_habita\_datos](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-04a988f1a62d6074b78bf852a4fd117f8c472926%2Frequest-data-method-name-en.png?alt=media)
* **Request Structure**: Structure of the request received by the WebService of the census. The *static* values of this request should be reported. The *dynamic* values related to Document Type, Document Number, Date of Birth and Postal Code should be filled with *null* value.

  ![Request data - Structure](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-2e680a21fe51d9b3656226e38ebe2eaeb6d3fd92%2Frequest-data-structure-en.png?alt=media)

  ```ruby
  {
    request: {
      codigo_institucion: 12,        # Since it is a "fixed" value in all requests, we fill in it.
      codigo_portal:      5,         # Since it is a "fixed" value in all requests, we fill in it.
      codigo_usuario:     10,        # Since it is a "fixed" value in all requests, we fill in it.
      documento:          null,      # Since it is a value related to Document Type, Document Number, Date of Birth or Postal Code, we fill it in with a null value
      tipo_documento:     null,      # Since it is a value related to Document Type, Document Number, Date of Birth or Postal Code, we fill it in with a null value
      codigo_idioma:      102,       # Since it is a "fixed" value in all requests, we fill in it.
      nivel:              3          # Since it is a "fixed" value in all requests, we fill in it.
    }
  }
  ```
* **Path for document type**: Path in the request structure that sends the Document Type.

  *NOTE: DO NOT FILL IN if the WebService does not require the Document Type to verify a user.*

  ![Request data - Path for document type is filled in with request.tipo\_documento](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-5ac695947486a81fe2d7f6cf2f82fdca4988da1f%2Frequest-data-path-document-type-en.png?alt=media)
* **Path for document number**: Path in the request structure that sends the Document Number.

  *NOTE: DO NOT FILL IN if the WebService does not require the Document Number to verify a user.*

  ![Request data - Path for document number is filled in with request.documento](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-96b56071a1fb37d9cce9709d89c1ee21986747a3%2Frequest-data-path-document-number-en.png?alt=media)
* **Path for date of birth**: Path in the request structure that sends the Date of Birth.

  *NOTE: DO NOT FILL IN if the WebService does not require the Date of Birth to verify a user.*

  In *this example*, we will leave it blank, since it is not necessary to send the date of birth to verify a user.

  ![Request data - Path for date of birth is left blank](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-659239f42f2f154fd037640dc90e21d8d0cba91d%2Frequest-data-path-date-of-birth-en.png?alt=media)
* **Path for Postal Code**: Path in the request structure that sends the Postal Code.

  *NOTE: DO NOT FILL IN if the WebService does not require the Postal Code to verify a user.*

  In *this example*, we will leave it blank, since it is not necessary to send the postal code to verify a user.

  ![Request data - Path for postal code is left blank](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-874be6600a258cc43704ad567ca84551c399617f%2Frequest-data-path-postal-code-en.png?alt=media)

### Response data

In this section we will configure all the necessary fields to be able to receive the answer of the WebService and to verify a user in the application.

As in the previous section, we will define an example answer to help you understand how to fill in each of the fields in this section.

```ruby
{
  get_habita_datos_response: {
    get_habita_datos_return: {
      datos_habitante: {
        item: {
          fecha_nacimiento_string: "31-12-1980",
          identificador_documento: "12345678Z",
          descripcion_sexo: "Varón",
          nombre: "José",
          apellido1: "García"
        }
      },
      datos_vivienda: {
        item: {
          codigo_postal: "28013",
          codigo_distrito: "01"
        }
      }
    }
  }
}
```

Required fields to parse the response:

* **Path for Date of Birth**: Path in the response structure containing the user's Date of Birth.

  ![Response data - Path for date of birth is filled in with get\_habita\_datos\_response.get\_habita\_datos\_return.datos\_habitante.item.fecha\_nacimiento\_string](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-6dc010f9b4a8b2af8d1c1669aadb50ed63f62b21%2Fresponse-data-path-date-of-birth-en.png?alt=media)
* **Path for Postal Code**: Path in the response structure containing the user's Postal Code.

  ![Response data - Path for postal code is filled in with get\_habita\_datos\_response.get\_habita\_datos\_return.datos\_vivienda.item.codigo\_postal](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-8231c97ecc59f325e18b4dc0bd3a8702b054aa8d%2Fresponse-data-path-postal-code-en.png?alt=media)
* **Path for District**: Path in the response structure containing the user's District.

  ![Response data - Path for district is filled in with get\_habita\_datos\_response.get\_habita\_datos\_return.datos\_vivienda.item.codigo\_distrito](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-130958d9cef56ac5ef5a2473878d4799c9b9ea7e%2Fresponse-data-path-district-en.png?alt=media)
* **Path for Gender**: Path in the response structure containing the user's Gender.

  ![Response data - Path for gender is filled in with get\_habita\_datos\_response.get\_habita\_datos\_return.datos\_habitante.item.descripcion\_sexo](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-77a56c3035de86e0f4619d567ee3d0251c25676e%2Fresponse-data-path-gender-en.png?alt=media)
* **Path for Name**: Path in the response structure containing the user's Name.

  ![Response data - Path for name is filled in with get\_habita\_datos\_response.get\_habita\_datos\_return.datos\_habitante.item.nombre](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-15edb0fcc6c4c780728e87033bd095a674efae5e%2Fresponse-data-path-name-en.png?alt=media)
* **Path for the Last Name**: Path in the response structure containing the user's Last Name.

  ![Response data - Path for last name is filled in with get\_habita\_datos\_response.get\_habita\_datos\_return.datos\_habitante.item.apellido1](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-90008148ca47e87ebf17d039d7894a2e726550a2%2Fresponse-data-path-last-name-en.png?alt=media)
* **Path for detecting a valid response**: Path in the response structure that must be filled in in valid responses.

  ![Response data - Path for valid response is filled in with get\_habita\_datos\_response.get\_habita\_datos\_return.datos\_habitante.item](https://4225702781-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FflWMexsaWhWHsmTfovvS%2Fuploads%2Fgit-blob-3fb3966a21c2495f3cae00a8460dab419b8bf76a%2Fresponse-data-path-valid-response-en.png?alt=media)

  Once the general data, the necessary fields of the request and **all** fields to validate the response have been correctly filled in, the application will be able to verify any user through the defined WebService.
