---
id: DeleteBuyer
name: Delete buyer
version: 1.0.0
badges:
  - content: Customer Management
    backgroundColor: orange
    textColor: orange
summary: Deletes a Buyer profile by identifier; the operation is restricted to administrators.
owners:
  - commerce-fulfillment-team
schemaPath: schema.json
operation:
  method: DELETE
  path: /api/v1/buyers/{id}
  statusCodes: ["204", "404"]
sidebar:
  badge: "DELETE"
---

`DeleteBuyer` permanently removes a [[entity|buyer]] profile from [[service|order-api]] (`DELETE /ordering/api/v1/buyers/{id}`) and returns `204 No Content`. Access is restricted to callers holding the Microsoft Entra ID `admin` role.

## Overview

| Property                           | Value                                                                                                                             |
| :--------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------- |
| **Bounded Context**                | Ordering                                                                                                                          |
| **Owner Service**                  | [[service\|order-api]]                                                                                                            |
| **Protocol / Format**              | HTTP `DELETE`, path parameter only, empty response (`204 No Content`)                                                             |
| **Gateway Endpoint**               | `DELETE /ordering/api/v1/buyers/{id}` (service path `/api/v1/buyers/{id}`)                                                        |
| **Authentication & Authorization** | Microsoft Entra ID JWT — `admin` policy (role `admin` plus scopes `ordering_read`, `ordering_write`)                              |
| **Idempotency / Concurrency**      | Not idempotent across retries; repeat calls return `404 Not Found`; 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

### Path Parameters

Accepts no request body and requires no `x-request-id` header.

| Name | Type              | Required | Constraints                | Description                                      |
| :--- | :---------------- | :------- | :------------------------- | :----------------------------------------------- |
| `id` | `string` (`uuid`) | Yes      | Path parameter; valid UUID | Unique identifier of the buyer profile to delete |

### Success Response (`204 No Content`)

Empty response body confirms the buyer profile was permanently deleted.

## Behavior & Side Effects

- **Permanent hard delete:** Permanently removes the [[entity|buyer]] row from PostgreSQL (unlike orders, buyers are not soft-deleted).
- **No events emitted:** Deleting a buyer raises no domain events and publishes no Kafka integration events.

:::warning
The `orders.buyer_id` foreign key column is non-nullable while the relationship is configured with `ON DELETE SET NULL`. Attempting to delete a buyer who has existing orders will fail at the database layer and return `500 Internal Server Error`.
:::

## Error Responses

| Status / Code               | Condition                                                                           | Client Recovery Action                                                            |
| :-------------------------- | :---------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------- |
| `400 Bad Request`           | Path parameter `{id}` is not a valid UUID                                           | Supply a valid UUID; 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 `admin` role or `ordering_read`/`ordering_write` scopes            | Authenticate with an `admin` token that includes the required scopes              |
| `404 Not Found`             | No buyer profile exists with the specified `{id}`                                   | Verify the buyer identifier; treat as already absent if retrying a prior deletion |
| `429 Too Many Requests`     | Rate limit quota exceeded (`Retry-After` header included)                           | Wait for the `Retry-After` interval before retrying                               |
| `500 Internal Server Error` | Database foreign-key constraint error (e.g., buyer has orders) or unhandled failure | Inspect service logs and check whether dependent orders reference the buyer       |

## Related Documentation

- [[service|order-api]] — Service architecture, persistence, and endpoints.
- [[entity|buyer]] — Buyer aggregate schema and constraints.
- [[command|CreateBuyer]] — Create a buyer profile for the authenticated caller.
- [[command|UpdateAddress]] — Update the authenticated customer's address.

<NodeGraph />

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


 ## Raw Schema:schema.json

{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"title": "DeleteBuyerRequest",
	"description": "Path identifier for the Buyer to delete. The operation has no request body.",
	"type": "string"
}
