Skip to content

Commit 3cb842a

Browse files
committed
fix(flags): Resolve api_key parameter conflict in remote_config
The post() function automatically sets api_key in the request body, causing a conflict when we also passed api_key as a kwarg. Fixed by creating a custom POST request for remote_config that: - Uses personal_api_key for Authorization header - Includes project_api_key in request body - Maintains proper request structure
1 parent 66e19b4 commit 3cb842a

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

posthog/request.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,27 @@ def remote_config(
139139
timeout: int = 15,
140140
) -> Any:
141141
"""Get remote config flag value from remote_config API endpoint"""
142-
res = post(
143-
personal_api_key,
144-
host,
145-
f"/api/projects/@current/feature_flags/{key}/remote_config/",
146-
timeout=timeout,
147-
api_key=project_api_key,
148-
)
142+
import requests
143+
from datetime import datetime
144+
from dateutil.tz import tzutc
145+
146+
url = remove_trailing_slash(host or DEFAULT_HOST) + f"/api/projects/@current/feature_flags/{key}/remote_config/"
147+
148+
body = {
149+
"api_key": project_api_key,
150+
"sentAt": datetime.now(tz=tzutc()).isoformat()
151+
}
152+
153+
headers = {
154+
"Authorization": f"Bearer {personal_api_key}",
155+
"Content-Type": "application/json",
156+
"User-Agent": USER_AGENT
157+
}
158+
159+
data = json.dumps(body, cls=DatetimeSerializer)
160+
161+
res = requests.post(url, data=data, headers=headers, timeout=timeout)
162+
149163
return _process_response(
150164
res,
151165
success_message=f"POST /api/projects/@current/feature_flags/{key}/remote_config/ completed successfully",

0 commit comments

Comments
 (0)