# Update Agent Metadata

PATCH https://services.leadconnectorhq.com/agent-studio/agent/{agentId}

Updates agent metadata such as name, description, and status. 

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `agent-studio.write`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `agentId` | string | Yes | Agent ID whose metadata is being updated |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `source` | string | No | Origin channel attributed to this write for auditing (e.g. public_api, internal) |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/agent-studio/agent/{agentId}": {
      "patch": {
        "summary": "Update Agent Metadata",
        "operationId": "updateAgentMetadata",
        "description": "Updates agent metadata such as name, description, and status. ",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "agentId",
            "required": true,
            "in": "path",
            "schema": {
              "type": "string"
            },
            "example": "p1q2r3s4t5u6v7w8x9y0z1a2",
            "description": "Agent ID whose metadata is being updated"
          },
          {
            "name": "source",
            "required": false,
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "api",
            "description": "Origin channel attributed to this write for auditing (e.g. public_api, internal)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdatePublicAgentMetadataDTO"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Agent metadata updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdatePublicAgentResponseDTO"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "404": {
            "description": "Agent not found"
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InternalServerErrorDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "agent-studio.write"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "UpdatePublicAgentMetadataDTO": {
        "type": "object",
        "properties": {
          "locationId": {
            "type": "string",
            "description": "Location ID for authorization (cannot be updated)",
            "example": "C2QujeCh8ZnC7al2InWR"
          },
          "name": {
            "type": "string",
            "description": "Name of the agent",
            "example": "Updated Customer Support Agent"
          },
          "description": {
            "type": "string",
            "description": "Description of the agent",
            "example": "Updated AI agent with enhanced customer support capabilities"
          },
          "status": {
            "type": "string",
            "description": "Status of the agent",
            "example": "active",
            "enum": [
              "active",
              "inactive",
              "archived"
            ]
          }
        },
        "required": [
          "locationId"
        ],
        "title": "UpdatePublicAgentMetadataDTO"
      },
      "UpdatePublicAgentResponseDTO": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "Success status",
            "example": true
          },
          "message": {
            "type": "string",
            "description": "Response message",
            "example": "Agent updated successfully"
          },
          "data": {
            "type": "object",
            "description": "Updated agent or version data",
            "example": {
              "agentId": "p1q2r3s4t5u6v7w8x9y0z1a2",
              "versionId": "v1a2b3c4d5e6f7g8h9i0",
              "name": "Updated Customer Support Agent",
              "description": "Updated AI agent with enhanced customer support capabilities",
              "status": "active",
              "updatedAt": "2024-02-27T11:45:00.000Z"
            }
          }
        },
        "required": [
          "success",
          "message",
          "data"
        ],
        "title": "UpdatePublicAgentResponseDTO"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      },
      "InternalServerErrorDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 500,
            "description": "HTTP status code"
          },
          "message": {
            "type": "string",
            "example": "Internal Server Error",
            "description": "Error message"
          }
        },
        "title": "InternalServerErrorDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X PATCH 'https://services.leadconnectorhq.com/agent-studio/agent/<agentId>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "locationId": "C2QujeCh8ZnC7al2InWR",
  "name": "Updated Customer Support Agent",
  "description": "Updated AI agent with enhanced customer support capabilities",
  "status": "active"
}'
```

**Node.js**

```javascript
const options = {
  method: 'PATCH',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "locationId": "C2QujeCh8ZnC7al2InWR",
      "name": "Updated Customer Support Agent",
      "description": "Updated AI agent with enhanced customer support capabilities",
      "status": "active"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/agent-studio/agent/<agentId>', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/agent-studio/agent/{agentId}"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

payload = {
    "locationId": "C2QujeCh8ZnC7al2InWR",
    "name": "Updated Customer Support Agent",
    "description": "Updated AI agent with enhanced customer support capabilities",
    "status": "active"
}

response = requests.patch(url, json=payload, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/agent-studio/agent/<agentId>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'PATCH',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "locationId": "C2QujeCh8ZnC7al2InWR",
  "name": "Updated Customer Support Agent",
  "description": "Updated AI agent with enhanced customer support capabilities",
  "status": "active"
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .patch("https://services.leadconnectorhq.com/agent-studio/agent/<agentId>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"locationId\":\"C2QujeCh8ZnC7al2InWR\",\"name\":\"Updated Customer Support Agent\",\"description\":\"Updated AI agent with enhanced customer support capabilities\",\"status\":\"active\"}")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
  "strings"
)

func main() {
  url := "https://services.leadconnectorhq.com/agent-studio/agent/<agentId>"
  payload := strings.NewReader(`{
  "locationId": "C2QujeCh8ZnC7al2InWR",
  "name": "Updated Customer Support Agent",
  "description": "Updated AI agent with enhanced customer support capabilities",
  "status": "active"
}`)
  req, _ := http.NewRequest("PATCH", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/agent-studio/agent/<agentId>")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Patch.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "locationId": "C2QujeCh8ZnC7al2InWR",
  "name": "Updated Customer Support Agent",
  "description": "Updated AI agent with enhanced customer support capabilities",
  "status": "active"
}'

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "locationId": "C2QujeCh8ZnC7al2InWR",
  "name": "Updated Customer Support Agent",
  "description": "Updated AI agent with enhanced customer support capabilities",
  "status": "active"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/agent-studio/agent/<agentId>' -Method 'PATCH' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
