> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/No-Country-simulation/S02-26-Equipo-33-Web-App/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Horse

> Update an existing horse listing (owner or admin)

## Authentication

Required - JWT Bearer token with `seller` or `admin` role

```bash theme={null}
Authorization: Bearer YOUR_JWT_TOKEN
```

## Authorization

* **Sellers** can only update their own listings
* **Admins** can update any listing

## Path Parameters

<ParamField path="id" type="string" required>
  Horse unique identifier (MongoDB ObjectId)
</ParamField>

## Request Body

All fields are optional - only include fields you want to update.

<ParamField body="name" type="string">
  Horse name (trimmed)
</ParamField>

<ParamField body="age" type="number">
  Horse age in years (0-40)
</ParamField>

<ParamField body="breed" type="string">
  Horse breed (trimmed)
</ParamField>

<ParamField body="discipline" type="string">
  Primary discipline (trimmed)
</ParamField>

<ParamField body="pedigree" type="string">
  Pedigree information
</ParamField>

<ParamField body="location" type="object">
  Horse location information

  <ParamField body="country" type="string">
    Country
  </ParamField>

  <ParamField body="region" type="string">
    Region or state
  </ParamField>

  <ParamField body="city" type="string">
    City
  </ParamField>

  <ParamField body="coordinates" type="object">
    <ParamField body="lat" type="number">
      Latitude
    </ParamField>

    <ParamField body="lng" type="number">
      Longitude
    </ParamField>
  </ParamField>
</ParamField>

<ParamField body="price" type="number">
  Listing price (minimum: 0)
</ParamField>

<ParamField body="currency" type="string">
  Currency code: USD, EUR, ARS, BRL, MXN
</ParamField>

<ParamField body="photos" type="array">
  Array of photos (minimum 3 required if updating)

  <ParamField body="url" type="string" required>
    Photo URL
  </ParamField>

  <ParamField body="caption" type="string">
    Photo caption
  </ParamField>

  <ParamField body="is_cover" type="boolean">
    Whether this is the cover photo
  </ParamField>
</ParamField>

<ParamField body="videos" type="array">
  Array of videos

  <ParamField body="url" type="string" required>
    Video URL
  </ParamField>

  <ParamField body="video_type" type="string" required>
    Type: training, competition, other
  </ParamField>

  <ParamField body="title" type="string">
    Video title
  </ParamField>

  <ParamField body="description" type="string">
    Video description
  </ParamField>

  <ParamField body="recorded_at" type="string" required>
    Recording date (ISO 8601)
  </ParamField>
</ParamField>

<ParamField body="status" type="string">
  Listing status: active, sold, paused, draft
</ParamField>

## Response

<ResponseField name="success" type="boolean">
  Indicates if the request was successful
</ResponseField>

<ResponseField name="data" type="object">
  Updated horse listing with all fields

  <ResponseField name="_id" type="string">
    Horse unique identifier
  </ResponseField>

  <ResponseField name="seller_id" type="string">
    Seller ID
  </ResponseField>

  <ResponseField name="name" type="string">
    Horse name
  </ResponseField>

  <ResponseField name="age" type="number">
    Horse age
  </ResponseField>

  <ResponseField name="breed" type="string">
    Horse breed
  </ResponseField>

  <ResponseField name="discipline" type="string">
    Primary discipline
  </ResponseField>

  <ResponseField name="pedigree" type="string">
    Pedigree information
  </ResponseField>

  <ResponseField name="location" type="object">
    Location details
  </ResponseField>

  <ResponseField name="price" type="number">
    Listing price
  </ResponseField>

  <ResponseField name="currency" type="string">
    Currency code
  </ResponseField>

  <ResponseField name="photos" type="array">
    Array of photos
  </ResponseField>

  <ResponseField name="videos" type="array">
    Array of videos with auto-generated embed\_url
  </ResponseField>

  <ResponseField name="status" type="string">
    Listing status
  </ResponseField>

  <ResponseField name="views_count" type="number">
    View count
  </ResponseField>

  <ResponseField name="created_at" type="string">
    Creation timestamp
  </ResponseField>

  <ResponseField name="updated_at" type="string">
    Last update timestamp (updated)
  </ResponseField>
</ResponseField>

## Notes

* Only provide fields you want to update (partial update)
* Validators run on update, ensuring data integrity
* Video `embed_url` is auto-regenerated for YouTube/Vimeo URLs
* `updated_at` timestamp is automatically updated
* Cannot change `seller_id` or `views_count` via this endpoint

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PUT "https://api.horsetrust.com/api/horses/507f1f77bcf86cd799439011" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer YOUR_JWT_TOKEN" \
    -d '{
      "price": 42000,
      "status": "active",
      "location": {
        "country": "Argentina",
        "region": "Buenos Aires",
        "city": "Pilar"
      }
    }'
  ```

  ```javascript JavaScript theme={null}
  const horseId = '507f1f77bcf86cd799439011';
  const response = await fetch(`https://api.horsetrust.com/api/horses/${horseId}`, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer YOUR_JWT_TOKEN'
    },
    body: JSON.stringify({
      price: 42000,
      status: 'active',
      location: {
        country: 'Argentina',
        region: 'Buenos Aires',
        city: 'Pilar'
      }
    })
  });

  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  horse_id = '507f1f77bcf86cd799439011'
  response = requests.put(
      f'https://api.horsetrust.com/api/horses/{horse_id}',
      headers={
          'Content-Type': 'application/json',
          'Authorization': 'Bearer YOUR_JWT_TOKEN'
      },
      json={
          'price': 42000,
          'status': 'active',
          'location': {
              'country': 'Argentina',
              'region': 'Buenos Aires',
              'city': 'Pilar'
          }
      }
  )

  data = response.json()
  print(data)
  ```
</CodeGroup>

<ResponseExample>
  ```json Response theme={null}
  {
    "success": true,
    "data": {
      "_id": "507f1f77bcf86cd799439011",
      "seller_id": "507f191e810c19729de860ea",
      "name": "Thunder",
      "age": 8,
      "breed": "Thoroughbred",
      "discipline": "Show Jumping",
      "pedigree": "Sire: Storm Cat, Dam: Winning Colors",
      "location": {
        "country": "Argentina",
        "region": "Buenos Aires",
        "city": "Pilar",
        "coordinates": {
          "lat": -34.4708,
          "lng": -58.5247
        }
      },
      "price": 42000,
      "currency": "USD",
      "photos": [
        {
          "_id": "65f1a2b3c4d5e6f7g8h9i0j1",
          "url": "https://cdn.horsetrust.com/photos/abc123.jpg",
          "caption": "Thunder at competition",
          "is_cover": true,
          "uploaded_at": "2026-03-01T10:00:00Z"
        }
      ],
      "videos": [
        {
          "_id": "65f1a2b3c4d5e6f7g8h9i0j2",
          "url": "https://youtube.com/watch?v=abc123",
          "embed_url": "https://www.youtube.com/embed/abc123",
          "video_type": "competition",
          "title": "Thunder jumping 1.40m",
          "recorded_at": "2026-02-15T00:00:00Z",
          "uploaded_at": "2026-03-01T10:00:00Z"
        }
      ],
      "status": "active",
      "views_count": 235,
      "created_at": "2026-03-01T10:00:00Z",
      "updated_at": "2026-03-05T15:45:00Z"
    }
  }
  ```
</ResponseExample>

## Error Responses

### 400 - Invalid Horse ID

```json theme={null}
{
  "success": false,
  "message": "Invalid horse ID"
}
```

### 400 - Validation Error

```json theme={null}
{
  "success": false,
  "message": "Validation failed: age: Path `age` (50) is more than maximum (40)"
}
```

### 401 - Unauthorized

```json theme={null}
{
  "success": false,
  "message": "Authentication required"
}
```

### 403 - Forbidden

```json theme={null}
{
  "success": false,
  "message": "Seller role required"
}
```

### 404 - Not Found or Unauthorized

```json theme={null}
{
  "success": false,
  "message": "Horse not found or unauthorized"
}
```

### 500 - Server Error

```json theme={null}
{
  "success": false,
  "message": "Server error"
}
```
