Skip to main content
Question

Response status code does not indicate success: 400 (Bad Request)

  • January 20, 2025
  • 1 reply
  • 49 views

Hi! Getting error 400. My code:
 

public async Task TrackEventAsync(string userId, string eventType, object eventProperties)
{
    var eventData = new
    {
        api_key = _apiKey,
        event_type = eventType,
        user_id = userId,
        event_properties = eventProperties
    };

    var json = JsonSerializer.Serialize(eventData);
    var content = new StringContent(json, Encoding.UTF8, "application/json");

    try
    {
        var response = await _httpClient.PostAsync("https://api.amplitude.com/2/httpapi", content);
        response.EnsureSuccessStatusCode();
        _logger.LogInformation("Event tracked successfully: {EventType}", eventType);
    }
    catch (HttpRequestException ex)
    {
        _logger.LogError(ex, "Error sending event to Amplitude: {EventType}", eventType);
    }
}

Any ideas how to figure out the issue?

1 reply

Alex Prismotrov wrote:

Hi! Getting error 400. My code:
 

public async Task TrackEventAsync(string userId, string eventType, object eventProperties)
{
    var eventData = new
    {
        api_key = _apiKey,
        event_type = eventType,
        user_id = userId,
        event_properties = eventProperties
    };

    var json = JsonSerializer.Serialize(eventData);
    var content = new StringContent(json, Encoding.UTF8, "application/json");

    try
    {
        var response = await _httpClient.PostAsync("https://api.amplitude.com/2/httpapi", content);
        response.EnsureSuccessStatusCode();
        _logger.LogInformation("Event tracked successfully: {EventType}", eventType);
    }
    catch (HttpRequestException ex)
    {
        _logger.LogError(ex, "Error sending event to Amplitude: {EventType}", eventType);
    }
}

Any ideas how to figure out the issue?

tried to switch to https://api2.amplitude.com/2/httpapi  , but also didnt work out


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings