Hi everyone, I'm exploring Prefect REST API. Auth...
# prefect-cloud
d
Hi everyone, I'm exploring Prefect REST API. Authentication request fails with 401 (Unauthorized). Here is my request using curl: curl --request POST 'https://api.prefect.cloud/auth/login' --header 'Content-Type: application/json' --header 'Authorization: Bearer <Service Account API key>' I validated service account api key using cli: prefect auth login --key <Service Account API key> With cli I'm able to login successfully. Does anyone know why my authentication request fails? Thanks, Dmitry
j
I think that API (/auth) is meant for browser authentication only, I’d suggest trying an authenticated read (e.g. GET) API instead (e.g. /api)
d
Hi Jonathan, thanks for your response. I tried GET: curl --location --request GET 'https://api.prefect.cloud/api/accounts/permissions' --header 'Authorization: Bearer ....' I'm still getting 401
j
this worked for me:
Copy code
curl  --location --request GET --header "Authorization: Bearer pnu_xxx" <https://api.prefect.cloud/api/me/>
d
Thanks. It doesn't work for me. I'm using service account API key as a Bearer token. Is that what you use?
j
I was using a user API key token, I’m not sure if service accounts have the same permission for this API 🤔
d
Hi Jonathan, thanks again for your response. I generated personal API key but I'm still getting 401. I found another way to implement what I'm trying to do with Python and GraphQL. I will investigate issue with REST API authentication later when I have more time. Thanks again! Regards, Dmitry
x
Looks like not many people used the /auth/login endpoint as no reply to my question for the last two days. Yes, I am getting the 401 with pnu_xxxx token. Here is my test code:
Copy code
def login():
    auth_token = 'pnu_xxxxxxxxxxxxx'
    hed = {'Authorization': 'Bearer ' + auth_token}
    response = <http://requests.post|requests.post>('<https://api.prefect.cloud/auth/login>', headers=hed)
    print(response.headers)
    print(response)
    print(response.json())
If change to GET, it returns http 200 with an empty body plus a lot of values in the header. According to the API doc, this endpoint should be working. Wonder if it is actually not working at this point without anyone noticed. Any advice?
j
Can you create an issue in the prefect repo? https://github.com/PrefectHQ/prefect If you have a support agreement, then filing a ticket should be faster
1
x