# Update a field agent profile

Operation ID: `fieldagent.updateAgent`

Patch mutable fields on the caller's own field-agent profile by FHIR Person ID. Only the fields UpdateAgentRequest declares are ever written; any other body key is silently ignored. Only the agent themselves may update their own profile.

## Public method

`updateAgent`

Signature: `fieldAgent.updateAgent(fhirPersonId, request)`

Return type: `Promise<FieldAgentResponse>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`PATCH /agents/{agent_id}`

## Path parameters

| Name | Type | Required | Format | Allowed values | Default | Nullable | Description |
|---|---|---:|---|---|---|---:|---|
| `agent_id` | `string` | Yes |  |  |  | No |  |

## Query parameters

None.

## Body parameters

| Name | Type | Required | Format | Allowed values | Default | Nullable | Description |
|---|---|---:|---|---|---|---:|---|
| `body` | [`UpdateAgentRequest`](../models/UpdateAgentRequest.md) | No |  |  |  | Yes |  |

Request model: [`UpdateAgentRequest`](../models/UpdateAgentRequest.md)

## Request example

```json
{
  "address": {
    "city": "Springfield",
    "country": "US",
    "is_primary": true,
    "state": "IL",
    "street1": "100 Health Avenue",
    "street2": "Suite 200",
    "type": "work",
    "zip_code": "62701"
  },
  "badge_number": "BADGE-1001",
  "department": "Field Operations",
  "first_name": "Alex",
  "last_name": "Smith",
  "license_number": "LIC-IL-1001",
  "organization": "HealthCloud Community Care",
  "phone": "+15550100000",
  "title": "Senior Field Agent"
}
```

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `200` | [`FieldAgentProfileResponse`](../models/FieldAgentProfileResponse.md) | application/json | Updated field-agent profile |

## Success response examples

### 200

```json
{
  "address": {
    "city": "Springfield",
    "country": "US",
    "is_primary": true,
    "state": "IL",
    "street1": "100 Health Avenue",
    "street2": "Suite 200",
    "type": "work",
    "zip_code": "62701"
  },
  "agent_id": "agent-example-001"
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `400` | [`fieldagent.ErrorResponse`](../models/fieldagent.ErrorResponse.md) | application/json | No updatable field was supplied |
| `401` | [`fieldagent.ErrorResponse`](../models/fieldagent.ErrorResponse.md) | application/json | Authorization required — missing or invalid Bearer JWT |
| `403` | [`fieldagent.ErrorResponse`](../models/fieldagent.ErrorResponse.md) | application/json | The authenticated caller does not own this agent profile |
| `404` | [`fieldagent.ErrorResponse`](../models/fieldagent.ErrorResponse.md) | application/json | No agent profile exists for the given agent_id |
| `500` | [`fieldagent.ErrorResponse`](../models/fieldagent.ErrorResponse.md) | application/json | Internal server error |

## Error examples

### 400 — Body contained none of the updatable fields

```json
{
  "error": "No updatable fields provided"
}
```

### 401 — Missing or invalid access token

```json
{
  "error": "Authorization required"
}
```

### 403 — The JWT caller's cognito_sub does not match the agent's

```json
{
  "error": "You may only access your own agent profile"
}
```

### 404 — No FHIR Person exists for agent_id

```json
{
  "error": "Agent not found"
}
```

### 500 — Unexpected service failure (sanitized example)

```json
{
  "error": "Internal server error"
}
```

## NodeJS / TypeScript implementation

```ts
import { HCSDK } from "@healthcloudai/hc-sdk";
import type { UpdateFieldAgentRequest } from "@healthcloudai/hc-sdk";
```

```ts
const fhirPersonId = "<FHIR_PERSON_ID>";

const request = {
  "address": {
    "city": "Springfield",
    "country": "US",
    "is_primary": true,
    "state": "IL",
    "street1": "100 Health Avenue",
    "street2": "Suite 200",
    "type": "work",
    "zip_code": "62701"
  },
  "badge_number": "BADGE-1001",
  "department": "Field Operations",
  "first_name": "Alex",
  "last_name": "Smith",
  "license_number": "LIC-IL-1001",
  "organization": "HealthCloud Community Care",
  "phone": "+15550100000",
  "title": "Senior Field Agent"
};

const result = await fieldAgent.updateAgent(fhirPersonId, request);
```

## cURL

```bash
curl -X PATCH \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{"address":{"city":"Springfield","country":"US","is_primary":true,"state":"IL","street1":"100 Health Avenue","street2":"Suite 200","type":"work","zip_code":"62701"},"badge_number":"BADGE-1001","department":"Field Operations","first_name":"Alex","last_name":"Smith","license_number":"LIC-IL-1001","organization":"HealthCloud Community Care","phone":"+15550100000","title":"Senior Field Agent"}' \
  'https://dev-api-fieldagent.health.cloud/agents/%3CAGENT_ID%3E'
```

## Notes

None.

## Prepared Test Console scenario

No canonical scenario is currently associated.

## Real response

No approved real integration response is currently published. Unapproved candidates are never rendered as examples.
