Use saved credentials in code
When your code scripts or code workflows call external APIs using MCP.Atomicwork.executeHttpRequest, you can reference saved credentials by name instead of putting secrets in your code. Two helpers make this work:
Before using these helpers, save the credential in Settings > Organization > Security > Credential store with its allowed hosts. See Managing credentials for setup, credential types, and allowed-host rules.
Parameters
- credential — the saved credential’s name (recommended) or its numeric ID. Names survive re-creating a credential, so prefer them.
- field — selects a top-level key from a JSON credential, such as
client_id. Without it, you get the whole value. Nested keys likeclient.idare not supported. - prefix / suffix (
aw.secretHeaderonly) — header-safe text up to 256 characters, such as"Bearer "or"SSWS ". You can’t concatenate a secret with+or use it in a template string — useprefix/suffixinstead. - Basic auth with no field —
aw.secretHeadersendsbase64(username:password). You can also select theusernameorpasswordfield individually.
Where they work
All HTTP methods work: GET, POST, PUT, PATCH and DELETE. Up to 8 secret headers and 16 secret body fields per request.
Code Library scripts are plain JavaScript — leave out type annotations like (res: any), and end the script with return await main();. Code workflows are TypeScript.
Code recipes
Bearer token in a header
Microsoft Entra app token, then Microsoft Graph
A two-step flow: exchange client credentials for an access token, then use that token to call the Graph API. The access token comes from a response, so it’s ordinary data — only the saved credentials in the first call need aw.secret.
Don’t log or return access tokens from token endpoints — console.log(res) on a token call writes the token to the run log.
Basic auth
A Basic-auth credential with no field is sent as base64(username:password).
Several values from one JSON credential
Use an “API key holding JSON” credential to keep related values together, then pull each field by name:
Two credentials in two headers
Supported and not supported
Move existing code over
- Find keys in your scripts: look for
Bearer,SSWS,client_secret,api_key,passwordand long random strings. - Create a credential for each one in Settings > Organization > Security > Credential store, with its allowed hosts.
- Replace each key with
aw.secretHeader(headers) oraw.secret(body fields). - Test once, then publish.
- Rotate the old key at the vendor — it was in code, so treat it as exposed.
Before:
After:
Tell a refused request from a vendor error
A request that fails the credential check comes back with the same shape as a vendor error. The body tells them apart:
Errors
From your code (before the request leaves)
These throw at the offending line before anything is sent. Wrap the call in try/catch if you want to return a message instead.
From the request check (nothing was sent)
From the vendor (the request was sent)
Learn more
-
Managing credentials — setting up credentials, credential types, and allowed hosts
-
Code actions — writing code scripts, testing, and using AI Assist
-
HTTP requests — using saved credentials in workflow HTTP request actions
-
Use Call API actions in workflows — calling connected apps from code (no credentials needed)
