> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://support.atomicwork.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://support.atomicwork.com/_mcp/server.

# Use saved credentials in code

> Reference saved credentials by name in code scripts and code workflows using aw.secret and aw.secretHeader — the secret never appears in your 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:

| Helper            | Signature                                                | Used for                                   |
| ----------------- | -------------------------------------------------------- | ------------------------------------------ |
| `aw.secret`       | `aw.secret(credential, { field })`                       | A JSON or form body field value            |
| `aw.secretHeader` | `aw.secretHeader(credential, { prefix, suffix, field })` | A header value, optionally wrapped in text |

Before using these helpers, save the credential in **Settings > Organization > Security > Credential store** with its allowed hosts. See [Managing credentials](/documentation/platform-administration/governance/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 like `client.id` are not supported.
* **prefix / suffix** (`aw.secretHeader` only) — 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 — use `prefix`/`suffix` instead.
* **Basic auth with no field** — `aw.secretHeader` sends `base64(username:password)`. You can also select the `username` or `password` field individually.

## Where they work

| Put the secret in…                           | Code Library scripts     | Code workflows |
| -------------------------------------------- | ------------------------ | -------------- |
| A header of `executeHttpRequest`             | Yes                      | Yes            |
| A JSON or form field of `executeHttpRequest` | Yes                      | Yes            |
| A header of `fetch`                          | Use `executeHttpRequest` | Yes            |

All HTTP methods work: GET, POST, PUT, PATCH and DELETE. Up to 8 secret headers and 16 secret body fields per request.

> **Note**
>
> **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

```javascript
const res = await MCP.Atomicwork.executeHttpRequest({
  url: "https://acme.okta.com/api/v1/users/me",
  method: "GET",
  headers: [
    { key: "Authorization", value: aw.secretHeader("okta-api-token", { prefix: "SSWS " }) },
  ],
});
```

### 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`.

```javascript
const tokenRes = await MCP.Atomicwork.executeHttpRequest({
  url: "https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token",
  method: "POST",
  headers: [
    { key: "Content-Type", value: "application/x-www-form-urlencoded" },
  ],
  form: {
    grant_type: "client_credentials",
    client_id: aw.secret("azure-app", { field: "client_id" }),
    client_secret: aw.secret("azure-app", { field: "client_secret" }),
    scope: "https://graph.microsoft.com/.default",
  },
});
const accessToken = JSON.parse(tokenRes.data.body).access_token;

const org = await MCP.Atomicwork.executeHttpRequest({
  url: "https://graph.microsoft.com/v1.0/organization",
  method: "GET",
  headers: [{ key: "Authorization", value: "Bearer " + accessToken }],
});
```

> **Warning**
>
> 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

```javascript
const res = await MCP.Atomicwork.executeHttpRequest({
  url: "https://api.vendor.com/v1/data",
  method: "GET",
  headers: [
    { key: "Authorization", value: aw.secretHeader("vendor-basic", { prefix: "Basic " }) },
  ],
});
```

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:

```javascript
form: {
  client_id: aw.secret("vendor-app", { field: "client_id" }),
  client_secret: aw.secret("vendor-app", { field: "client_secret" }),
  audience: "https://api.vendor.com",
}
```

### Two credentials in two headers

```javascript
headers: [
  { key: "Authorization", value: aw.secretHeader("vendor-api-key", { prefix: "Bearer " }) },
  { key: "X-Tenant-Key", value: aw.secretHeader("vendor-tenant-key") },
]
```

## Supported and not supported

| Pattern                                                              | Supported                                              | Alternative                                                                                                                                                                                         |
| -------------------------------------------------------------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Secret in a URL path or query string                                 | No — URLs appear in proxy and access logs              | Send it in a header with `aw.secretHeader`                                                                                                                                                          |
| Secret joined to other text (`"Bearer " + secret`, template strings) | No — code never holds the value                        | Headers: use `prefix` / `suffix`. Body: use the secret as the whole field value                                                                                                                     |
| Secret in a raw text, XML or SOAP body                               | No — only JSON and form fields can be filled in safely | Send the body with `fetch` and the key in a header with `aw.secretHeader`                                                                                                                           |
| Secret in a `fetch` body or `JSON.stringify`                         | No                                                     | Use `executeHttpRequest` with `json` or `form`                                                                                                                                                      |
| `fetch` with a secret in a Code Library script                       | No — scripts send HTTP through `executeHttpRequest`    | Use `executeHttpRequest`                                                                                                                                                                            |
| Signing requests (HMAC, AWS SigV4, signed JWT, certificate auth)     | No — signing needs the raw secret inside the code      | Ask the platform team for a native integration                                                                                                                                                      |
| Challenge-response auth (Digest, NTLM, Kerberos)                     | No — computed from the secret inside the client        | Use the vendor's token or API-key auth                                                                                                                                                              |
| Client certificates (mutual TLS)                                     | No — the credential store holds keys, not certificates | Ask the platform team                                                                                                                                                                               |
| More than 8 secret headers or 16 body fields per request             | No                                                     | Split into separate calls                                                                                                                                                                           |
| Nested JSON field (`client.id`)                                      | No — fields are top-level keys                         | Save the JSON flat: `{"client_id": …}`                                                                                                                                                              |
| Apps already connected under Integrations                            | Use the connection's own auth                          | Call them with `API.<app>…` via [Call API](/documentation/enterprise-workflows/actions-and-integrations/use-call-api-actions-in-workflows); use saved credentials only for APIs without a connector |

## Move existing code over

1. Find keys in your scripts: look for `Bearer `, `SSWS `, `client_secret`, `api_key`, `password` and long random strings.
2. Create a credential for each one in **Settings > Organization > Security > Credential store**, with its allowed hosts.
3. Replace each key with `aw.secretHeader` (headers) or `aw.secret` (body fields).
4. Test once, then publish.
5. Rotate the old key at the vendor — it was in code, so treat it as exposed.

**Before:**

```javascript
headers: [{ key: "Authorization", value: "SSWS 00aBc…" }]
```

**After:**

```javascript
headers: [{ key: "Authorization", value: aw.secretHeader("okta-api-token", { prefix: "SSWS " }) }]
```

## 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:

```javascript
const res = await MCP.Atomicwork.executeHttpRequest({
  url: "https://acme.okta.com/api/v1/users/me",
  method: "GET",
  headers: [{ key: "Authorization", value: aw.secretHeader("okta-api-token", { prefix: "SSWS " }) }],
});
let body = {};
try { body = JSON.parse(res.data.body); } catch (e) {}

const refused = body.message === "Credentials not allowed on this URL"
  || body.message === "Webhook execution failed.";
if (refused) return { ok: false, reason: "credential check failed: check the name, field and allowed hosts" };
if (res.data.status_code !== 200) return { ok: false, vendor_status: res.data.status_code };
return { ok: true, user_id: body.id };
```

## 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.

| Error message                                                                                         | Cause                                                                                  | Fix                                                                           |
| ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `aw.secret(...) is not a string: use it as a whole json or form value…`                               | Placeholder joined to text, put in a URL, or used in a template string                 | Use it as a whole field value; in headers use `aw.secretHeader` with `prefix` |
| `aw.secret(...) can only be used as a json or form value of MCP.Atomicwork.executeHttpRequest…`       | Placeholder in a `fetch` body, `JSON.stringify` or another tool                        | Use `executeHttpRequest` with `json` or `form`                                |
| `aw.secretHeader(...) is not a string: use it as the whole value of a header entry…`                  | Header placeholder joined to text, or put in a `fetch` header in a Code Library script | Use `prefix`/`suffix`; in Code Library scripts use `executeHttpRequest`       |
| `aw.secret is for json or form values; in headers use aw.secretHeader(credential, { prefix, field })` | `aw.secret` used as a header value                                                     | Switch to `aw.secretHeader`                                                   |
| `aw.secretHeader is for header values; in json or form use aw.secret(credential, { field })`          | `aw.secretHeader` used in a body                                                       | Switch to `aw.secret`                                                         |
| `Too many secret headers (at most 8)`                                                                 | More than 8 secret headers in one request                                              | Split the call                                                                |
| `Too many credential references`                                                                      | More than 16 secret body fields in one request                                         | Split the call                                                                |

### From the request check (nothing was sent)

| Response                                           | Cause                                                                                                                                                                                                                             | Fix                                                                                                                      |
| -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `403` with `"Credentials not allowed on this URL"` | The credential name isn't in your tenant, the field doesn't exist (including nested fields like `client.id`), the host isn't allowed, the URL uses `http://` or a port other than 443, or the credential has no allowed hosts yet | Check the name, field and allowed hosts in **Settings > Organization > Security > Credential store**, and use `https://` |
| `400` with `"Webhook execution failed."`           | The same header set both as a secret and literally (any letter case), a reserved header like `Host` or `Proxy-Authorization`, an object inside `form`, or a body on a GET                                                         | Set each header once; use a normal auth header; use `json` for nested data; send bodies with POST, PUT or PATCH          |

### From the vendor (the request was sent)

| Response                                                   | Cause                                                              | Fix                                                                       |
| ---------------------------------------------------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------- |
| 401/403 with the vendor's own body (e.g. `invalid_client`) | The saved value is wrong, expired or lacks permission              | Update the credential's value in the store or the vendor-side permissions |
| 3xx with a `Location` header                               | The API redirected; `executeHttpRequest` does not follow redirects | Call the final URL directly                                               |

#### Learn more

* [Managing credentials](/documentation/platform-administration/governance/managing-credentials) — setting up credentials, credential types, and allowed hosts

* [Code actions](/documentation/enterprise-workflows/actions-and-integrations/code-actions) — writing code scripts, testing, and using AI Assist

* [HTTP requests](/documentation/enterprise-workflows/actions-and-integrations/http-requests) — using saved credentials in workflow HTTP request actions

* [Use Call API actions in workflows](/documentation/enterprise-workflows/actions-and-integrations/use-call-api-actions-in-workflows) — calling connected apps from code (no credentials needed)