Error while generating API Key from a service user for AYON Python api

I am facing a problem while generating api key for a service user from the ayon web app.

I created a new user(Active User) as a service user and generated the api key. I used the api key generated to create an instance of ServerAPI(from ayon-python-api). Later if I retrieve any information using the connection I created with the instance of ServerAPI, it is giving me the following error:
Example:
from ayon_api.server_api import ServerAPI
connection = ServerAPI(base_url="url_goes_here", token="token_goes_here")
connection.get_project_names(active=True)
The above code gives me the error:
ayon_api.exceptions.HTTPRequestError: 401 Client Error: Unauthorized for url:

But when I login after creating the instance of the ServerAPI and then call the method it works properly.
Example:
from ayon_api.server_api import ServerAPI
connection = ServerAPI(base_url="url_goes_here", token="token_goes_here")
connection.login("service_user_username", "service_user_password")
connection.get_project_names(active=True)
The above code gives me the result:
['demo_Big_Episodic', 'demo_Big_Feature', 'demo_Commercial']

Am I missing any step while generating the api key or do we need to login before calling any method from the ServerAPI instance.
I would really appreciate any guidance on this topic.

I’ll have a look once I have some spare time. It does work after login, because login will create new token (different from the one you pass on initialization).

1 Like

Sure. Thanks a lot for responding.

Issue should be resolved now.