Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(openapi): publish the catalog response schemas

Yudhi Armyndharis3e4d0610a1d2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2643b6a72..1db2b53e7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
+- **The catalog endpoints now publish the shape of what they return, including one that disagrees with the rest of the API** — `POST /messages/send-product` answers `{id, timestamp}` while every send served by the message module answers `{messageId, timestamp}` for the same value, because this route passes the engine result through unmapped; the schema records the field the code actually sends rather than the one the neighbouring routes use. `send-catalog` is left with no success schema on purpose: no engine can send a catalog link, so a 2xx there would document a response that cannot occur.
- **The ten contacts endpoints now publish the shape of what they return** — they documented a status and a sentence but no schema, so the committed OpenAPI snapshot had nothing to diff for any of them and a change to a response body could reach clients without the contract gate noticing; `GET /contacts/{contactId}/phone` returning `null` for an unresolvable id, and the batch picture lookup answering `null` per id rather than failing, are now stated rather than discovered by calling.
- **Fourteen more boolean environment variables are now validated at boot** — they are read with a bare `=== 'true'` / `!== 'false'` comparison, so a spelling like `DATABASE_SSL=require` silently configured the opposite of what was asked for; `DATABASE_SSL` in particular read as OFF and sent credentials in plaintext to a server the operator believed was TLS-protected. Only `true`/`false` (or blank) are accepted now, so a deployment using another spelling will fail startup until it is corrected. `MCP_READONLY` and `PUPPETEER_HEADLESS` stay tolerant deliberately — both fail toward the safe state.
- **The API description now documents the two statuses middleware returns before routing** — `415` for a compressed request body and `503` with `Retry-After` when too much body data is already in flight, neither of which appeared anywhere in the OpenAPI document despite applying to every operation.
diff --git a/openapi.json b/openapi.json
index 9c23b7e3f..d6414cabc 100644
--- a/openapi.json
+++ b/openapi.json
@@ -5955,6 +5955,16 @@
}
],
"responses": {
+ "200": {
+ "description": "Catalog summary, or an empty body when the account has no collection to describe.",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/CatalogDto"
+ }
+ }
+ }
+ },
"501": {
"description": "Not supported by the active engine: whatsapp-web.js has no catalog API."
},
@@ -6004,6 +6014,16 @@
}
],
"responses": {
+ "200": {
+ "description": "One page of catalog products",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/PaginatedProductsDto"
+ }
+ }
+ }
+ },
"501": {
"description": "Not supported by the active engine: whatsapp-web.js has no catalog API."
},
@@ -6039,6 +6059,16 @@
}
],
"responses": {
+ "200": {
+ "description": "The product, or an empty body when no product in the catalog carries that id.",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ProductDto"
+ }
+ }
+ }
+ },
"501": {
"description": "Not supported by the active engine: whatsapp-web.js has no catalog API."
},
@@ -6076,6 +6106,16 @@
}
},
"responses": {
+ "201": {
+ "description": "Product message accepted for sending",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ProductMessageResponseDto"
+ }
+ }
+ }
+ },
"400": {
"description": "Product has no image — a product card requires one."
},
@@ -9892,6 +9932,154 @@
}
}
},
+ "CatalogDto": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "Catalog id. Synthesized from the first collection — the only named grouping the engine exposes.",
+ "example": "1234567890123456"
+ },
+ "name": {
+ "type": "string",
+ "description": "Collection name.",
+ "example": "Default"
+ },
+ "description": {
+ "type": "string",
+ "description": "Collection description, when the engine reports one."
+ },
+ "productCount": {
+ "type": "number",
+ "description": "How many products the first collection holds.",
+ "example": 12
+ },
+ "url": {
+ "type": "string",
+ "description": "Public catalog link for the account.",
+ "example": "https://wa.me/c/628123456789"
+ }
+ },
+ "required": [
+ "id",
+ "name",
+ "productCount",
+ "url"
+ ]
+ },
+ "ProductDto": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "Product id in the engine's native format.",
+ "example": "7891234567890"
+ },
+ "name": {
+ "type": "string",
+ "description": "Product name.",
+ "example": "Kopi Gayo 200g"
+ },
+ "description": {
+ "type": "string",
+ "description": "Product description, when set."
+ },
+ "price": {
+ "type": "number",
+ "description": "Price in the currency’s minor-unit-free numeric form.",
+ "example": 85000
+ },
+ "currency": {
+ "type": "string",
+ "description": "ISO currency code.",
+ "example": "IDR"
+ },
+ "priceFormatted": {
+ "type": "string",
+ "description": "Price rendered for display. Synthesized by the gateway from price + currency, so an unrecognised currency code falls back to a plain \"CODE amount\" pair.",
+ "example": "IDR 85,000.00"
+ },
+ "imageUrl": {
+ "type": "string",
+ "description": "First product image URL. Absent when the product carries no image.",
+ "example": "https://pps.whatsapp.net/v/t61.24694-24/12345_678_910_n.jpg"
+ },
+ "url": {
+ "type": "string",
+ "description": "Product link, empty when the engine reports none.",
+ "example": "https://wa.me/p/123/628"
+ },
+ "isAvailable": {
+ "type": "boolean",
+ "description": "Whether the engine reports the product as in stock.",
+ "example": true
+ },
+ "retailerId": {
+ "type": "string",
+ "description": "The merchant's own SKU, when set.",
+ "example": "SKU-001"
+ }
+ },
+ "required": [
+ "id",
+ "name",
+ "price",
+ "currency",
+ "priceFormatted",
+ "url",
+ "isAvailable"
+ ]
+ },
+ "ProductPaginationDto": {
+ "type": "object",
+ "properties": {
+ "page": {
+ "type": "number",
+ "description": "Page that was returned (1-based).",
+ "example": 1
+ },
+ "limit": {
+ "type": "number",
+ "description": "Page size that was applied.",
+ "example": 20
+ },
+ "total": {
+ "type": "number",
+ "description": "Total products in the catalog, not on this page.",
+ "example": 12
+ },
+ "totalPages": {
+ "type": "number",
+ "description": "Total pages at this page size.",
+ "example": 1
+ }
+ },
+ "required": [
+ "page",
+ "limit",
+ "total",
+ "totalPages"
+ ]
+ },
+ "PaginatedProductsDto": {
+ "type": "object",
+ "properties": {
+ "products": {
+ "description": "Products on the requested page.",
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/ProductDto"
+ }
+ },
+ "pagination": {
+ "$ref": "#/components/schemas/ProductPaginationDto"
+ }
+ },
+ "required": [
+ "products",
+ "pagination"
+ ]
+ },
"SendProductDto": {
"type": "object",
"properties": {
@@ -9916,6 +10104,25 @@
"productId"
]
},
+ "ProductMessageResponseDto": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "The message id, assigned when the gateway accepts the message for sending. Note the field name: the send routes served by MessageService answer `messageId` for the same value. A 2xx here means the message was handed to the WhatsApp client, not that it was delivered.",
+ "example": "[email protected]_3EB0123456789"
+ },
+ "timestamp": {
+ "type": "number",
+ "description": "Unix SECONDS the engine stamped on the outgoing message.",
+ "example": 1786000000
+ }
+ },
+ "required": [
+ "id",
+ "timestamp"
+ ]
+ },
"SendCatalogDto": {
"type": "object",
"properties": {
diff --git a/src/modules/catalog/catalog.controller.ts b/src/modules/catalog/catalog.controller.ts
index cfb83956d..fc96fe66c 100644
--- a/src/modules/catalog/catalog.controller.ts
+++ b/src/modules/catalog/catalog.controller.ts
@@ -4,6 +4,7 @@ import { CatalogService } from './catalog.service';
import { SendProductDto, SendCatalogDto, ProductQueryDto } from './dto/send-product.dto';
import { RequireRole } from '../auth/decorators/auth.decorators';
import { ApiKeyRole } from '../auth/entities/api-key.entity';
+import { CatalogDto, PaginatedProductsDto, ProductDto, ProductMessageResponseDto } from './dto/catalog-response.dto';
/**
* Every catalog read walks WhatsApp's business-catalog IQ, which the server simply leaves
@@ -19,6 +20,11 @@ export class CatalogController {
@Get('catalog')
@ApiOperation({ summary: 'Get business catalog info (Baileys engine only)' })
+ @ApiResponse({
+ status: 200,
+ description: 'Catalog summary, or an empty body when the account has no collection to describe.',
+ type: CatalogDto,
+ })
@ApiResponse({
status: 501,
description: 'Not supported by the active engine: whatsapp-web.js has no catalog API.',
@@ -30,6 +36,7 @@ export class CatalogController {
@Get('catalog/products')
@ApiOperation({ summary: 'List catalog products (Baileys engine only)' })
+ @ApiResponse({ status: 200, description: 'One page of catalog products', type: PaginatedProductsDto })
@ApiResponse({
status: 501,
description: 'Not supported by the active engine: whatsapp-web.js has no catalog API.',
@@ -41,6 +48,11 @@ export class CatalogController {
@Get('catalog/products/:productId')
@ApiOperation({ summary: 'Get a specific product (Baileys engine only)' })
+ @ApiResponse({
+ status: 200,
+ description: 'The product, or an empty body when no product in the catalog carries that id.',
+ type: ProductDto,
+ })
@ApiResponse({
status: 501,
description: 'Not supported by the active engine: whatsapp-web.js has no catalog API.',
@@ -53,6 +65,7 @@ export class CatalogController {
@Post('messages/send-product')
@RequireRole(ApiKeyRole.OPERATOR)
@ApiOperation({ summary: 'Send a product message (Baileys engine only)' })
+ @ApiResponse({ status: 201, description: 'Product message accepted for sending', type: ProductMessageResponseDto })
@ApiResponse({ status: 404, description: 'Product id not found in the session catalog.' })
@ApiResponse({ status: 400, description: 'Product has no image — a product card requires one.' })
@ApiResponse({
diff --git a/src/modules/catalog/dto/catalog-response.dto.ts b/src/modules/catalog/dto/catalog-response.dto.ts
new file mode 100644
index 000000000..8b6b7372f
--- /dev/null
+++ b/src/modules/catalog/dto/catalog-response.dto.ts
@@ -0,0 +1,112 @@
+import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
+
+/**
+ * Response shapes for the catalog routes. These describe what the handlers already return — the
+ * payload is the raw handler value, not an envelope — so that a change to the shape shows up as a
+ * diff in the committed OpenAPI snapshot instead of reaching clients unannounced.
+ *
+ * Decorated properties avoid named utility types: emitDecoratorMetadata wraps a named type in a
+ * runtime guard whose other arm can never execute, leaving an uncoverable branch.
+ */
+export class CatalogDto {
+ @ApiProperty({
+ description: 'Catalog id. Synthesized from the first collection — the only named grouping the engine exposes.',
+ example: '1234567890123456',
+ })
+ id!: string;
+
+ @ApiProperty({ description: 'Collection name.', example: 'Default' })
+ name!: string;
+
+ @ApiPropertyOptional({ description: 'Collection description, when the engine reports one.' })
+ description?: string;
+
+ @ApiProperty({ description: 'How many products the first collection holds.', example: 12 })
+ productCount!: number;
+
+ @ApiProperty({ description: 'Public catalog link for the account.', example: 'https://wa.me/c/628123456789' })
+ url!: string;
+}
+
+export class ProductDto {
+ @ApiProperty({ description: "Product id in the engine's native format.", example: '7891234567890' })
+ id!: string;
+
+ @ApiProperty({ description: 'Product name.', example: 'Kopi Gayo 200g' })
+ name!: string;
+
+ @ApiPropertyOptional({ description: 'Product description, when set.' })
+ description?: string;
+
+ @ApiProperty({ description: 'Price in the currency’s minor-unit-free numeric form.', example: 85000 })
+ price!: number;
+
+ @ApiProperty({ description: 'ISO currency code.', example: 'IDR' })
+ currency!: string;
+
+ @ApiProperty({
+ description:
+ 'Price rendered for display. Synthesized by the gateway from price + currency, so an ' +
+ 'unrecognised currency code falls back to a plain "CODE amount" pair.',
+ example: 'IDR 85,000.00',
+ })
+ priceFormatted!: string;
+
+ @ApiPropertyOptional({
+ description: 'First product image URL. Absent when the product carries no image.',
+ example: 'https://pps.whatsapp.net/v/t61.24694-24/12345_678_910_n.jpg',
+ })
+ imageUrl?: string;
+
+ @ApiProperty({ description: 'Product link, empty when the engine reports none.', example: 'https://wa.me/p/123/628' })
+ url!: string;
+
+ @ApiProperty({ description: 'Whether the engine reports the product as in stock.', example: true })
+ isAvailable!: boolean;
+
+ @ApiPropertyOptional({ description: "The merchant's own SKU, when set.", example: 'SKU-001' })
+ retailerId?: string;
+}
+
+export class ProductPaginationDto {
+ @ApiProperty({ description: 'Page that was returned (1-based).', example: 1 })
+ page!: number;
+
+ @ApiProperty({ description: 'Page size that was applied.', example: 20 })
+ limit!: number;
+
+ @ApiProperty({ description: 'Total products in the catalog, not on this page.', example: 12 })
+ total!: number;
+
+ @ApiProperty({ description: 'Total pages at this page size.', example: 1 })
+ totalPages!: number;
+}
+
+export class PaginatedProductsDto {
+ @ApiProperty({ type: [ProductDto], description: 'Products on the requested page.' })
+ products!: ProductDto[];
+
+ @ApiProperty({ type: ProductPaginationDto })
+ pagination!: ProductPaginationDto;
+}
+
+/**
+ * What POST /messages/send-product answers.
+ *
+ * Deliberately NOT MessageResponseDto: this route returns the engine's MessageResult unmapped, so
+ * the id field is `id`, whereas every route that goes through MessageService answers `messageId`.
+ * Documenting it as `messageId` here would be a contract that the code does not honour.
+ */
+export class ProductMessageResponseDto {
+ @ApiProperty({
+ description:
+ 'The message id, assigned when the gateway accepts the message for sending. Note the field ' +
+ 'name: the send routes served by MessageService answer `messageId` for the same value. A 2xx ' +
+ 'here means the message was handed to the WhatsApp client, not that it was delivered.',
+ example: '[email protected]_3EB0123456789',
+ })
+ id!: string;
+
+ @ApiProperty({ description: 'Unix SECONDS the engine stamped on the outgoing message.', example: 1786000000 })
+ timestamp!: number;
+}