---
id: UpdateAddress
name: Update buyer address
version: 1.0.0
badges:
  - content: Customer Management
    backgroundColor: orange
    textColor: orange
summary: Updates the authenticated Buyer's address using the supplied street, city, and province.
owners:
  - commerce-fulfillment-team
schemaPath: schema.json
operation:
  method: PATCH
  path: /api/v1/buyers/address
  statusCodes: ["200", "400", "404"]
sidebar:
  badge: "PATCH"
---

`UpdateAddress` replaces the shipping address on the authenticated customer's [[entity|buyer]] profile in [[service|order-api]] (`PATCH /ordering/api/v1/buyers/address`) and returns the updated buyer profile. Access is restricted strictly to the Microsoft Entra ID `customer` role (administrators cannot invoke this endpoint on another user's behalf).

## Overview

| Property                           | Value                                                                                                                             |
| :--------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------- |
| **Bounded Context**                | Ordering                                                                                                                          |
| **Owner Service**                  | [[service\|order-api]]                                                                                                            |
| **Protocol / Format**              | HTTP `PATCH`, `application/json` request and response                                                                             |
| **Gateway Endpoint**               | `PATCH /ordering/api/v1/buyers/address` (service path `/api/v1/buyers/address`)                                                   |
| **Authentication & Authorization** | Microsoft Entra ID JWT — `customer` policy only (role `customer` plus scopes `ordering_read`, `ordering_write`)                   |
| **Idempotency / Concurrency**      | Naturally idempotent full address replacement; no `x-request-id` header is required                                               |
| **Rate Limit / Caching**           | Global concurrency (`100`), per-IP fixed-window (`30 req/min`), and per-user token bucket (`30` burst, `20` per `10s`, queue `5`) |
| **Contract Version**               | `1.0.0` (`ApiVersions.V1`)                                                                                                        |

## Request & Response Contract

### Request Body (`application/json`)

All three address fields are required together to replace the address value object.

| Name       | Type     | Required | Constraints                                          | Description               |
| :--------- | :------- | :------- | :--------------------------------------------------- | :------------------------ |
| `street`   | `string` | Yes      | Non-empty, max `50` characters; PII-redacted in logs | Updated street address    |
| `city`     | `string` | Yes      | Non-empty, max `50` characters; PII-redacted in logs | Updated city or district  |
| `province` | `string` | Yes      | Non-empty, max `50` characters; PII-redacted in logs | Updated province or state |

### Success Response (`200 OK`)

| Name      | Type              | Required | Constraints                                                         | Description                              |
| :-------- | :---------------- | :------- | :------------------------------------------------------------------ | :--------------------------------------- |
| `id`      | `string` (`uuid`) | Yes      | Valid UUID                                                          | Identifier of the authenticated buyer    |
| `name`    | `string \| null`  | No       | PII-redacted in logs                                                | Buyer display name stored on the profile |
| `address` | `string \| null`  | No       | Formatted as `"{Street}, {City}, {Province}"`; PII-redacted in logs | Formatted full address                   |

## Behavior & Side Effects

- **Session-bound lookup:** Derives the buyer ID from the authenticated user's `NameIdentifier` claim (no buyer ID is accepted in the route or body). Returns `404 Not Found` if no profile exists yet; callers must first create a profile via [[command|CreateBuyer]].
- **Atomic address replacement:** Replaces the address value object inside a database transaction; emits no domain or integration events.
- **PII redaction:** Request address fields and response `name`/`address` fields are automatically redacted in structured logs.

## Error Responses

| Status / Code               | Condition                                                                                                         | Client Recovery Action                                       |
| :-------------------------- | :---------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------- |
| `400 Bad Request`           | Empty/whitespace address field, field exceeding `50` characters, or non-UUID `NameIdentifier` claim               | Fix the request body or token claims; do not retry unchanged |
| `401 Unauthorized`          | Missing, expired, or invalid Entra ID bearer token                                                                | Acquire a fresh Entra ID access token and retry              |
| `403 Forbidden`             | Caller lacks the `customer` role (including `admin`-only tokens) or lacks `ordering_read`/`ordering_write` scopes | Authenticate as a `customer` with the required scopes        |
| `404 Not Found`             | Authenticated caller does not have an existing buyer profile                                                      | Create the profile first using [[command\|CreateBuyer]]      |
| `429 Too Many Requests`     | Rate limit quota exceeded (`Retry-After` header included)                                                         | Wait for the `Retry-After` interval before retrying          |
| `500 Internal Server Error` | Unhandled database or server failure                                                                              | Retry with backoff and inspect service logs                  |

## Related Documentation

- [[service|order-api]] — Service architecture, persistence, and endpoints.
- [[entity|buyer]] — Buyer aggregate schema and address value object.
- [[command|CreateBuyer]] — Create a buyer profile before updating its address.
- [[command|DeleteBuyer]] — Administrative permanent removal of a buyer profile.

<NodeGraph />

<SchemaViewer
	file="schema.json"
	title="Update buyer address schema"
	maxHeight="500"
	search="true"
/>


 ## Raw Schema:schema.json

{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"title": "UpdateAddressCommand",
	"description": "Address fields required to update the authenticated Buyer's address.",
	"type": "object",
	"required": ["street", "city", "province"],
	"properties": {
		"street": {
			"type": "string"
		},
		"city": {
			"type": "string"
		},
		"province": {
			"type": "string"
		}
	}
}
