Get current workspace without the need for token

Description of the limitation and why it is relevant to address

As a developer I want to be able to access the current workspace (Workspace object) from within the workspace (for example by calling API().get_current_workspace()) so that I can use the workspace information (such as name, visibility, app version, …) in my app.

Current workarounds

Currently, one can access the “current” workspace by calling

# workspace_id is available via kwargs
API(token="TOKEN").get_workspace(workspace_id)

Notice that token needs to be provided, otherwise it does not work. However, I don’t think that accessing the workspace from within the workspace should require a token. I don’t feel comfortable having the token as an environment variable for the app, as it can potentially be misused.

Proposed design

This can be done by:

  • Adding a “get_current_workspace()” method to API;
  • Allowing the workspace id of the current workspace to be passed to API().get_workspace(workspace_id) without the need to provide the api token.

Hi @Sina,

Sorry for the late response.
Since SDK version v14.7.1, workspace_id is added to the signature of controller methods and callback functions. So this can be accessed without using the API the same way as enitity_id enz.

v14.7.1
Current workspace and entity

I hope this helped.

Maarten

Hi Maarten,

Thank you for your reaction!

It is true that workspace_id can be accessed, but the workspace itself, cannot be accessed without the API and a token.

So this works:

API(token="TOKEN").get_workspace(workspace_id)

But this doesn’t:

API().get_workspace(workspace_id)

And my “feature request” is that it works without the need for a token.

Sorry, I misunderstood your question.
Thanks for makeing the request. We will look into this.

1 Like