How to connect to prefect cloud 2.0 RESTAPI

Hi,
I was using GraphQL to interact with Prefect Cloud 1.0 in order to run flow based on another API (our internal fastapi). We are now trying to go for prefect cloud 2.0.
If running orion in local (I’m able to connect with http://127.0.0.1:4200/docs)
But how can I interact with the cloud version ?

For example in python
import requests
r = requests.get('https://api.prefect.cloud/api/hello', headers=headers)
And we received :
{'detail': 'Not Found'}

Any help would be useful.
Kind regards

1 Like

check this:

https://discourse.prefect.io/t/how-to-trigger-a-flow-run-from-a-deployment-via-api-call-using-python-requests-library-or-from-a-terminal-using-curl/1396

Hello Anna,

Thanks a lot for your answer.
By using the same code as above I still receive the same issue.
(And replacing the workspace id parameters, the account id as well as the private key)

import requests

base_url="https://api.prefect.cloud/api/accounts/316eecbc-e7fe-4457-b47f-e925ff3ffd43/workspace/ed8c9a67-6cbe-4eea-b713-762dd9a64ba2"


def create_flow_run(deployment_id, base_url, token):
    return requests.post(
        url=f"{base_url}/deployments/{deployment_id}/create_flow_run",
        headers={
            "Content-Type": "application/json",
            "Authorization": f"Bearer {token}",
        },
    )

flow_id = '44211159-e9e7-40d2-a624-f8ac9d989e5c'
r = create_flow_run(flow_id, base_url, token)
print(r.status_code)
print(r.text)

404
{“detail”:“Not Found”}

I obviously double check on the UI the deployment id, the workspace id and account id.

I see why this may be confusing, but here you need to pass a deployment ID rather than the flow ID. You can find it on a deployment page of your flow:

Hi Anna,

Thanks for your quick answer !
It is a mistake in the name of the variable but it’s the good deployment id :face_with_peeking_eye:

1 Like

Can you delete and recreate your deployment using the latest Prefect version and using a work queue name rather than tags?

No change … :confused:

We managed to update everything to prefect 2.4.2 and delete, recreate our deployment.
But still, we got the same answer … :confused:

Would be helpful in the future to add a swagger doc to your cloud api

You do not have any interactive swagger doc linked to your API?
Something like

https://api.prefect.cloud/api/docs

or

https://api.prefect.cloud/api/accounts/316eecbc-e7fe-4457-b47f-e925ff3ffd43/workspace/ed8c9a67-6cbe-4eea-b713-762dd9a64ba2/docs

Could be definitely helpful to quickly interact

I don’t know why this doesn’t work, can you try using exactly the same example I used + optionally add “X-PREFECT-API-VERSION” = your_prefect_api_version (atm 0.8.0) to your request headers? did you try just with curl?

thanks for the Swagger docs suggestion, afaik we deliberately don’t expose the entire API to every user of your workspace for security and access control reasons, but if you need that, reach out to sales@prefect.io perhaps we can expose that for some Admin users in your Cloud workspace

1 Like