Skip to content

DELETE /groups/:groupId/participants returns 400 — DTOs missing class-validator` decorators #190

@roldan

Description

@roldan

Hi, first of all thanks for this project — it's been really useful!

While integrating the group management endpoints I ran into the following issue.

Description:

Trying to remove a participant from a group always returns a 400 Bad Request:

curl -X DELETE \
  'http://localhost:2785/api/sessions/<sessionId>/groups/<groupId>/participants' \
  -H 'Content-Type: application/json' \
  -H 'X-API-Key: <key>' \
  -d '{"participants": ["<participantId>@c.us"]}'
{
  "message": ["property participants should not exist"],
  "error": "Bad Request",
  "statusCode": 400
}

Root cause:

The global ValidationPipe is configured with forbidNonWhitelisted: true, but the DTOs in group.controller.ts have no class-validator decorators. With whitelist: true active, NestJS strips every undecorated property before it reaches the handler, so dto.participants arrives as undefined and causes a secondary crash in the adapter:

TypeError: Cannot read properties of undefined (reading 'map')
    at WhatsAppWebJsAdapter.removeParticipants

Note: commenting out forbidNonWhitelisted: true alone is not enough — whitelist: true still strips the properties. This likely affects all endpoints that receive a body across all modules.

Fix:

Add class-validator decorators to all DTOs. Example for ParticipantsDto:

import { IsArray, IsString } from 'class-validator';

class ParticipantsDto {
  @IsArray()
  @IsString({ each: true })
  participants: string[];
}

class-validator and class-transformer are already in the project dependencies so no new packages are needed. Happy to open a PR if you'd like.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions