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

# Valores de Campos

> Definir e obter valores de campos personalizados para leads

## Definir Valor

<Card>
  <strong>PUT</strong> `/backend/lead-fields/{lead_id}/{field_id}`
</Card>

Define o valor de um campo personalizado para um lead específico.

### Path Parameters

<ParamField path="lead_id" type="string" required>
  UUID do lead
</ParamField>

<ParamField path="field_id" type="string" required>
  UUID da definição do campo
</ParamField>

### Request Body

<ParamField body="value" type="any" required>
  Valor do campo (tipo deve corresponder ao field\_type)
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X PUT "https://api.leavo.ai/backend/lead-fields/uuid-lead/uuid-field" \
    -H "Authorization: Bearer sua_chave_aqui" \
    -H "Content-Type: application/json" \
    -d '{
      "value": "Indicação"
    }'
  ```

  ```javascript JavaScript theme={null}
  const leadId = 'uuid-lead';
  const fieldId = 'uuid-field';

  const response = await fetch(
    `https://api.leavo.ai/backend/lead-fields/${leadId}/${fieldId}`,
    {
      method: 'PUT',
      headers: {
        'Authorization': 'Bearer sua_chave_aqui',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        value: 'Indicação'
      })
    }
  );
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "lead_id": "uuid-lead",
    "field_id": "uuid-field",
    "value": "Indicação",
    "updated_at": "2024-01-15T10:30:00Z"
  }
  ```
</ResponseExample>

***

## Obter Valores de um Lead

<Card>
  <strong>GET</strong> `/backend/lead-fields/{lead_id}`
</Card>

Retorna todos os valores de campos personalizados de um lead.

### Path Parameters

<ParamField path="lead_id" type="string" required>
  UUID do lead
</ParamField>

### Query Parameters

<ParamField query="detailed" type="boolean" default="false">
  Incluir detalhes da definição do campo
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.leavo.ai/backend/lead-fields/uuid-lead?detailed=true" \
    -H "Authorization: Bearer sua_chave_aqui"
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK - Simples theme={null}
  {
    "origem_lead": "Indicação",
    "valor_potencial": 50000,
    "data_primeiro_contato": "2024-01-10T00:00:00Z"
  }
  ```

  ```json 200 OK - Detalhado theme={null}
  [
    {
      "field_id": "uuid-1",
      "field_key": "origem_lead",
      "field_label": "Origem do Lead",
      "field_type": "select",
      "value": "Indicação"
    },
    {
      "field_id": "uuid-2",
      "field_key": "valor_potencial",
      "field_label": "Valor Potencial",
      "field_type": "number",
      "value": 50000
    }
  ]
  ```
</ResponseExample>

***

## Exemplo Completo

```javascript theme={null}
// 1. Criar definição de campo
const fieldDef = await fetch('https://api.leavo.ai/backend/custom-fields', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    field_key: 'valor_potencial',
    field_label: 'Valor Potencial',
    field_type: 'number',
    required: false
  })
}).then(r => r.json());

// 2. Definir valor para um lead
await fetch(
  `https://api.leavo.ai/backend/lead-fields/${leadId}/${fieldDef.id}`,
  {
    method: 'PUT',
    headers: {
      'Authorization': 'Bearer key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ value: 75000 })
  }
);

// 3. Buscar todos os valores do lead
const values = await fetch(
  `https://api.leavo.ai/backend/lead-fields/${leadId}`,
  { headers: { 'Authorization': 'Bearer key' } }
).then(r => r.json());

console.log(values);
// { valor_potencial: 75000 }
```
