# Upload a field agent photo

Operation ID: `fieldagent.uploadAgentPhoto`

Store a base64-encoded photo as a FHIR Binary resource for the authenticated field agent, and stamp a photo_binary_id extension on the agent's Person resource so fieldagent.getAgentPhoto can find it without a binary_id. Only the agent themselves may upload their own photo. This is independent of fieldagent.agentPhotoUploadUrl's presigned-URL flow — the two write to different storage and are not sequenced.

## Public method

`uploadPhoto`

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

Return type: `Promise<PhotoUploadResponse>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`POST /agents/{agent_id}/photo`

## 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` | [`UploadAgentPhotoRequest`](../models/UploadAgentPhotoRequest.md) | No |  |  |  | Yes |  |

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

## Request example

```json
{
  "content_type": "image/png",
  "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
}
```

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `201` | [`UploadAgentPhotoResponse`](../models/UploadAgentPhotoResponse.md) | application/json | Field Agent photo stored |

## Success response examples

### 201

```json
{
  "binary_id": "photo-example-001"
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `400` | [`fieldagent.ErrorResponse`](../models/fieldagent.ErrorResponse.md) | application/json | The base64 photo data was not 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 — Required body field is missing

```json
{
  "error": "data (base64) is required"
}
```

### 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 { PhotoUploadRequest } from "@healthcloudai/hc-sdk";
```

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

const request = {
  "content_type": "image/png",
  "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
};

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

## cURL

```bash
curl -X POST \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{"content_type":"image/png","data":"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="}' \
  'https://dev-api-fieldagent.health.cloud/agents/%3CAGENT_ID%3E/photo'
```

## 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.
