From 6c36c61c1390179224adc8a285f06e2c79e63de6 Mon Sep 17 00:00:00 2001 From: stijnhoste Date: Tue, 24 Nov 2026 14:34:40 +0400 Subject: [PATCH] fix: allow bodyless non-GET requests in api request rest A DELETE (or any non-GET request) with no --body and no --file threw "No 'mode' found in 'body' entry" before sending, and so did the documented empty body --body "". Only read the body from --file when the file has one; otherwise send no body. Fixes forcedotcom/cli#3693 Co-Authored-By: Claude Opus 5.5 --- src/commands/api/request/rest.ts | 7 +++--- test/commands/api/request/rest/rest.test.ts | 24 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/commands/api/request/rest.ts b/src/commands/api/request/rest.ts index 4279b52..7f0b072 100644 --- a/src/commands/api/request/rest.ts +++ b/src/commands/api/request/rest.ts @@ -125,7 +125,8 @@ export class Rest extends SfCommand { // body can be undefined; // if we have a --body @myfile.json, read the file // if we have a --body '{"key":"value"}' use that - // else read from --file's body + // else read from --file's body, if it has one + // with neither (or --body ''), send no body, e.g. for DELETE let body; if (method !== 'GET') { if (flags.body?.startsWith('@')) { @@ -133,8 +134,8 @@ export class Rest extends SfCommand { body = readFileSync(flags.body.substring(1)); } else if (flags.body) { body = flags.body; - } else if (!flags.body) { - body = getBodyContents(fileOptions?.body); + } else if (flags.body === undefined && fileOptions?.body) { + body = getBodyContents(fileOptions.body); } } diff --git a/test/commands/api/request/rest/rest.test.ts b/test/commands/api/request/rest/rest.test.ts index d4cf88f..c413ff8 100644 --- a/test/commands/api/request/rest/rest.test.ts +++ b/test/commands/api/request/rest/rest.test.ts @@ -207,6 +207,30 @@ describe('rest', () => { } }); + it('should send a DELETE without a body when neither --body nor --file is given', async () => { + nock(testOrg.instanceUrl).delete('/services/data/v56.0/sobjects/Account/001', '').reply(204); + + await Rest.run(['/services/data/v56.0/sobjects/Account/001', '--method', 'DELETE', '--target-org', 'test@hub.com']); + + expect(nock.isDone()).to.be.true; + }); + + it('should send a DELETE without a body when --body is empty', async () => { + nock(testOrg.instanceUrl).delete('/services/data/v56.0/sobjects/Account/001', '').reply(204); + + await Rest.run([ + '/services/data/v56.0/sobjects/Account/001', + '--method', + 'DELETE', + '--body', + '', + '--target-org', + 'test@hub.com', + ]); + + expect(nock.isDone()).to.be.true; + }); + it('should not follow redirects', async () => { nock(testOrg.instanceUrl) .get('/services/data/v56.0/limites')