Hello! I'm having trouble getting the REST API to...
# prefect-cloud
m
Hello! I'm having trouble getting the REST API to work on Prefect Cloud. I keep getting 404 - Not Found for every endpoint I test. I am able to hit https://api.prefect.cloud/api/health only (but nothing using my account/workspace IDs). Here's the code I'm running (api_key is pulled from Prefect CLI):
Copy code
import requests

account_id="REDACTED"
workspace_id="0851ecb8-a917-43ce-b7d6-c7332cbdc608"
base_url=f"<https://api.prefect.cloud/api/accounts/{account_id}/workspaces/{workspace_id}>"
endpoint=f"{base_url}/api/hello"
headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}

r=requests.get(endpoint, headers=headers)

print(endpoint)
print(r.status_code)
print(r.json())
It generates this output:
Copy code
<https://api.prefect.cloud/api/accounts/REDACTED/workspaces/0851ecb8-a917-43ce-b7d6-c7332cbdc608/api/hello>
404
{'detail': 'Not Found'}
Any help would be much appreciated! NOTE - I can fire up a local Orion server and hit /api/hello just fine.
j
Hey there! We’re not currently routing /hello (just a bug on our end that we can fix) but I just tested that the account/workspace-scoped healthcheck route should work: https://api.prefect.cloud/api/accounts/REDACTED/workspaces/REDACTED/health can you try that one instead? it should apply a workspace authorization check as well, so you’ll get an error if you omit the bearer token
m
Ah, that worked! I think I was confused by the documentation. A path like: /api/health on Prefect Cloud is actually: api/accounts/account_id/workspaces/workspace_id/health As you can see in my example, I put "api" path in base_url and in endpoint. I'll test other endpoints and see if I can get things to work. Thanks!
plus one 1