# Register a field agent

Operation ID: `fieldagent.register`

Create a Cognito user with role=field_agent and a matching FHIR Person resource. Unless the deployment sets AUTO_VERIFY_EMAIL=true, the account starts unverified and an email OTP is sent — call fieldagent.verifyEmail before fieldagent.login will treat the account as fully onboarded. When AUTO_VERIFY_EMAIL=true, the email is verified immediately and this call attempts an automatic login; on success the response also carries access_token/id_token/expires_in so the agent can skip a separate login.

## Public method

`register`

Signature: `fieldAgent.register(request)`

Return type: `Promise<RegisterFieldAgentResponse>`

## Authentication

Classification: **PUBLIC**

## Prerequisites

None documented.

## HTTP

`POST /auth/register`

## Path parameters

None.

## Query parameters

None.

## Body parameters

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

Request model: [`fieldagent.RegisterRequest`](../models/fieldagent.RegisterRequest.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",
  "date_of_birth": "1985-06-15",
  "department": "Field Operations",
  "email": "test.user@example.com",
  "first_name": "Alex",
  "gender": "unknown",
  "last_name": "Smith",
  "license_number": "LIC-IL-1001",
  "organization": "HealthCloud Community Care",
  "password": "PasswordTest1234$",
  "phone": "+15550100000",
  "race": "white",
  "tenant_id": "tenant-example-001",
  "title": "Senior Field Agent"
}
```

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `201` | [`fieldagent.RegisterResponse`](../models/fieldagent.RegisterResponse.md) | application/json | Field Agent registered |

## Success response examples

### 201

```json
{
  "access_token": "string",
  "cognito_sub": "string",
  "email_otp_sent": true,
  "email_verified": true,
  "expires_in": 0,
  "fhir_person_id": "string",
  "id_token": "string",
  "person_type": "field_agent"
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `400` | [`fieldagent.ErrorResponse`](../models/fieldagent.ErrorResponse.md) | application/json | Required fields are missing, invalid, or Cognito/FHIR rejected the registration |

## Error examples

### 400 — Required fields are missing

```json
{
  "error": "tenant_id, first_name, last_name, email and password are required"
}
```

### 400 — Password does not meet the minimum length

```json
{
  "error": "password must be at least 8 characters"
}
```

## NodeJS / TypeScript implementation

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

```ts
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",
  "date_of_birth": "1985-06-15",
  "department": "Field Operations",
  "email": "test.user@example.com",
  "first_name": "Alex",
  "gender": "unknown",
  "last_name": "Smith",
  "license_number": "LIC-IL-1001",
  "organization": "HealthCloud Community Care",
  "password": "PasswordTest1234$",
  "phone": "+15550100000",
  "race": "white",
  "tenant_id": "tenant-example-001",
  "title": "Senior Field Agent"
};

const result = await fieldAgent.register(request);
```

## cURL

```bash
curl -X POST \
  -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","date_of_birth":"1985-06-15","department":"Field Operations","email":"test.user@example.com","first_name":"Alex","gender":"unknown","last_name":"Smith","license_number":"LIC-IL-1001","organization":"HealthCloud Community Care","password":"PasswordTest1234$","phone":"+15550100000","race":"white","tenant_id":"tenant-example-001","title":"Senior Field Agent"}' \
  'https://dev-api-fieldagent.health.cloud/auth/register'
```

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