I’m using withApiAuthRequired to secure my API endpoints.
However, I want to be able to call the api using a python script. Below was something I have tried, the access code with retrieved successfully, but because a user session is required i still get the not_authenticated error:
https://gist.github.com/agentzhao/890e6356b5536414955968c3be67f08e
{"error":"not_authenticated","description":"The user does not have an active session or is not authenticated"}
session_url = f"https://example.com/api/auth/callback"
session_headers = {"Authorization": f"Bearer {access_token}"}
session_response = requests.get(session_url, headers=session_headers)
cookies = session_response.cookies
# Use the session cookie to access the protected API
protected_url = "https://example.com/api/example"
response = requests.get(protected_url, cookies=cookies)
print(response.json())
I have also tried to include the session cookie in the request but it does not work