Solved

iOS app receives "400 Bad Request" Error when using Domain Proxy (setServerUrl)

  • 25 February 2024
  • 1 reply
  • 56 views

Hello,

I’m trying to implement a Domain Proxy in an iOS app, however, I'm facing a challenge with sending events to my proxy server and am seeking advice on how to address a recurring "400 Bad Request" error.

The setup involves an iOS app that sends event data to Amplitude via a proxy. However, when attempting to send these events (some with a large payloads), the requests fail with a "400 Bad Request" response.

Here are some specifics about the failing requests:

- **Method:** POST
- **Headers:** Include `Content-Type: application/x-www-form-urlencoded` and a specific `User-Agent` tailored to our app.
- **Body:** The request body is URL-encoded and contains multiple complex events.

Despite ensuring the request body is correctly URL-encoded and the `Content-Type` header is appropriately set, these larger requests consistently fail.

**Questions:**

  1. Are there any known size limitations for batches of event data sent to Amplitude, especially through a proxy server?
  2. Could the "400 Bad Request" error indicate a problem with how the proxy server processes larger payloads, or might it suggest an issue with the formatting of the event data itself?
  3. Are there recommended practices for structuring large event batches to avoid such errors, or specific configurations for the proxy that might help?
  4. Are there any configurations or settings that should be defined (or removed) from the Amplitude instance when using a Domain Proxy (setServerUrl)?

I would greatly appreciate any insights or guidance on this matter. If anyone has encountered similar issues or has suggestions on best practices, your advice would be invaluable.

Thank you for your time and help!

icon

Best answer by Niv Ben Porath 26 February 2024, 10:37

View original

1 reply

I found the issue:

When the Amplitude SDK uploads the user_properties where one of the keys has a () in its value, the request fails.

 

For example:

user_properties":{
"$set":{
"app_build":"357",
"ios.userTheme":"System (auto)", <<<<<<<<<<
"dark_mode_system_setting_iphone":true
}
}

Take note that the Amplitude does not include the user_properties in every request it makes making the issue harder to track down. Plus the user property might change (and not include () in the value) due to the user changing the setting. 

 

Reply