Skip to content

POST /group/participant always returns 400 "participants is required and cannot be empty" (wrong validation middleware on route) #97

Description

@netoduwe

Welcome!

  • Yes, I have searched for similar issues on GitHub and found none.

What did you do?

Called POST /group/participant to add a participant to a group, sending the exact payload documented in the Postman collection:

{
"groupJid": "120363332413160732@g.us",
"participants": ["557499879409"],
"action": "add"
}

Same result for every action (add / remove / promote / demote).

What did you expect?

The participant to be added to the group and the API to return {"message": "success"}, as the UpdateParticipant handler implements.

What did you observe instead of what you expected?

The request is always rejected with HTTP 400 and the body:

{"error": "participants is required and cannot be empty"}

regardless of the participants sent (raw number 557499879409 or full JID 557499879409@s.whatsapp.net).

Root cause: in pkg/routes/routes.go the route registers the wrong validation middleware:

routes.POST("/participant", r.jidValidationMiddleware.ValidateJIDFields("number", "participants"), r.groupHandler.UpdateParticipant)

ValidateJIDFields is designed for single-string fields. Since participants is an array, the type assertion value.(string) in the middleware fails, strValue defaults to "", and it aborts on the else if strValue == "" branch (jid_validation_middleware.go, line ~80) BEFORE reaching the handler. The handler UpdateParticipant is correct — the request never gets there.

Suggested fix (one line) — use the array-aware middleware already used by /group/create for the same participants field:

routes.POST("/participant", r.jidValidationMiddleware.ValidateMultipleNumbers("participants"), r.groupHandler.UpdateParticipant)

(The "number" field can be dropped: this route has no number field in its body.)

This means all participant actions (add / remove / promote / demote) are currently unusable via the API. Reproduced on v0.6.1, 0.7.0 and 0.7.1 — the route has had this middleware since at least v0.6.1.

Screenshots/Videos

No response

Which version are you using?

0.7.1 (also reproduced on 0.7.0 and 0.6.1)

What is your environment?

Linux

If applicable, paste the log output

Request: POST /group/participant
Body: {"groupJid":"120363040128842797@g.us","action":"add","participants":["554799009115@s.whatsapp.net"]}
Response: 400 {"error":"participants is required and cannot be empty"}

Additional Notes

The Postman collection and the UpdateParticipant handler are both correct — the mismatch is only in the middleware wired to the route. A PR changing that single line should fully resolve it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions