Skip to content

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

Merged
shrutiburman merged 1 commit into
twilio:xinghaohuang91fix/async-json-bodyfrom
xinghaohuang91:fix/async-json-body
Nov 26, 2026
Merged

shrutiburman merged 1 commit into
twilio:xinghaohuang91fix/async-json-bodyfrom
xinghaohuang91:fix/async-json-body

Conversation

@xinghaohuang91

Copy link
Copy Markdown

Fixes #932

AsyncTwilioHttpClient passes every request body to aiohttp as data, and aiohttp form-encodes a dict. So on endpoints whose Content-Type is application/json (Conversations v2, Memory v1, Knowledge v2 and others), the async client sends a form body under a JSON header, and the API returns 400. The sync client already sends these as JSON. This PR applies the same rule to the async client: json= for application/json and application/scim+json, data= otherwise.

Verified against the live API with a Knowledge v2 search (create_async): 400 on main, 200 with this change.

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

🤖 Generated with Claude Code

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 (twilio#737); this applies the
same rule to the async client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shrutiburman
shrutiburman changed the base branch from main to xinghaohuang91fix/async-json-body November 26, 2026 06:50
@shrutiburman

Copy link
Copy Markdown
Contributor

Change base merge to a local twilio-owned repo.

@shrutiburman
shrutiburman merged commit cf361c0 into twilio:xinghaohuang91fix/async-json-body Nov 26, 2026
10 of 12 checks passed
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.

AsyncTwilioHttpClient does not JSON-serialize request bodies for application/json endpoints (sync client does) → 400 on JSON-body v2 endpoints

2 participants