When we look at the workspaces section of the Reference, we see that to create a new workspace, we must use the POST method on the
/workspaces endpoint, which corresponds to the operation ID
Other fields accepted in the body are
restrictedSharing, but they are optional because they have a default value.
Because inserting a workspace involves various calls on the Drive API, it can take some time. Therefore, the operation is done asynchronously and the API response is empty.
A way to programmatically wait for a workspace to be created is to try getting the workspace resource thanks to the
workspaces.getByName endpoint at regular intervals:
found = False
while not found:
results = client.workspaces().getByName(
if "workspaces" in results:
my_projects_workspace = results["workspaces"]
found = True
The snippet of code above tries getting the workspace we just inserted thanks to its name "MyProjects". the
workspaces.getByName endpoint returns a list of workspaces having the given name (multiple workspaces can have the same name) in the
workspaces field. We test whether the field is set (at least one workspace found) or not (no workspace found) and if that's the case, we take the first element of the list and end the loop. Otherwise, we wait 10 seconds before looping.
It shouldn't take more than a few iterations before obtaining the workspace.