# AS4 Settlement API Reference

**Date**: 2026-01-19  
**Version**: 1.0.0

---

## Base URL

```
http://localhost:3000/api/v1/as4
```

---

## Authentication

All endpoints (except metrics) require authentication:

```
Authorization: Bearer <token>
```

---

## Endpoints

### AS4 Gateway

#### POST /gateway/messages
Receive AS4 message

**Request**:
```json
{
  "messageId": "MSG-001",
  "fromMemberId": "MEMBER-001",
  "toMemberId": "DBIS",
  "businessType": "DBIS.SI.202",
  "payload": "...",
  "tlsCertFingerprint": "...",
  "properties": {}
}
```

**Response**: `202 Accepted`

---

### Member Directory

#### GET /directory/members/:memberId
Get member by ID

**Response**: `200 OK` with member record

#### GET /directory/members
Search members

**Query Parameters**:
- `status` - Filter by status
- `capacityTier` - Filter by tier
- `routingGroup` - Filter by routing group

#### POST /directory/members
Register new member

**Request**:
```json
{
  "memberId": "MEMBER-001",
  "organizationName": "Test Bank",
  "as4EndpointUrl": "https://...",
  "tlsCertFingerprint": "...",
  "allowedMessageTypes": ["DBIS.SI.202"],
  "routingGroups": ["DEFAULT"]
}
```

#### GET /directory/members/:memberId/certificates
Get member certificates

#### POST /directory/members/:memberId/certificates
Add certificate

---

### Settlement

#### POST /settlement/instructions
Submit settlement instruction

**Request**:
```json
{
  "fromMemberId": "MEMBER-001",
  "payloadHash": "...",
  "message": { ... }
}
```

#### GET /settlement/instructions/:instructionId
Get instruction status

#### GET /settlement/postings/:postingId
Get posting status

#### GET /settlement/statements
Generate statement

**Query Parameters**:
- `memberId` - Member ID
- `accountId` - Account ID
- `startDate` - Start date
- `endDate` - End date

#### GET /settlement/audit/:instructionId
Export audit trail

---

### Metrics

#### GET /metrics
Prometheus metrics (public endpoint)

#### GET /metrics/health
Health check with metrics summary

---

**For detailed API documentation, see Swagger UI**: `/api-docs`
