Authenticating to Domo¶
Every crew-dcs script starts the same way: an auth object that tells the library who you are and which Domo instance to talk to. This page gets you from nothing to a script that prints the name of the user your token acts as, then goes deeper on the other credentials and on a safe pattern for automation.
Keep your credentials off the internet
An access token can do whatever its user can do. Never paste it into code you
commit, a chat, a forum post or a screenshot. This page keeps it in a .env
file that stays on your machine.
Your instance is the first part of your Domo address. If you sign in at
mycompany.domo.com, your instance is mycompany.
Which credential should I use?¶
Domo gives you three ways to prove who you are. Start with the first.
- Access token (
DomoTokenAuth): a long password you create for your own user in Domo. Use this for scripts and automation. It is the simplest, and it is the one this page walks through. - Client ID and secret (
DomoDeveloperAuth): credentials for an app registered in the Domo Developer Portal. Use it when you are building an app on the Domo developer platform, not for an admin script. - Username and password (
DomoFullAuth): your normal Domo sign-in. Keep it for cases where a token will not do, because it puts a real password in your script.
The happy path: a working script in four steps¶
1. Create an access token in Domo¶
In Domo, open Admin → Authentication → Access tokens and create a new token.
Give it a name that says what it is for, such as my-first-script, set an
expiration date, and copy the token when it is shown. The menu path may differ
by Domo version. If you cannot find it, see Domo's
Managing Access Tokens
article.
A token acts as the user it was created for (its owner), and can do anything that user can do. The token list in Domo shows the owner next to each token (check against your Domo version).
2. Put it in a .env file¶
A .env file is a plain text file named exactly .env that sits next to your
script. It holds settings as NAME=value lines, so your script can read them
without the secret being written inside the code.
DOMO_INSTANCE=mycompany
DOMO_ACCESS_TOKEN=paste-your-token-here
Replace mycompany with your instance and paste your token after the = sign,
with no quotes and no spaces. Each NAME is an environment variable: a
named setting that a program can read while it runs.
Never commit .env
If your folder is a git repository, add .env to its .gitignore file so it
is never uploaded. Anyone who sees the token can act as you in Domo.
3. Run the script¶
Save this as who_am_i.py next to your .env file:
import asyncio
import os
from dotenv import load_dotenv
from crew_dcs.auth import DomoTokenAuth
load_dotenv() # copies the lines in .env into environment variables
async def main():
async with DomoTokenAuth(
domo_instance=os.environ["DOMO_INSTANCE"],
domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
) as auth:
res = await auth.who_am_i()
user = res.response
print(user["displayName"], "-", user["emailAddress"])
asyncio.run(main())
Run it with uv run python who_am_i.py from the project folder where you
installed crew-dcs. (If you installed crew-dcs into a virtual environment
instead, activate it and run python who_am_i.py.) The script reads your .env
file with python-dotenv, which crew-dcs installs for you. You should see the
name and email of the token's owner:
Jane Admin - jane.admin@mycompany.com
Three Python ideas you just used:
async defandawaitmark code that waits on the network. crew-dcs makes every Domo call this way, so many calls can run at the same time.asyncio.run(main())starts that waiting code from an ordinary script. You write it once, at the bottom of the file.async with ... as auth:opens the connection and closes it for you when the block ends. Without it, callawait auth.close_session()when you are done.
In Jupyter you can skip asyncio.run
A notebook already runs an event loop, so there you can write
await auth.who_am_i() directly in a cell.
4. Check it in Domo¶
Open the access token you created (Admin → Authentication → Access tokens;
the menu name may differ by Domo version) and look at the owner shown on it (check against your Domo version). The
name and email your script printed should match that owner. If they do not, you
copied a different token, or put the wrong one in .env.
If the script raises an error instead, stop and fix the credential first. See Troubleshooting. Once this works, go on to Your first script.
Why the user behind the token matters¶
Access tokens are created in your instance under Admin → Authentication → Access tokens (Domo KB). An access token is tied to a specific user and inherits that user's permissions: anything the user can do, the token can do. If the user's role changes, the token's effective access changes with it. Tokens get a description and an expiration date, and admins can revoke them any time from the same page.
API client credentials (Client ID + Secret) are created in the
Domo Developer Portal.
These are OAuth2 client_credentials: your app exchanges the ID/secret for a
short-lived bearer token, then refreshes it as needed. This is the right shape
for applications (Domo Apps, connectors, anything user-facing) because the
credential identifies the app, not a person.
Rule of thumb: writing a script that automates your instance (move cards, swap datasources, document dataflows)? You want an access token. Building software other people install? You want client credentials.
Best practice: the access-token account pattern¶
Because an access token inherits a user's permissions, which user you attach matters more than anything else on this page. What we recommend, and practice ourselves:
- Create a dedicated service-account user (e.g.
svc-automation@yourco.com) and generate tokens for that user, never for a human's account. If the person who wrote the script leaves the company, their offboarding doesn't silently kill your pipelines, and the blast radius of a leaked token is limited to what the service account can do. - Grant least privilege. The service account gets the roles/grants the automation actually needs, nothing more. You can always widen later.
- One token per purpose, named after its job (
etl-docs-nightly,card-datasource-migration), each with an expiration date. When something goes wrong, the token name tells you which script is responsible, and you can revoke one purpose without touching the others. - Treat tokens like passwords. Store them in a
.envfile that is git-ignored (or a real secrets manager), never hard-code them, never commit them. Rotate on suspicion; revocation is one click in Admin.
crew-dcs auth classes, mapped to the credentials¶
| Credential | crew-dcs class | Use it for |
|---|---|---|
| Access token | DomoTokenAuth |
Scripts and automation (most readers) |
| Client ID + Secret | DomoDeveloperAuth |
Apps on the Domo developer platform |
| Username + password | DomoFullAuth |
Legacy flows; avoid when a token works |
| Jupyter workspace token | DomoJupyterTokenAuth |
Calling the workspace API itself |
DomoTokenAuth and who_am_i()¶
The happy path above is the full DomoTokenAuth script. Call who_am_i() once
before running anything bigger: it confirms the token works and shows whose
permissions you are using.
Client credentials: DomoDeveloperAuth¶
from crew_dcs.auth import DomoDeveloperAuth
auth = DomoDeveloperAuth(
domo_client_id=os.environ["DOMO_CLIENT_ID"],
domo_client_secret=os.environ["DOMO_CLIENT_SECRET"],
domo_instance=os.environ["DOMO_INSTANCE"],
)
Same rule for the secret
Keep the client ID and secret in .env, never in code you share.
The library handles the OAuth handshake and bearer-token refresh for you; that's
the main reason to prefer it over hand-rolling requests. One difference:
DomoDeveloperAuth.who_am_i() returns only the user id, so print
res.response["id"] instead of the name and email.
Inside Domo Jupyter Workspaces¶
Domo Jupyter Workspaces are a special case, because there are two "auth" stories depending on what you're doing:
- Reading/writing DataSets from a notebook: use Domo's own
domojupyterlibrary (import domo;domo.read_dataframe(...)). The workspace is already authenticated to the instance; you don't manage a token at all (Domo KB). - Driving the workspace itself: listing workspaces, pulling configs, automating workspace lifecycle. That's the Jupyter server API, and it needs a workspace token plus the service location/prefix:
from crew_dcs.auth import DomoJupyterFullAuth
auth = DomoJupyterFullAuth(
jupyter_token=os.environ["JUPYTER_TOKEN"],
service_location=os.environ["JUPYTER_SERVICE_LOCATION"],
service_prefix=os.environ["JUPYTER_SERVICE_PREFIX"],
domo_instance=os.environ["DOMO_INSTANCE"],
domo_username=os.environ["DOMO_USERNAME"],
domo_password=os.environ["DOMO_PASSWORD"],
)
This one holds a real password
The Jupyter token and your Domo password both go in .env, never in the
script. Do not commit .env or paste these values anywhere public.
See the Jupyter Workspaces guide for the workspace
management classes (DomoJupyterWorkspace, DomoJupyterWorkspaces).
Troubleshooting¶
| Symptom | Likely cause |
|---|---|
InvalidCredentialsError from who_am_i() |
Token revoked, expired, or pasted with whitespace |
InvalidInstanceError from who_am_i() |
Domo answered 403 Forbidden, which the code treats as a wrong instance. Check the spelling in DOMO_INSTANCE. |
| A connection error instead | A mistyped instance may fail before Domo answers at all (unverified). DOMO_INSTANCE must be only the mycompany part: a value like mycompany.domo.com builds the host mycompany.domo.com.domo.com, which most likely fails this way. |
KeyError: 'DOMO_ACCESS_TOKEN' |
.env is not next to the script you ran, or the name is misspelled |
| Calls work for reads, fail for writes | Token's user lacks the grant. Check the user, not the token |
| Worked last month, dead now | Token expiry date passed, or the underlying user was deactivated |
| Works locally, fails in CI | .env not deployed; put the token in your CI secret store |
Still stuck?¶
First upgrade crew-dcs to the latest version, because bugs are fixed often. If it still fails, ask in the DataCrew community Slack: datacrew.space/slack.