Skip to content

fix: send body in api client delete method - #41349

Open
Rohit3523 wants to merge 5 commits into
developfrom
fix/api-client-delete-body
Open

fix: send body in api client delete method#41349
Rohit3523 wants to merge 5 commits into
developfrom
fix/api-client-delete-body

Conversation

@Rohit3523

@Rohit3523 Rohit3523 commented Jul 13, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

RestClient.delete (packages/api-client/src/index.ts:189) silently dropped its params argument and never sent a request body. This PR makes delete forward params as a JSON (or FormData) body — mirroring the existing post/put behavior — so DELETE endpoints that expect a body now work. Param-less DELETE calls are unchanged (no body is sent).

Example

await sdk.rest.delete('/v1/push.token', { token: 'abc123' });

Affected APIs

Endpoint Code reference Impact
DELETE /v1/push.token apps/meteor/server/api/v1/push.ts:63-79 (PushTokenDELETE = { token: string }), route wired at apps/meteor/server/api/v1/push.ts:211 Requires { token: string } in the request body. Previously the body was silently dropped, causing error-token-param-not-valid.
DELETE /v1/livechat/message/:_id packages/ddp-client/src/livechat/LivechatClientImpl.ts:328-333 (deleteMessage); typed at packages/rest-typings/src/v1/omnichannel.ts:4921-4924 (DELETELivechatMessageIdParams) Passes { rid, token } in the request body. Previously discarded, now sent correctly.
DELETE /v1/livechat/visitor/:token packages/ddp-client/src/livechat/LivechatClientImpl.ts:335-339 (deleteVisitor) Path-only endpoint; unaffected.

No caller passed params expecting them as a query string, so this is a safe behavioral fix with no regressions.

Issue(s)

https://rocketchat.atlassian.net/browse/CORE-2422

Steps to test or reproduce

  • Before: sdk.rest.delete('/v1/push.token', { token: 'abc' }) sent an empty DELETE (token dropped) → server 400 error-token-param-not-valid.
  • After: the token is sent in the body → 200 { success: true }.
  • LivechatClientImpl.deleteMessage now delivers rid/token to the server.

Further comments

Note: rest-typings does not yet declare DELETE /v1/push.token, so ParamsFor<'DELETE', '/v1/push.token'> currently resolves to void — callers must cast until that route is typed (intentionally left out of this PR to keep scope minimal).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed DELETE requests so provided parameters are included in the request body (matching POST/PUT behavior).
    • Improved request payload serialization for DELETE, including correct handling of JSON vs form-data.
    • Preserved/merged caller-provided headers while applying appropriate content headers based on the payload type.
    • Corrected nested object form-data construction so nested values are properly included.
  • Tests

    • Added Jest coverage for DELETE body/headers behavior, multipart handling with files, and 204 (empty response) handling.
  • Release

    • Patch update for the API client.

@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2716824

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@rocket.chat/api-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant

CLAassistant commented Jul 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@dionisio-bot

dionisio-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

RestClient.delete now sends optional params in the request body using FormData or JSON encoding, applies corresponding headers, preserves request options, fixes nested FormData construction, and adds coverage plus patch release metadata.

Changes

DELETE body fix

Layer / File(s) Summary
DELETE body forwarding and serialization
packages/api-client/src/index.ts
RestClient.delete conditionally sends params as FormData or JSON with appropriate headers and forwards request options; nested FormData construction uses the correct recursive argument order.
DELETE behavior validation and release metadata
packages/api-client/__tests__/requests.spec.ts, .changeset/fix-rest-client-delete-body.md
Tests cover JSON, absent, and FormData DELETE bodies plus 204 responses; the Changesets entry declares a patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: type: bug

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a request body to the API client DELETE method.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • CORE-2422: Request failed with status code 401

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Rohit3523 Rohit3523 changed the title fix: send body in RestClient.delete so DELETE endpoints like push.token work fix: send body in RestClient.delete so DELETE endpoint Jul 13, 2026
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Rohit3523
Rohit3523 marked this pull request as ready for review July 15, 2026 15:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/api-client/src/index.ts`:
- Around line 191-207: Update the DELETE request method to return an empty
result without calling response.json() when the response status is 204, matching
the existing POST behavior. Also apply Content-Type: application/json only when
params is defined and the request is not FormData, while preserving existing
headers for parameter-less requests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 47b4d86f-3351-4cc9-b811-fef610c57748

📥 Commits

Reviewing files that changed from the base of the PR and between 012dd32 and 5bfa63e.

📒 Files selected for processing (2)
  • .changeset/fix-rest-client-delete-body.md
  • packages/api-client/src/index.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/api-client/src/index.ts
🧠 Learnings (4)
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.

Applied to files:

  • .changeset/fix-rest-client-delete-body.md
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/api-client/src/index.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/api-client/src/index.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • packages/api-client/src/index.ts

Comment thread packages/api-client/src/index.ts
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 10.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.38%. Comparing base (012dd32) to head (2716824).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41349      +/-   ##
===========================================
- Coverage    68.38%   68.38%   -0.01%     
===========================================
  Files         3970     3970              
  Lines       154935   154942       +7     
  Branches     27807    27833      +26     
===========================================
- Hits        105960   105956       -4     
- Misses       44232    44252      +20     
+ Partials      4743     4734       -9     
Flag Coverage Δ
e2e 59.19% <ø> (-0.07%) ⬇️
e2e-api 44.03% <ø> (-0.02%) ⬇️
unit 70.30% <10.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.

Re-trigger cubic

Comment thread packages/api-client/src/index.ts
Comment thread packages/api-client/src/index.ts
Comment thread packages/api-client/src/index.ts Outdated
@Rohit3523 Rohit3523 changed the title fix: send body in RestClient.delete so DELETE endpoint fix: send body in RestClient.delete Jul 15, 2026
@Rohit3523 Rohit3523 changed the title fix: send body in RestClient.delete fix: send body in api client delete method Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants