To enable programmatic use of data as if "attached" to a given session, an administrator can configure the server to let users obtain a Session Key
Enable Session Keys
- Select (Admin) > Site > Admin Console.
- Click the Admin Console Links tab.
- Under Configuration, click Site Settings.
- Under Configure API Keys, check Let users create session keys.
Access and Use a Session Key
Once enabled, the user can log in, providing all the necessary compliance information, then retrieve their unique session key from the username > API Keys
Click Generate Session Key
. The session key is a long, randomly generated token, beginning with the prefix "session|" that is valid for only this single browser session. Click Copy to Clipboard
to grab it (the button will read "Copied!" when copied). Then click Done
You can then paste this key into a script, tying that code's authorization to the browser session where the key was generated. The session key can also be used in a .netrc file or via an external client that supports Basic authentication, as shown in API Keys
. When using a session key, the code's actions and access will be logged with your user information and assertions you made at login time.
For example, if you were accessing data via R, the following shows the usage:
labkey.setDefaults(apiKey="session|the_rest of the_long_string_session_id")
You will then be able to access the data from R until the session associated with that key is terminated, whether via timeout or log out.