posthog-ios icon indicating copy to clipboard operation
posthog-ios copied to clipboard

Batch 400 Status Code: "failed to parse request: expected value at line 1 column 1"

Open gaelph opened this issue 1 year ago • 1 comments

Version

3.12.7

Steps to Reproduce

  1. Trigger any event
  2. Wait for a request to /batch to be sent

Expected Result

A successful call with a 200 status code.

Actual Result

The request to the /batch route consistently fails with a 400 HTTP status code. The body of the response is always the plain text string: "failed to parse request: expected value at line 1 column 1". This fails to be parsed as JSON and no explicit error shows up in the logs. No events are shown in Activity feed on website.

The SDK is configured as follow:

let config = PostHogConfig(
    apiKey: Constants.PosthogKey,
    host: "https://\(Constants.PosthogHost)"
)
config.debug = true
PostHogSDK.shared.setup(config)

where the PosthogHost is either eu.i.posthog.com or eu.posthog.com with the same result.

Logs in XCode look as follow:

[PostHog] Queued event 'Application Opened'. Depth: 14
[PostHog] Queued event 'Application Opened'. Depth: 15
[PostHog] Decide called successfully.
[PostHog] Queued event 'Application Backgrounded'. Depth: 16
[PostHog] Queued event '$screen'. Depth: 17
[PostHog] Queued event '$screen'. Depth: 18
[PostHog] Queued event 'Application Opened'. Depth: 19
[PostHog] Queued event 'Application Backgrounded'. Depth: 20
[PostHog] Sending batch of 20 events to PostHog
[PostHog] Queued event '$screen'. Depth: 21
[PostHog] Already flushing
[PostHog] Queued event 'Application Opened'. Depth: 22
[PostHog] Already flushing
[PostHog] Queued event 'Application Backgrounded'. Depth: 23
[PostHog] Already flushing
[PostHog] Queued event 'Application Opened'. Depth: 24
[PostHog] Already flushing
[PostHog] Error sending events to batch API: status: nil.
[PostHog] Completed!
[PostHog] Sending batch of 4 events to PostHog

I am aware of a previous similar issue (https://github.com/PostHog/posthog-ios/issues/103), however the date sent_at seems to be formatted correctly, so I am assuming this is a different issue.

gaelph avatar Oct 09 '24 15:10 gaelph

@gaelph host should be https://eu.i.posthog.com for EU. I wonder if it's your network or something, is this on an emulator only or on a real device? I just tested this on an emulator and everything worked fine. Double check if Constants.PosthogKey and Constants.PosthogHost are correct?

marandaneto avatar Oct 10 '24 09:10 marandaneto

Closing the issue as a part of large repository cleanup, due to it being inactive and/or outdated. Please do not hesitate to ping me if it is still relevant, and I will happily reopen and work on it. Cheers!

marandaneto avatar Oct 24 '24 15:10 marandaneto