Skip to content

fix: send query params instead of a body for GET and HEAD requests from slack api - #727

Merged
mwbrooks merged 6 commits into
mainfrom
zimeg-fix-api-get-query-params
Oct 28, 2026
Merged

mwbrooks merged 6 commits into
mainfrom
zimeg-fix-api-get-query-params

Conversation

@zimeg

@zimeg zimeg commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Changelog

slack api --method GET now sends key=value arguments and --data as query parameters, with the token in the Authorization header, instead of form-encoding them into a request body.

Summary

This pull request stops slack api from attaching a request body to GET and HEAD requests, since many proxies and CDNs reject these requests when a body is included.

  • key=value arguments and --data are sent in the query string for GET and HEAD, and the token moves from the body to the Authorization: Bearer header.
  • A JSON body from --json or a JSON argument is still sent as given, and the API response is returned unchanged.
  • Help text is updated for GET and HEAD, and the "No args" line now matches the form-encoded token sent with POST.

Testing

  • slack api api.test foo=bar -X GET --no-auth --verbose shows GET https://slack.com/api/api.test?foo=bar with <no body> and returns {"ok":true,"args":{"foo":"bar"}}.
  • slack api auth.test -X GET --token <token> --verbose shows no request body and authenticates with the header token.
  • slack api chat.postMessage channel=<channel> text=hi --token <token> still sends a form-encoded body with POST.
  • slack api api.test --json '{"foo":"bar"}' -X GET --no-auth sends the JSON body and prints the API response as is.

Notes

  • The RawRequest retry loop also attaches an empty reader to requests without a body. Go's transport drops this for GET and HEAD, so it's fixed separately in fix: avoid attaching an empty body to raw api requests on retryย #728 for POST.
  • DoWithRetry uses the same body-reattach loop, but is left as is: its GET callers pass a nil body that Go's transport drops on the wire, and its POST callers always have a body.
  • Sending a JSON body with GET or HEAD is kept as an explicit choice for now and might be worth revisiting.

Requirements

๐Ÿค– Generated with Claude Code

โ€ฆom slack api

Many proxies and CDNs reject GET or HEAD requests that include a body,
but "slack api -X GET" form-encoded key=value args and the token into one.
These are now sent in the query string with the token in the Authorization
header. RawRequest also no longer attaches an empty body when retrying.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg zimeg added this to the Next Release milestone Oct 27, 2026
@zimeg zimeg added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch Use on pull requests to describe the release version increment labels Oct 27, 2026
@zimeg zimeg self-assigned this Oct 27, 2026
@zimeg zimeg added the changelog Use on updates to be included in the release notes label Oct 27, 2026
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

โŒ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.
โœ… Project coverage is 78.11%. Comparing base (07ab1ca) to head (f5ca986).

Files with missing lines Patch % Lines
cmd/api/api.go 96.55% 1 Missing โš ๏ธ
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #727   +/-   ##
=======================================
  Coverage   78.10%   78.11%           
=======================================
  Files         238      238           
  Lines       18097    18114   +17     
=======================================
+ Hits        14135    14150   +15     
- Misses       3962     3964    +2     

โ˜” View full report in Codecov by Harness.
๐Ÿ“ข Have feedback on the report? Share it here.

๐Ÿš€ New features to boost your workflow:
  • โ„๏ธ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zimeg zimeg left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

๐Ÿ“ฃ Notes to me - the self for here.

Comment thread internal/api/raw_request.go Resolved
Comment thread cmd/api/api_test.go Resolved
zimeg and others added 2 commits October 27, 2026 16:25
โ€ฆequest

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>

@zimeg zimeg left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Getting to a good place but another comment to make.

Comment thread cmd/api/api.go
}
bodyReader = strings.NewReader(formData)
token = ""
case len(params) == 1 && (strings.HasPrefix(params[0], "{") || strings.HasPrefix(params[0], "[")):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

๐Ÿ” note: Refactored up to L161 at the time of writing.

Comment thread cmd/api/api.go Resolved
Comment thread cmd/api/api.go
bodyReader = strings.NewReader(values.Encode())
token = ""
case bodyless:
// Send no body and keep the token for the Authorization header

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

๐Ÿฆ  note: This is set in our request:

if token != "" {
request.Header.Set("Authorization", "Bearer "+token)
}

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg
zimeg marked this pull request as ready for review October 27, 2026 23:46
@zimeg
zimeg requested review from a team as code owners October 27, 2026 23:46

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @zimeg! LGTM ๐Ÿš€

Comment thread cmd/api/api_test.go
assert.Equal(t, tc.expectedQuery, receivedQuery)
if tc.assertNoBody {
assert.Empty(t, receivedContentType)
assert.Zero(t, receivedContentLength)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

praise: Thanks for extending the table test instead of adding new ones. Checking ContentLength along with the body is a nice way to prove nothing goes over the wire.

@mwbrooks
mwbrooks merged commit ef296d4 into main Oct 28, 2026
13 checks passed
@mwbrooks
mwbrooks deleted the zimeg-fix-api-get-query-params branch October 28, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented changelog Use on updates to be included in the release notes semver:patch Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants