Skip to content

fix: send JSON request bodies as JSON in AsyncTwilioHttpClient (#994) - #995

Open
shrutiburman wants to merge 1 commit into
mainfrom
xinghaohuang91fix/async-json-body
Open

shrutiburman wants to merge 1 commit into
mainfrom
xinghaohuang91fix/async-json-body

Conversation

@shrutiburman

Copy link
Copy Markdown
Contributor

AsyncTwilioHttpClient passed every body to aiohttp as data, which form-encodes a dict. Endpoints whose Content-Type is application/json (Conversations v2, Memory v1, Knowledge v2, ...) then got a form body and returned 400 when called with the async client. The sync client already picks json= for these content types (#737); this applies the same rule to the async client.

Fixes

A short description of what this PR does.

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

If you have questions, please file a support ticket, or create a GitHub Issue in this repository.

AsyncTwilioHttpClient passed every body to aiohttp as `data`, which
form-encodes a dict. Endpoints whose Content-Type is application/json
(Conversations v2, Memory v1, Knowledge v2, ...) then got a form body
and returned 400 when called with the async client. The sync client
already picks `json=` for these content types (#737); this applies the
same rule to the async client.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the asynchronous client’s request-body handling changes.

No open issues 🎉

What changed in this PR

Aligns AsyncTwilioHttpClient with the synchronous client’s JSON-body handling, preventing JSON endpoints from receiving form-encoded dictionaries.

Changes:

  • Uses json= for application/json and application/scim+json request bodies.
  • Preserves data= handling for other content types.
  • Adds tests for both JSON content types and form-encoded requests.
File Description
twilio/​http/​async_http_client.py Selects JSON or form body handling based on Content-Type.
tests/​unit/​http/​test_async_http_client.py Verifies JSON and form requests use the appropriate body argument.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants