---
id: GetBasket
name: Get basket
version: 1.0.0
badges:
  - content: Order Lifecycle
    backgroundColor: blue
    textColor: blue
summary: Returns the current basket and its item details.
owners:
  - commerce-fulfillment-team
schemaPath: schema.json
operation:
  method: GET
  path: /api/v1/baskets
  statusCodes: ["200", "404"]
sidebar:
  badge: "GET"
---

`GetBasket` retrieves the authenticated customer's active basket from [[service|basket-api]] (`GET /basket/api/v1/baskets`) and enriches non-empty basket items with live titles and pricing from [[service|catalog-api]] over gRPC. The caller's customer identity is resolved from the Microsoft Entra ID access token; no basket identifier parameter is accepted.

## Overview

| Property                           | Value                                                                                                                             |
| :--------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------- |
| **Bounded Context**                | Shopping                                                                                                                          |
| **Owner Service**                  | [[service\|basket-api]]                                                                                                           |
| **Protocol / Format**              | HTTP `GET`, `application/json` response                                                                                           |
| **Gateway Endpoint**               | `GET /basket/api/v1/baskets` (service path `/api/v1/baskets`)                                                                     |
| **Authentication & Authorization** | Microsoft Entra ID JWT — `customer` role plus scopes `basket_read`, `basket_write`                                                |
| **Idempotency / Concurrency**      | Read-only and naturally idempotent                                                                                                |
| **Rate Limit / Caching**           | Global concurrency (`100`), per-IP fixed-window (`30 req/min`), and per-user token bucket (`30` limit, `20` per `10s`, queue `5`) |
| **Contract Version**               | `1.0.0` (`ApiVersions.V1`)                                                                                                        |

## Request & Response Contract

### Request Parameters

Accepts no path parameters, query parameters, or request body; resolves the customer ID from the authenticated token.

### Success Response (`200 OK`)

| Name                | Type                       | Required | Constraints           | Description                                                                                 |
| :------------------ | :------------------------- | :------- | :-------------------- | :------------------------------------------------------------------------------------------ |
| `id`                | `string \| null`           | Yes      | —                     | Identifier of the customer's basket                                                         |
| `items`             | `object[]`                 | Yes      | Array (may be empty)  | Line items currently stored in the basket                                                   |
| `items[].id`        | `string \| null`           | Yes      | —                     | Catalog book identifier                                                                     |
| `items[].quantity`  | `integer \| string`        | Yes      | `int32`               | Requested unit quantity                                                                     |
| `items[].name`      | `string \| null`           | No       | Nullable              | Book title enriched from [[service\|catalog-api]] (`null` when unavailable)                 |
| `items[].price`     | `number \| string`         | No       | `double`, default `0` | Regular unit price enriched from [[service\|catalog-api]]                                   |
| `items[].priceSale` | `number \| string \| null` | No       | `double` or `null`    | Promotional sale price enriched from [[service\|catalog-api]] (`null` when no sale applies) |

## Behavior & Side Effects

- **Read-time catalog enrichment:** Reads basket state from Redis and, when `items` is non-empty, deduplicates book IDs and enriches items via [[query|GetBooksGrpc]].
- **No state mutation:** Pure read query with no database writes or integration events.

## Error Responses

| Status / Code           | Condition                                                                           | Client Recovery Action                                                |
| :---------------------- | :---------------------------------------------------------------------------------- | :-------------------------------------------------------------------- |
| `401 Unauthorized`      | Missing, expired, or invalid Entra ID bearer token                                  | Re-authenticate the customer and retry                                |
| `403 Forbidden`         | Principal lacks the `customer` role or required `basket_read`/`basket_write` scopes | Request a token with the required customer scopes                     |
| `404 Not Found`         | No active basket exists in Redis for the authenticated customer                     | Treat as an empty/uninitialized basket until the customer creates one |
| `429 Too Many Requests` | Rate limit quota exceeded (`Retry-After` header included)                           | Wait for the `Retry-After` duration before retrying                   |

## Related Documentation

- [[service|basket-api]] — Service overview, Redis persistence, and endpoints.
- [[entity|basket]] — Basket entity model.
- [[query|GetBasketGrpc]] — Internal gRPC contract used by [[service|order-api]] during checkout.
- [[query|GetBooksGrpc]] — Batch gRPC book lookup used to enrich basket items.
- [[command|CreateBasket]] — Create a new customer basket.

<NodeGraph />

<SchemaViewer file="schema.json" title="Get basket schema" maxHeight="500" search="true" />


 ## Raw Schema:schema.json

{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"title": "CustomerBasketDto",
	"type": "object",
	"required": ["id", "items"],
	"properties": {
		"id": {
			"type": ["string", "null"]
		},
		"items": {
			"type": "array",
			"items": {
				"type": "object",
				"required": ["id", "quantity"],
				"properties": {
					"id": {
						"type": ["string", "null"]
					},
					"quantity": {
						"type": ["integer", "string"],
						"format": "int32",
						"pattern": "^-?(?:0|[1-9]\\d*)$"
					},
					"name": {
						"type": ["string", "null"]
					},
					"price": {
						"type": ["number", "string"],
						"format": "double",
						"pattern": "^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?$",
						"default": 0
					},
					"priceSale": {
						"type": ["number", "string", "null"],
						"format": "double",
						"pattern": "^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?$"
					}
				}
			}
		}
	}
}
