diff --git a/src/PostHog/Api/LocalEvaluationApiResult.cs b/src/PostHog/Api/LocalEvaluationApiResult.cs index 3ec1777a..edb72258 100644 --- a/src/PostHog/Api/LocalEvaluationApiResult.cs +++ b/src/PostHog/Api/LocalEvaluationApiResult.cs @@ -5,7 +5,7 @@ namespace PostHog.Api; /// -/// The API Payload from the /api/feature_flag/local_evaluation endpoint used to evaluate feature flags +/// The API Payload from the /flags/definitions endpoint used to evaluate feature flags /// locally. /// internal record LocalEvaluationApiResult diff --git a/src/PostHog/Api/PostHogApiClient.cs b/src/PostHog/Api/PostHogApiClient.cs index a9c7d3a8..c1b9e61d 100644 --- a/src/PostHog/Api/PostHogApiClient.cs +++ b/src/PostHog/Api/PostHogApiClient.cs @@ -144,7 +144,7 @@ public async Task SendEventAsync( /// /// Retrieves all the feature flags for the project by making a request to the - /// /api/feature_flag/local_evaluation endpoint. This requires that a Personal API Key is set in + /// /flags/definitions endpoint. This requires that a Personal API Key is set in /// . /// /// Optional ETag from a previous request for conditional fetching. @@ -155,7 +155,7 @@ public async Task GetFeatureFlagsForLocalEvaluationAsyn string? etag, CancellationToken cancellationToken) { - var uriBuilder = new UriBuilder(new Uri(HostUrl, "/api/feature_flag/local_evaluation")) + var uriBuilder = new UriBuilder(new Uri(HostUrl, "/flags/definitions")) { Query = $"token={Uri.EscapeDataString(ProjectApiKey)}&send_cohorts" }; diff --git a/tests/TestLibrary/Fakes/FakeHttpMessageHandlerExtensions.cs b/tests/TestLibrary/Fakes/FakeHttpMessageHandlerExtensions.cs index 4ae1a6ef..5726c93b 100644 --- a/tests/TestLibrary/Fakes/FakeHttpMessageHandlerExtensions.cs +++ b/tests/TestLibrary/Fakes/FakeHttpMessageHandlerExtensions.cs @@ -68,7 +68,7 @@ public static void AddRepeatedFlagsResponse(this FakeHttpMessageHandler handler, public static void AddRepeatedFlagsResponse(this FakeHttpMessageHandler handler, int count, string responseBody) => handler.AddRepeatedFlagsResponse(count, _ => responseBody); - static readonly Uri LocalEvaluationUrl = new("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts"); + internal static readonly Uri LocalEvaluationUrl = new("https://us.i.posthog.com/flags/definitions?token=fake-project-api-key&send_cohorts"); public static FakeHttpMessageHandler.RequestHandler AddLocalEvaluationResponse( this FakeHttpMessageHandler handler, diff --git a/tests/UnitTests/Features/FeatureFlagsTests.cs b/tests/UnitTests/Features/FeatureFlagsTests.cs index ec84763d..76568843 100644 --- a/tests/UnitTests/Features/FeatureFlagsTests.cs +++ b/tests/UnitTests/Features/FeatureFlagsTests.cs @@ -3354,7 +3354,7 @@ public async Task ReturnsEmptyDictionaryWhenPersonalApiKeyIncorrect() FeatureFlagPayloads = new Dictionary(), }); container.FakeHttpMessageHandler.AddResponse( - new Uri("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts"), + FakeHttpMessageHandlerExtensions.LocalEvaluationUrl, HttpMethod.Get, new HttpResponseMessage(HttpStatusCode.Unauthorized) { @@ -3510,7 +3510,7 @@ public async Task ReturnsEmptyDictionaryWhenLocalEvaluationQuotaExceeded() // When local evaluation is quota limited, we do not want to fallback to /decide. var decideHandler = container.FakeHttpMessageHandler.AddFlagsResponseException(new InvalidOperationException()); container.FakeHttpMessageHandler.AddResponse( - new Uri("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts"), + FakeHttpMessageHandlerExtensions.LocalEvaluationUrl, HttpMethod.Get, new HttpResponseMessage(HttpStatusCode.PaymentRequired) { @@ -3542,7 +3542,7 @@ public async Task ReturnsFalseWhenSingleFlagLocalEvaluationRequestQuotaExceeded( var container = new TestContainer("fake-personal-api-key"); var decideHandler = container.FakeHttpMessageHandler.AddFlagsResponseException(new InvalidOperationException()); container.FakeHttpMessageHandler.AddResponse( - new Uri("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts"), + FakeHttpMessageHandlerExtensions.LocalEvaluationUrl, HttpMethod.Get, new HttpResponseMessage(HttpStatusCode.PaymentRequired) { diff --git a/tests/UnitTests/Features/LocalFeatureFlagsLoaderTests.cs b/tests/UnitTests/Features/LocalFeatureFlagsLoaderTests.cs index b04c53ad..516422f3 100644 --- a/tests/UnitTests/Features/LocalFeatureFlagsLoaderTests.cs +++ b/tests/UnitTests/Features/LocalFeatureFlagsLoaderTests.cs @@ -29,8 +29,7 @@ public class TheDisposeAsyncMethod } """; - static readonly Uri LocalEvaluationUrl = - new("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts"); + static readonly Uri LocalEvaluationUrl = FakeHttpMessageHandlerExtensions.LocalEvaluationUrl; [Fact] public async Task CompletesGracefullyDuringInFlightPoll() diff --git a/tests/UnitTests/PostHogClientTests.cs b/tests/UnitTests/PostHogClientTests.cs index 612771af..69ab3298 100644 --- a/tests/UnitTests/PostHogClientTests.cs +++ b/tests/UnitTests/PostHogClientTests.cs @@ -1510,7 +1510,7 @@ public async Task RespectsCancellationToken() { var container = new TestContainer(personalApiKey: "fake-personal-api-key"); // Add a handler that will throw OperationCanceledException - var uri = new Uri("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts"); + var uri = FakeHttpMessageHandlerExtensions.LocalEvaluationUrl; container.FakeHttpMessageHandler.AddResponseException(uri, HttpMethod.Get, new OperationCanceledException()); var client = container.Activate(); @@ -1529,7 +1529,7 @@ public async Task DoesNotLogErrorForCancellation() { var container = new TestContainer(personalApiKey: "fake-personal-api-key"); // Add a handler that will throw OperationCanceledException - var uri = new Uri("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts"); + var uri = FakeHttpMessageHandlerExtensions.LocalEvaluationUrl; container.FakeHttpMessageHandler.AddResponseException(uri, HttpMethod.Get, new OperationCanceledException()); var client = container.Activate();