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

Open Beginner friendly
#97 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
go
Domain
api, backend

Research direction

Start in pkg/routes/routes.go and compare the /group/participant registration with the /group/create route. Read jid_validation_middleware.go around the reported validation branch, then exercise POST /group/participant with the documented payload for each action. Done means the request reaches UpdateParticipant and returns the expected success response instead of the 400 validation error.

Written by the indexing model from the issue text.

Description

bug
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.

Dominant language
Go
Stars
878
Forks
461
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from evolution-foundation/evolution-go

All issues in evolution-foundation/evolution-go

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.