
# Creating a Background Check

{{<tags >}}

Let’s make our first background check to help illustrate the usage of our API.

## Prerequisites

To create a check, the following elements are needed:

- **Truora API-Key:** Grants access to our services. If you don’t have one already go to [Set up an account](/checks/account/) to learn how to get your **Truora API-key**.
- **A valid ID**: from the person, vehicle, or company to run the background check.
- **Postman:** Use Postman or any other collaboration tool for API development. Although it is not required to perform the integration, it will help perform tests along the way.

## Create a Check - Using an API Platform like Postman

Follow these steps to perform your first **background check** for a **person**:
1. Create a **POST** request to ``https://api.checks.truora.com/v1/checks`` in Postman.
2. Click the **Headers** tab. Create a new key named ``Truora-API-Key``.
3. Set the **Value** for ``Truora-API-Key`` as your Truora API-key.
4. Create a new key named ``Content-Type``.
5. Set the value for Content-Type as ``application/x-www-form-urlencoded``.
6. Click the Body tab. Tick the ``x-www-form-urlencoded`` box.
7. Create a new key named ``national_id``.
8. Set the value for ``national_id`` as your ID card number (numbers only, CC for Colombia, CURP for Mexico, DNI for Peru and so on).
9. Create a new key named ``country`` and set its value to your country:
    - ``ALL`` for International Lists
    - ``BR`` for Brazil
    - ``CO`` for Colombia
    - ``CL`` for Chile
    - ``CR`` for Costa Rica
    - ``MX`` for Mexico
    - ``PE`` for Peru
10. Create a new key named ``type`` and set its value to ``person`` (when you create a [Custom Type](/guides/background_check_custom_type/) check and want to use it, you must set the value to the name of your **Custom Type** instead).
11. For background checks in **Brazil**, create a new key named ``date_of_birth`` and set its value to the date of birth of the person to be checked in format ``yyyy-mm-dd``.
12. For background checks in **Mexico**, you have two input options for type person checks that require validation of identity against RENAPO:
    - **Standard method:** Use the CURP number with the ``national_id`` field
    - **Alternative method:** Use the following fields instead of ``national_id``:
      - ``first_name``: Person's first name
      - ``last_name``: Person's last name
      - ``state_id``: Mexico state ID (2 letters). Valid codes: 
{{<table "table w-auto small m-auto text-center table-striped table-bordered" >}}
| State | Code | State | Code |
|:-----------------------:|:----:|:---------------:|:----:|
| Aguascalientes | AS | Morelos | MS |
| Baja California | BC | Nayarit | NT |
| Baja California Sur | BS | Nuevo León | NL |
| Campeche | CC | Oaxaca | OC |
| Coahuila | CL | Puebla | PL |
| Colima | CM | Querétaro | QT |
| Chiapas | CS | Quintana Roo | QR |
| Chihuahua | CH | San Luis Potosí | SP |
| Distrito Federal | DF | Sinaloa | SL |
| Durango | DG | Sonora | SR |
| Guanajuato | GT | Tabasco | TC |
| Guerrero | GR | Tamaulipas | TS |
| Hidalgo | HG | Tlaxcala | TL |
| Jalisco | JC | Veracruz | VZ |
| México | MC | Yucatán | YN |
| Nacido en el Extranjero | NE | Zacatecas | ZS |
{{</table >}}
      - ``gender``: Gender (accepted values: ``"male"``, ``"masculino"``, ``"hombre"``, ``"h"``, ``"female"``, ``"femenino"``, ``"mujer"``, ``"m"``)
      - ``date_of_birth``: Date of birth in format ``yyyy-mm-dd``
13. Create a new key named ``user_authorized`` and set its value to ``true``. This indicates that you have the **authorization** of the person to be checked. This is **mandatory** in order to comply with **data protection laws**.
14. Create a new key named ``force_creation`` and set its value to ``true``. This forces the creation of a new check rather than searching for a previous performed check.
15. Optionally, you can create the key called ``custom_input``. This field accepts a string of up to 128 characters and can be used to send additional information in the Background Check. You can use it to send any relevant information for your operation or use case.
16. Click **Send**. The API returns a response in JSON format. Copy the ``check_id`` from the response.
17. Create a GET request to ``https://api.checks.truora.com/v1/checks/{{check_id}}``.
18. Replace ``{{check_id}}`` with the ``check_id`` from the response.
19. Click **Send**. The API returns a response in JSON format containing the check result.
20. Click **Send** again to refresh the response in case some results are missing. The time it takes for results to 
be ready varies between countries and depends on the availability of the databases we use.
21. Additionally, You can look at the check details by creating a GET request to ``https://api.checks.truora.com/v1/checks/{check_id}/details`` and replacing ``{{check_id}}`` with the ``check_id from`` the response.
---

## Create a Check - Using an example Script (Javascript or Python)

### Calling the endpoint

In the following example, we will run a background check of the type **person** for the country **CO** (Colombia).

- We will make a **POST** call to the https://api.checks.truora.com/v1/checks endpoint to create the check (More info in the [API reference](/docs/)).
- Then we will poll the result by making **GET** requests to ``https://api.checks.truora.com/v1/checks/{{check_id}}``, replacing ``{{check_id}}`` with the ``check_id`` from the previous **POST** response.

**Lets start:**

You can copy the following script (select Javascript or Python) to test the use of this endpoint:
- ***Remember***: The ``api_key`` value must be set with the **Truora API-key** you got in the first steps of this guide. 

{{<code2 "{\"python\": \"create_check.py\", \"javascript\": \"create_check.js\"}" "Create Check" >}}

After the Check is created, you will receive a response similar to the following, in JSON format:

{{<code lang="json" lang_title="Check response" >}}
{
    "check": {
        "check_id": "CHK3815eafb4ec7yd4cd3i3b5f4093f7a2c",
        "country": "CO",
        "creation_date": "2023-09-11T16:49:11.903834331Z",
        "name_score": 0,
        "id_score": 0,
        "score": -1,
        "status": "not_started",
        "update_date": "2023-09-11T16:49:11.944670023Z",
        "billing_hub": "hub",
        "national_id": "10000000",
        "type": "person"
    },
    "details": "/v1/checks/CHK3815eafb4ec7yd4cd3i3b5f4093f7a2c/details",
    "self": "/v1/checks/CHK3815eafb4ec7yd4cd3i3b5f4093f7a2c"
}
{{</code>}}

- ***Note***: Copy the ``check_id`` value from your response as you will need it in the next step.

### Polling the result

The most important field in the Checks response is **status**. It'll always return **not_started** upon creation but as the checks moves to the different stages of its lifecycle, it will be updated accordingly. It is important then to **poll** the result of the Check so you can verify when the Check has finished according to the **status** value.

The following sample script will poll the request until the status is **completed**, but keep in mind that other final statuses are also possible. Refer to the "**Check Statuses**" section in this [guide](/checks/lifecycle) for more information.

- ***Remember***: 
    - The ``api_key`` value must be set with the **Truora API-key** you got in the first steps of this guide. 
    - The ``check_id`` value must be set with the **check_id** you got in the response of the previous step. 

{{<code2 "{\"python\": \"poll_check.py\", \"javascript\": \"poll_check.js\"}" "Poll Check" >}}

Once the Check has completed now you can use the **score** of your **Check Response** to make a decision.