Script Credentials & Allowed Domains
What credentials are for
A credential is a secret stored once for your company: an API key, a password, a Plex login, an ODBC access token, or the settings for an OAuth 2.0 sign-in. Scripts and workflows use a credential by its name, so the secret never appears in your code, and changing it in one place updates every script that uses it.
Credentials are encrypted when stored and never sent back to the browser. Nobody, including administrators, can read a stored value on screen. When you edit one, the secret fields stay empty; leave them blank to keep the stored value.
Where credentials live
Open Script Engine › Credentials. The page lists your Company-Wide Credentials with their Name, Type, Description, Status and Last Updated. Each row has a Who can use it link to the credential's rules page.
The same list appears in the script editor: click the gear button (Script settings) and open the Credentials section. A credential you add there is also company-wide.
You need the DataMagik - Builder or DataMagik - Security permission to see and manage credentials. Once a restricted credential's rules are enforced, it is listed only for the people who may see it.
Never put a secret in the Description. The description is shown to everyone who can open the credentials page. Put the secret only in the secret fields.
Adding a credential
- Click Add Credential.
- Enter a Credential Name in UPPER_SNAKE_CASE: it must start with an uppercase letter and contain only uppercase letters, numbers and underscores, such as
PLEX_BASIC_AUTHorSHIPENGINE. - Choose the Type. The fields below change to match it (see the table).
- For an API key or token, you can fill in Send it only to these hosts so scripts send it without ever reading it. See Allowed hosts.
- Optionally add a Description, such as what the credential is for and who owns it.
- Click Save Credential.
Deleting a credential cannot be undone, and any script that uses it will fail. A credential whose status is Inactive is not given to scripts. A credential limited to listed items can only be changed or deleted by its stewards.
Credential types
| Type (as shown) | What you enter | Used by |
|---|---|---|
| API Key, Bearer Token, Password, OAuth Token, Secret (generic) | One Value. | fetch(url, {credential: "NAME"}) once it has allowed hosts; otherwise credentials.get(). In a workflow, the HTTP Request step's Bearer token (credential) and Credential as a header sign-ins. |
| Basic Auth (username:password) | A username and a password. | plex.execute() and the Plex Data Source workflow step (your Plex web services login). The HTTP Request step's Basic (credential) sign-in. credentials.get() returns the username and password already Base64-encoded, ready to follow Basic in an Authorization header. |
| ODBC Connection | Host (default odbc.plex.com), Port (default 19995), Username and Access Token (PAT). Tick Set as default for this credential type to make it the company's default. | odbc.executeQuery() and the other odbc functions, the SQL Editor's Data Source list, and the ODBC Query workflow step. See Plex API Access. |
| Plex Connect (REST API) | Consumer Key (API Key) from your app in the Plex Developer Portal (sent to Plex as the X-Plex-Connect-Api-Key header). Optional Default PCN and Default Tenant Id. Consumer Secret (optional) is not used yet. | plex.api.call() and the Plex API workflow step. |
| OAuth 2.0 (sign in to an API) | Token URL (must start with https://), Client ID, Client secret, optional Scope and Audience, the Grant type, and how to Send the client ID and secret: In the Authorization header (most APIs) or As form fields. | http.oauthToken() in a script, and the HTTP Request step's OAuth 2.0 (credential) sign-in. |
Plex logins (Basic Auth, ODBC and Plex Connect) also show a Plex PCN block. Press Check now to have DataMagik confirm which plant the login reaches (Verified from Plex), and for ODBC and Plex Connect logins, which other plants it reaches through enterprise views.
Signing and certificate credentials
- AWS access key (Signature V4): access key ID, secret access key and an optional session token. The HTTP Request step and Apps steps set to AWS Signature V4 (with the region and service) have DataMagik sign each request, for S3, SQS, SNS, API Gateway and other AWS services.
- OAuth 1.0 token (NetSuite TBA): consumer key and secret, token ID and secret, the realm (the NetSuite account ID) and the signature method (HMAC-SHA256 by default). Steps set to OAuth 1.0, token-based are signed with it.
- Client certificate (mutual TLS): the certificate and its private key, as PEM (the key not encrypted). Steps with a Client certificate present it to the API, and to the OAuth 2.0 token URL, as ADP requires.
In a script, name them in fetch: { sign: { kind: "aws4", credential: "S3", region: "us-east-1", service: "s3" } }, { sign: { kind: "oauth1", credential: "NetSuite" } } or { clientCertificate: "ADP certificate" }, and http.oauthToken(name, { clientCertificate }). DataMagik signs or presents them; the script never handles the secret. On an edit, fields left blank keep their stored values.
OAuth 2.0 grant types
- Client credentials (the app signs in): the client ID and secret are enough. This is the usual choice for system-to-system work.
- Password (a user signs in): also asks for a username and password.
- Refresh token: also asks for a refresh token.
- Sign in with the provider (authorization code): for APIs where a person must sign in and agree once, such as Google, Microsoft 365, Salesforce, HubSpot and QuickBooks. Also asks for the provider's Sign-in (authorization) URL, and shows the Redirect URI to register in the provider's app settings. Save the credential, then click Connect on it in the list: you sign in to the provider, and DataMagik stores the refresh token it returns. The list then shows it as Connected. Include the scope that returns a refresh token (often
offline_access). Changing the client ID, sign-in URL, scopes or audience needs a new Connect; Reconnect signs in again at any time. Only someone who may change the credential can connect it, and the sign-in must be finished by the person who started it.
DataMagik gets the access token and renews it for you. Add the token URL's domain to the allowed-domains list (below) as well as the API's own domain.
Who and what may use a credential
By default every script and automation in the company may use every credential, as it always has. Each credential can be locked down on its rules page (Who can use it):
- Which items may use it, and whether a script may read the password itself. See Which items may use a credential.
- Which people and roles may see, run, build with or manage it. See Who may use a credential.
- Stewards who look after it and answer requests.
New rules start in a 14-day trial that only counts. See Credential rules for the overview and Trial and enforcement.
In a Site, items can also use a Plex login the parent shares, by its name or through a binding on Site setup. See Sharing credentials with Sites.
Using a credential in a script
Helpers that take a credential name
Most of the time you pass the credential's name to a helper, and the platform uses the secret for you. The script never sees it:
| Helper | Option | Credential type |
|---|---|---|
fetch(), fetchAsync() | { credential: "NAME" } | API key, bearer token, basic auth, password, OAuth token or secret with allowed hosts |
plex.execute() | credentialName | Basic Auth |
plex.api.call() | credentialName | Plex Connect (REST API) |
odbc.executeQuery(), odbc.execute() | credential in the options (optional) | ODBC Connection |
http.oauthToken() | its only argument | OAuth 2.0 |
plex.api.call() only sends to https://connect.plex.com or https://test.connect.plex.com. Pass a path such as /mdm/v1/customers rather than a full URL, and isTest: true for the test tier.
credentials.get(name)
credentials.get("NAME") returns the credential's value as text, or undefined when there is no active credential with that name. Check for that before you use it. It does not return:
- a credential with allowed hosts: it throws an error telling you to send it with
fetch(url, {credential: "NAME"})instead; - a Plex login the parent company shares with your Site: it returns
undefined, because shared logins can only sign Plex calls; - a credential whose enforced rules refuse this use: it throws an error that starts with
credential refused:, names the credential, and says a steward can grant access. This happens, for example, when the credential is limited to listed items and this script is not listed with Read the password and approved by a steward. See Which items may use a credential.
function main(context) {
const apiKey = credentials.get("CARRIER_API_KEY");
if (!apiKey) {
return { success: false, script_message: "Credential CARRIER_API_KEY is missing or inactive" };
}
// Better: give CARRIER_API_KEY allowed hosts and use fetch(url, {credential: "CARRIER_API_KEY"})
const resp = fetch("https://api.carrier.example.com/v1/rates", {
method: "POST",
headers: { "Authorization": "Bearer " + apiKey, "Content-Type": "application/json" },
body: JSON.stringify({ zip: context.zip, weight: context.weight })
});
if (!resp.ok) {
return { success: false, script_message: "Rate request failed: HTTP " + resp.status };
}
return { success: true, data: resp.json() };
}
For the structured types (ODBC Connection, Plex Connect, OAuth 2.0), credentials.get returns the stored settings as JSON text. Use the helper for that type instead of reading them yourself.
Signing in with OAuth 2.0
http.oauthToken("NAME") returns { ok, accessToken, tokenType, expiresIn }, or { ok: false, error } if the sign-in fails. The token is cached and renewed a minute before it expires, so call it before each request instead of keeping the token yourself.
function main(context) {
const t = http.oauthToken("PARTNER_API");
if (!t.ok) {
return { success: false, script_message: t.error };
}
const resp = fetch("https://api.partner.example.com/v1/orders?status=open", {
headers: { Authorization: "Bearer " + t.accessToken }
});
if (!resp.ok) {
return { success: false, script_message: "Partner API returned HTTP " + resp.status };
}
return { success: true, data: { orders: resp.json() } };
}
Using a credential in a workflow
Workflow steps that need a credential have a picker that lists the credentials of the right type: Plex credential on the Plex Data Source step, Plex Connect credential on the Plex API step, ODBC credential on the ODBC Query step, and the Credential or OAuth 2.0 credential on the HTTP Request step once you choose an Authentication option. A key with allowed hosts is sent by the platform as its header, so the step never reads it. A Code step can call credentials.get like a script.
Keeping secrets out of logs
- Scripts: nothing is masked for you. Whatever you pass to
console.log, or put in what the script returns, is stored in the run's record under Executions exactly as written. Never log a credential, an Authorization header or a full token response. Sending keys with allowed hosts avoids the problem: the script never has the key. - Workflows: the run trace replaces the values of credentials the steps used with
••••, and masks fields whose names look like secrets (password, secret, token, API key, authorization, cookie, private key, credential) in step output, logged objects and error messages. Treat this as a safety net, not permission to log secrets: a credential written into a plain text log line in a Code step is not masked.
Allowed domains
The allowed-domains list names the outside hosts your scripts may call. It applies to fetch(), fetchAsync(), http.get(), the token URL used by http.oauthToken(), files a script downloads with helpers.toBase64() or documents.mergePdf(), the _navigation URL a script returns, and the workflow HTTP Request step.
It does not apply to the helpers that call Plex for you (plex.execute, plex.api.call, odbc) or to links to DataMagik's own documents. It is also not a record of every outbound connection DataMagik makes: the Git hosts used for source control, for example, are configured separately.
Allowed domains are for the whole company. A credential's own allowed hosts are a second, narrower list: where that one key may be sent. See Allowed hosts.
Where to manage it
- Open any script in the editor and click the gear button (Script settings).
- Open the Allowed Domains section and click + Add.
- Enter the Domain without
https://or a path, such asapi.example.com. Optionally add Notes (Optional) saying what it is used for. - Click Add Domain.
The list belongs to the company, not to the script you opened it from. Adding and removing domains needs the DataMagik - Builder permission. Only add hosts you trust.
How matching works
| Entry | Allows | Does not allow |
|---|---|---|
api.example.com | api.example.com only | example.com, eu.api.example.com |
*.example.com | Any subdomain at any depth: api.example.com, eu.api.example.com | example.com itself (add it separately) |
- Matching ignores upper and lower case and ignores the port:
api.example.comalso allowshttps://api.example.com:8443/. - A wildcard must name a real domain after
*.; entries that are too broad are refused. - An empty list allows no outside hosts.
What happens to a host that is not on the list
For helpers.toBase64(), documents.mergePdf() and _navigation, the call is refused. For fetch(), fetchAsync() and http.get(), the run's console gets a warning that starts with [allowed-domains] and names the host, and the warning says the request will fail once enforcement is enabled. Add every host your scripts call now, so they keep working when it is.
Private and local addresses are always blocked
Scripts cannot reach localhost, loopback, private network ranges (such as 10.x.x.x and 192.168.x.x), link-local and cloud metadata addresses, or host names ending in .local, .internal, .private or .localhost. Only http and https URLs are allowed. Adding such an address to the list does not change this, and the run's console says [blocked] with the reason. Redirects are checked the same way, and a request stops after 5 redirects.
To reach a system on your own network, use the on-prem connector instead: bridge.fetch() for an HTTP API registered under Connectors › API Bridge, or localdb for a database registered under Connectors › Local Databases.
AI provider keys are separate
The keys for OpenAI, Anthropic, Gemini and other AI providers are not script credentials. They are managed on the AI Provider Keys page, under Admin › Company Provider Keys. Scripts that call ai.complete() or ai.extract() use the company's key from that page; you do not pass a credential name. Credential rules do not cover AI keys, FTP logins or notification channels yet.