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

# Update Loop

> Update an existing loop's name, description, or icon. Only the loop creator can make updates.

Update the details of an existing loop. You can modify the name, description, and icon of any loop you've created. This operation preserves all members and existing requests.

## Authentication

**Authorization** `string` *required*

Your API key for authentication

## Path Parameters

**id** `string` *required*

The unique identifier of the loop to update

## Body Parameters

**name** `string`

New name for the loop (1-100 characters)

**description** `string`

New description of the loop's purpose (max 500 characters)

**icon** `string`

New icon identifier for the loop

> [!NOTE]
>
> All body parameters are optional. Only provide the fields you want to update.

## Response

**error** `boolean`

Whether an error occurred

**msg** `string`

Success message

**data** `object`

**data**

**loop** `object`

The updated loop object with all current information

**loop**

**id** `string`

Unique identifier for the loop

**name** `string`

Updated name of the loop

**description** `string`

Updated description of the loop

**icon** `string`

Updated icon identifier

**creator\_id** `string`

ID of the loop creator (unchanged)

**members** `array`

Array of loop members (unchanged)

**member\_count** `integer`

Total number of members

**pending\_count** `integer`

Number of pending invitations

**created\_at** `string`

ISO timestamp of creation (unchanged)

**updated\_at** `string`

ISO timestamp of this update

```bash cURL theme={null}
curl -X PUT https://api.hitl.sh/v1/api/loops/65f1234567890abcdef12345 \
  -H "Authorization: Bearer your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Enhanced Content Moderation",
    "description": "Advanced review system for user-generated content with improved guidelines",
    "icon": "shield-exclamation"
  }'
```

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

loop_id = "65f1234567890abcdef12345"
url = f"https://api.hitl.sh/v1/api/loops/{loop_id}"
headers = {
    "Authorization": "Bearer your_api_key_here",
    "Content-Type": "application/json"
}
data = {
    "name": "Enhanced Content Moderation",
    "description": "Advanced review system with improved guidelines",
    "icon": "shield-exclamation"
}

response = requests.put(url, headers=headers, json=data)
print(response.json())
```

```javascript Node.js theme={null}
const axios = require('axios');

const loopId = '65f1234567890abcdef12345';
const response = await axios.put(
  `https://api.hitl.sh/v1/api/loops/${loopId}`,
  {
    name: 'Enhanced Content Moderation',
    description: 'Advanced review system with improved guidelines',
    icon: 'shield-exclamation'
  },
  {
    headers: {
      'Authorization': 'Bearer your_api_key_here',
      'Content-Type': 'application/json'
    }
  }
);

console.log(response.data);
```

```json Response theme={null}
{
  "error": false,
  "msg": "Loop updated successfully",
  "data": {
    "loop": {
      "id": "65f1234567890abcdef12345",
      "name": "Enhanced Content Moderation",
      "description": "Advanced review system for user-generated content with improved guidelines",
      "icon": "shield-exclamation",
      "creator_id": "65f1234567890abcdef12346",
      "members": [
        {
          "user_id": "65f1234567890abcdef12346",
          "email": "creator@example.com",
          "status": "active",
          "joined_at": "2024-03-15T10:30:00Z"
        },
        {
          "user_id": "65f1234567890abcdef12347",
          "email": "reviewer1@example.com",
          "status": "active", 
          "joined_at": "2024-03-15T11:45:00Z"
        }
      ],
      "member_count": 2,
      "pending_count": 0,
      "created_at": "2024-03-15T10:30:00Z",
      "updated_at": "2024-03-15T14:20:00Z"
    }
  }
}
```

## Update Scenarios

### Name Only Update

Update just the loop name:

```json theme={null}
{
  "name": "Content Review V2"
}
```

### Description Only Update

Update just the description:

```json theme={null}
{
  "description": "Updated workflow for reviewing user submissions with new compliance requirements"
}
```

### Icon Only Update

Update just the icon:

```json theme={null}
{
  "icon": "shield-alt"
}
```

### Partial Update

Update multiple fields (but not all):

```json theme={null}
{
  "name": "Premium Content Review",
  "icon": "star"
}
```

## Available Icons

> [card] Security
>
> shield-check, shield-alt, shield-exclamation, lock, key

> [card] Content
>
> document-text, document-check, file-text, clipboard, edit

> [card] Review
>
> eye, search, thumbs-up, thumbs-down, star

> [card] Quality
>
> badge-check, certificate, award, beaker, cog

> [card] Communication
>
> chat, comment, bell, megaphone, mail

> [card] General
>
> folder, tag, flag, bookmark, heart

## Validation Rules

### Name Validation

* **Required**: No (optional for updates)
* **Min length**: 1 character
* **Max length**: 100 characters
* **Allowed**: Letters, numbers, spaces, and basic punctuation

### Description Validation

* **Required**: No (optional for updates)
* **Max length**: 500 characters
* **Allowed**: All characters including newlines

### Icon Validation

* **Required**: No (optional for updates)
* **Format**: String identifier
* **Validation**: Must be a valid icon identifier from available icons

## Use Cases

### Rebranding Loops

Update loop name and icon for rebranding:

```python theme={null}
def rebrand_loop(loop_id, new_name, new_icon):
    url = f"https://api.hitl.sh/v1/api/loops/{loop_id}"
    data = {
        "name": new_name,
        "icon": new_icon
    }
    
    response = requests.put(url, headers=headers, json=data)
    
    if response.status_code == 200:
        loop_data = response.json()["data"]["loop"]
        print(f"Successfully rebranded loop to '{loop_data['name']}'")
        return loop_data
    else:
        print(f"Failed to rebrand loop: {response.json()['msg']}")
        return None
```

### Improving Descriptions

Add more detailed descriptions to existing loops:

```javascript theme={null}
async function improveLoopDescription(loopId, newDescription) {
    try {
        const response = await axios.put(
            `https://api.hitl.sh/v1/api/loops/${loopId}`,
            { description: newDescription },
            { headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' } }
        );
        
        console.log('Description updated successfully');
        return response.data.data.loop;
    } catch (error) {
        console.error('Failed to update description:', error.response?.data?.msg);
        throw error;
    }
}

// Usage
await improveLoopDescription(
    'loopId',
    'Comprehensive content moderation with AI pre-filtering and human oversight for policy violations'
);
```

### Bulk Loop Updates

Update multiple loops with a consistent naming scheme:

```python theme={null}
def standardize_loop_names(loop_prefix="Review"):
    # Get all loops
    loops_response = requests.get("https://api.hitl.sh/v1/api/loops", headers=headers)
    loops = loops_response.json()["data"]["loops"]
    
    updated_loops = []
    for loop in loops:
        # Skip loops that already follow the naming convention
        if loop["name"].startswith(loop_prefix):
            continue
            
        new_name = f"{loop_prefix} - {loop['name']}"
        
        update_response = requests.put(
            f"https://api.hitl.sh/v1/api/loops/{loop['id']}", 
            headers=headers, 
            json={"name": new_name}
        )
        
        if update_response.status_code == 200:
            updated_loops.append(update_response.json()["data"]["loop"])
    
    return updated_loops
```

## Access Control

### Who Can Update Loops

> [accordion] Loop Creators
>
> Only the user who created the loop can update it. This is enforced by checking the `creator_id` against the authenticated user.

> [accordion] API Key Restrictions
>
> API keys can only update loops created by the same user account that owns the API key.

> [accordion] Loop Members
>
> Regular loop members cannot update loop details. They can only participate in reviews.

## Error Handling

### Common Error Scenarios

> [accordion] Loop Not Found
>
> ```json theme={null}
> {
>   "error": true,
>   "msg": "Loop not found"
> }
> ```
>
> **Causes:**
>
> * Invalid loop ID
> * Loop was deleted
> * User doesn't own the loop

> [accordion] Access Denied
>
> ```json theme={null}
> {
>   "error": true,
>   "msg": "Access denied to this loop"
> }
> ```
>
> **Cause:** Only loop creators can update loops.

> [accordion] Validation Error
>
> ```json theme={null}
> {
>   "error": true,
>   "msg": "Validation failed",
>   "data": "name must be between 1 and 100 characters"
> }
> ```
>
> **Causes:**
>
> * Name too long (>100 characters)
> * Name empty (if provided)
> * Description too long (>500 characters)
> * Invalid icon identifier

> [accordion] Empty Update
>
> ```json theme={null}
> {
>   "error": true,
>   "msg": "At least one field must be provided for update"
> }
> ```
>
> **Cause:** Request body is empty or contains no valid update fields.

## Best Practices

### Versioning Updates

Track major changes with version numbers in names:

```python theme={null}
def version_loop_update(loop_id, updates, version=None):
    if version:
        if 'name' in updates:
            updates['name'] = f"{updates['name']} v{version}"
        updates['description'] = f"{updates.get('description', '')} (Updated to v{version})"
    
    return requests.put(f"https://api.hitl.sh/v1/api/loops/{loop_id}", headers=headers, json=updates)
```

### Gradual Updates

Update loops incrementally rather than all at once:

```javascript theme={null}
async function updateLoopGradually(loopId, updates) {
    const updateOrder = ['description', 'icon', 'name']; // Update description first, name last
    
    for (const field of updateOrder) {
        if (updates[field]) {
            await axios.put(
                `https://api.hitl.sh/v1/api/loops/${loopId}`,
                { [field]: updates[field] },
                { headers: { 'Authorization': `Bearer ${apiKey}` } }
            );
            
            // Small delay between updates
            await new Promise(resolve => setTimeout(resolve, 100));
        }
    }
}
```

### Backup Before Updates

Keep a record of previous state:

```python theme={null}
def safe_loop_update(loop_id, updates):
    # Get current state
    current_response = requests.get(f"https://api.hitl.sh/v1/api/loops/{loop_id}", headers=headers)
    backup = current_response.json()["data"]["loop"]
    
    # Perform update
    update_response = requests.put(
        f"https://api.hitl.sh/v1/api/loops/{loop_id}", 
        headers=headers, 
        json=updates
    )
    
    if update_response.status_code == 200:
        return {
            "success": True,
            "updated": update_response.json()["data"]["loop"],
            "backup": backup
        }
    else:
        return {
            "success": False,
            "error": update_response.json()["msg"],
            "backup": backup
        }
```

## Next Steps

> [card] [Delete Loop](https://docs.hitl.sh/api-reference/loops/delete-loop.md)
>
> Learn how to delete loops when they're no longer needed.

> [card] [Manage Members](https://docs.hitl.sh/api-reference/loops/loop-members.md)
>
> Add or remove members from your updated loop.

> [card] [View Loop Requests](https://docs.hitl.sh/api-reference/requests/get-requests.md)
>
> See all requests that have been created within this loop.


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