> ## Documentation Index
> Fetch the complete documentation index at: https://docs.localpayment.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creare un'entità

> Registra una persona o un'azienda con i dati KYC minimi e il relativo documento principale: il primo passo di un onboarding KYC/KYB.

Questa guida ti accompagna nella registrazione di una persona e di un'azienda con [Creare un'entità](https://docs.localpayment.com/it/reference/create-entity.md). L'entità viene creata senza file: li caricherai nel passaggio successivo, [Caricare documenti e documenti probatori](https://docs.localpayment.com/it/docs/upload-documents-and-proofs.md).

## Prerequisiti

* Un token di accesso per l'ambiente Stage. Consulta [Ottenere il token di accesso](https://docs.localpayment.com/it/reference/get-token.md).
* Il tipo di entità: `INDIVIDUAL` per una persona fisica, `COMPANY` per una persona giuridica.
* Il documento identificativo. Per una persona: l'identificativo fiscale (`CPF`, `CUIT`, `RFC`, `CURP`) o un documento d'identità (`DNI`, `PASSPORT`, `CC`). Per un'azienda: l'identificativo fiscale (`CNPJ`, `CUIT`, `RFC`, `RUC`, `NIT`). Diventa il documento principale.
* Un `externalId` stabile: il tuo riferimento, univoco per esercente.
* Se Localpayment ha configurato campi personalizzati per il tuo profilo esercente, il relativo schema. Consulta [Campi personalizzati](https://docs.localpayment.com/it/docs/custom-fields.md).

## Quali documenti dichiarare

Un documento è un id che contiene tutti i file di cui hai bisogno, come il fronte, il retro e il selfie di un documento d'identità. Quando crei l'entità, invia il documento identificativo in `document`: diventa il documento principale. Dichiara ogni altro documento con [Aggiungere un documento](https://docs.localpayment.com/it/reference/add-entity-document.md). La coppia `type` + `id` deve essere univoca nel tuo profilo esercente.

| Tipo | Documento principale | Altri documenti |
| - | - | - |
| `INDIVIDUAL` | Identificativo fiscale o documento d'identità (CPF, DNI, PASSPORT). Documenti probatori: FRONT, BACK, SELFIE. | PROOF\_OF\_ADDRESS e qualsiasi altra evidenza (PROOF\_OF\_FUNDS, PAYSLIP, OTHER). |
| `COMPANY` | Identificativo fiscale (CNPJ, CUIT, RFC, RUC, NIT). Documento probatorio: DOCUMENT. | ARTICLES\_OF\_INCORPORATION, PROOF\_OF\_ADDRESS. I titolari vengono registrati come entità INDIVIDUAL e collegati con [Gestire gli UBO](https://docs.localpayment.com/it/docs/manage-ubos.md). |

L'elenco completo dei valori è disponibile in [Tipi di documenti e documenti probatori](https://docs.localpayment.com/it/reference/entity-document-and-proof-types.md).

## Dati minimi

| Tipo | Richiesti dall'API | Fortemente consigliati |
| - | - | - |
| `INDIVIDUAL` | externalId, type, name, lastname, document | birthdate, nationality, residenceCountry, email, phone, address |
| `COMPANY` | externalId, type, name, document | incorporationCountry, incorporationDate, legalRepresentativeName, website, email, phone, address |

Se mancano dati KYC obbligatori, viene restituito 422 `INCOMPLETE_KYC_DATA`.

## Creare una persona

```bash Request theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
curl -X POST https://api.stage.localpayment.com/api/entity/v1/entities \
  -H "Authorization: Bearer $LOCALPAYMENT_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "X-Correlation-ID: 0e8f6a2c-5b3d-4c1e-9a7f-6d5e4c3b2a10" \
  -d '{
    "externalId": "550e8400-e29b-41d4-a716-446655440000",
    "type": "INDIVIDUAL",
    "name": "Jane",
    "lastname": "Doe",
    "birthdate": "1990-01-15",
    "nationality": "BRA",
    "birthCountry": "BRA",
    "residenceCountry": "BRA",
    "isPep": false,
    "email": "jane.doe@example.com",
    "phone": {
      "countryCode": "55",
      "areaCode": "11",
      "number": "999990001"
    },
    "address": {
      "street": "Rua Exemplo",
      "number": "123",
      "city": "São Paulo",
      "state": "SP",
      "zipCode": "01310-100",
      "country": "BRA"
    },
    "document": {
      "type": "CPF",
      "id": "00000000000",
      "issuingCountry": "BRA"
    }
  }'
```

```json Response theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
  "internalId": "5aced5da-40c1-4bec-85ff-c8cd1bcb4526",
  "externalId": "550e8400-e29b-41d4-a716-446655440000",
  "type": "INDIVIDUAL",
  "status": "PENDING_KYC",
  "name": "Jane",
  "lastname": "Doe",
  "birthdate": "1990-01-15",
  "gender": null,
  "nationality": "BRA",
  "birthCountry": "BRA",
  "residenceCountry": "BRA",
  "occupation": null,
  "isPep": false,
  "incorporationDate": null,
  "incorporationCountry": null,
  "website": null,
  "legalRepresentativeName": null,
  "email": "jane.doe@example.com",
  "phone": {
    "countryCode": "55",
    "areaCode": "11",
    "number": "999990001"
  },
  "address": {
    "street": "Rua Exemplo",
    "city": "São Paulo",
    "state": "SP",
    "zipCode": "01310-100",
    "number": "123",
    "comment": null,
    "country": "BRA",
    "line2": null,
    "line3": null
  },
  "attributes": null,
  "documentationStatus": "NO_FILES",
  "document": {
    "documentId": "2e16d844-4fa9-4295-9a21-83ec32ef241a",
    "entityId": "5aced5da-40c1-4bec-85ff-c8cd1bcb4526",
    "type": "CPF",
    "id": "00000000000",
    "issuingCountry": "BRA",
    "issueDate": null,
    "expirationDate": null,
    "isPrimary": true,
    "status": "PENDING",
    "metadata": null,
    "proofs": [],
    "createdAt": "2024-01-15T17:03:10Z",
    "updatedAt": "2024-01-15T17:03:10Z"
  },
  "documents": [],
  "version": 0,
  "createdAt": "2024-01-15T17:03:10Z",
  "updatedAt": "2024-01-15T17:03:10Z",
  "customFieldSchemaVersion": null
}
```

La risposta è 201 Created con l'header `ETag: "0"`.

Conserva `internalId` (l'entità) e `document.documentId` (il documento principale): ti serviranno entrambi nei passaggi successivi.

## Creare un'azienda

Un'azienda con il proprio identificativo fiscale come documento principale, un indirizzo con righe aggiuntive e campi personalizzati:

```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
  "externalId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
  "type": "COMPANY",
  "name": "Example Company S.A.",
  "incorporationCountry": "BRA",
  "incorporationDate": "2020-01-15",
  "website": "https://www.example.com",
  "email": "test@example.com",
  "phone": {
    "countryCode": "55",
    "areaCode": "11",
    "number": "999990000"
  },
  "legalRepresentativeName": "Jane Doe",
  "isPep": false,
  "address": {
    "street": "Rua Exemplo",
    "number": "100",
    "city": "São Paulo",
    "state": "SP",
    "zipCode": "01310-100",
    "country": "BRA",
    "line2": "Sala 100",
    "line3": "Torre A"
  },
  "document": {
    "type": "CNPJ",
    "id": "00000000000100",
    "issuingCountry": "BRA"
  },
  "attributes": {
    "reasonForAccountOpening": "receive_payments_for_goods_and_services",
    "sourceOfFundsAndIncome": "sales_of_goods_and_services",
    "numberOfEmployees": "11-50",
    "estimatedAnnualRevenueUsd": "1m_to_10m",
    "estimatedMonthlyVolumeUsd": "50000",
    "businessActivityDescription": "Online retail of home goods. Receives payments from end customers in Brazil via PIX.",
    "countryTaxResidence": "BRA",
    "socialMedia": "https://www.linkedin.com/company/example",
    "emailPixKey": "test@example.com"
  }
}
```

## Gestire gli errori nella tua integrazione

```python theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
import os
import uuid
import requests

BASE_URL = "https://api.stage.localpayment.com/api/entity"
access_token = os.environ["LOCALPAYMENT_ACCESS_TOKEN"]

payload = {
    "externalId": "550e8400-e29b-41d4-a716-446655440000",
    "type": "INDIVIDUAL",
    "name": "Jane",
    "lastname": "Doe",
    "document": {"type": "CPF", "id": "00000000000", "issuingCountry": "BRA"},
}

response = requests.post(
    f"{BASE_URL}/v1/entities",
    json=payload,
    headers={
        "Authorization": f"Bearer {access_token}",
        "X-Correlation-ID": str(uuid.uuid4()),
    },
    timeout=30,
)

if response.status_code == 201:
    entity = response.json()
    entity_id = entity["internalId"]
    primary_document_id = entity["document"]["documentId"]
else:
    problem = response.json()  # application/problem+json
    code = problem.get("code")
    if code == "DUPLICATE_ENTITY":
        # Already registered: look it up with GET /v1/entities?externalId=...
        pass
    elif code in ("VALIDATION_ERROR", "CUSTOM_FIELDS_INVALID"):
        for detail in problem.get("details", []):
            print(f"{detail['field']}: {detail['issue']}")
    else:
        # Quote the correlation id when you contact support
        print(f"{response.status_code} {code} correlationId={problem.get('correlationId')}")
```

## Errori comuni

| Errore | Causa | Soluzione |
| - | - | - |
| 400 VALIDATION\_ERROR | Proprietà sconosciuta, codice paese a due lettere, un elenco documents invece di document oppure nessun documento. | Controlla il campo indicato in ciascuna voce di details. Sposta i dati aggiuntivi in attributes. |
| 400 CUSTOM\_FIELDS\_INVALID | attributes non rispetta lo schema dei campi personalizzati. | Leggi lo schema e correggi il campo indicato in details. |
| 409 DUPLICATE\_ENTITY | externalId, oppure una coppia type + id di un documento, è già utilizzato nel tuo profilo esercente. | Riutilizza l'entità esistente. Puoi trovarla con [Elencare le entità](https://docs.localpayment.com/it/reference/list-entities.md). |
| 422 INCOMPLETE\_KYC\_DATA | Mancano i dati KYC minimi. | Aggiungi name e lastname (persona) o name (azienda). |

Esempio di errore di convalida dei campi personalizzati:

```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
  "type": "about:blank",
  "title": "Validation error",
  "status": 400,
  "detail": "Validation error",
  "instance": "/api/entity/v1/entities",
  "code": "CUSTOM_FIELDS_INVALID",
  "correlationId": "fff39bf8-1cb2-40c7-ac99-37478d819943",
  "details": [
    {
      "field": "numberOfEmployees",
      "issue": "NOT_IN_OPTIONS"
    },
    {
      "field": "legacyNote",
      "issue": "UNKNOWN_FIELD"
    }
  ]
}
```

> [!WARNING]
>
> Un identificativo fiscale (`CPF`, `CNPJ`, `CUIT`, `RFC`) è un documento, non un campo dell'entità: invialo in `document`. I codici paese devono essere in formato ISO 3166-1 alpha-3 (`BRA`, non `BR`).

## Passaggi successivi

> [card] [Caricare documenti e documenti probatori](https://docs.localpayment.com/it/docs/upload-documents-and-proofs.md)
>
> Allega i file a supporto di ciascun documento dichiarato.

> [card] [Riferimento API: Creare un'entità](https://docs.localpayment.com/it/reference/create-entity.md)
>
> Tutti i campi della richiesta e della risposta e i codici di errore.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.