# PayPal API tokens: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/paypal
Last checked: 2026-11-08

PayPal REST API credentials are a client ID and client secret per app, found in the PayPal Developer Dashboard under **Apps & Credentials**. You exchange the PayPal client ID and secret at `/v1/oauth2/token` for a bearer access token that expires after the `expires_in` seconds in the response, and sandbox and live apps have separate credentials.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| REST app client ID | — | No | Identifies your REST app | — |
| REST app client secret | — | Yes | Authenticates your REST app when requesting access tokens | — |
| OAuth access token | — | Yes | Bearer token for REST API calls, obtained with the client credentials grant | Returned in `expires_in` seconds; request a new one when it expires |

## How to create a PayPal key

1. Log in to the PayPal Developer Dashboard and select **Apps & Credentials**.
2. Under **REST API apps**, use the Default Application or click **Create App**.
3. Copy the client ID and client secret for the app and store the secret in a secrets vault.
4. POST them to `/v1/oauth2/token` with HTTP Basic auth and `grant_type=client_credentials` to get an access token.

## Limiting what the key can do

PayPal does not offer narrower keys within one REST app. Use a separate app, and so separate credentials, for each environment and role, as PayPal's security guidelines recommend. A 403 `NOT_AUTHORIZED` response means the app lacks the OAuth scope or permission for that call.

## How to rotate a PayPal key

1. Open **Apps & Credentials** in the PayPal Developer Dashboard and select the app.
2. Generate new credentials for the app using the dashboard's credential management tools.
3. Deploy the new client secret to every service, then revoke or remove the old credentials.

## How to revoke a PayPal key

1. Open **Apps & Credentials** in the PayPal Developer Dashboard, select the app and revoke the credentials you no longer use.

## If the key leaked

1. Revoke the exposed credentials in **Apps & Credentials** and generate replacements.
2. Update every deployment with the new client secret and request new access tokens.
3. Review recent transactions and API activity on the account for anything you did not initiate.
4. Use separate credentials per environment so a sandbox leak never reaches live funds.

## Environment variables

- `PAYPAL_CLIENT_ID`
- `PAYPAL_CLIENT_SECRET`
- `PAYPAL_ACCESS_TOKEN`
- `PAYPAL_ENVIRONMENT`

## Gotchas

- The sandbox token endpoint is `https://api-m.sandbox.paypal.com/v1/oauth2/token`; sandbox and live use separate credentials.
- Client ID and secret are sent with HTTP Basic auth (Base64 of `CLIENT_ID:CLIENT_SECRET`) and body `grant_type=client_credentials`.
- The PayPal MCP server (`@paypal/mcp`) takes an access token in `PAYPAL_ACCESS_TOKEN`, not the client secret, plus `PAYPAL_ENVIRONMENT` set to `SANDBOX` or `PRODUCTION`.
- A PayPal Business account is needed to go live.

## Using this key with AI agents (BotPassword)

- `run_with`: Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
- `http_request`: Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused.
- `store_secret`: Saves a value the agent already holds as a new vault item.

## FAQ

### Where do I find my PayPal client ID and secret?

In the PayPal Developer Dashboard under **Apps & Credentials**, in the REST API apps section.

### How do I get a PayPal access token?

POST to `/v1/oauth2/token` with Basic auth (client ID and secret) and `grant_type=client_credentials`; the response includes `access_token` and `expires_in`.

### Do PayPal sandbox and live use the same credentials?

No. Sandbox apps and live apps have separate client IDs and secrets, and going live requires a PayPal Business account.

### Why does PayPal return invalid_client?

The `Authorization` header is missing or the Base64-encoded client ID and secret are wrong, often because sandbox credentials were sent to the live endpoint.

### Does a PayPal client secret expire?

PayPal's REST docs give no expiry for the client secret, but PayPal recommends rotating credentials regularly. Access tokens expire after `expires_in` seconds.

### Can an AI agent use my PayPal key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a `.env` file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with `run_with`, `http_request`, `store_secret`, so the agent gets the result and never the value.

## Sources

- https://developer.paypal.com/api/rest/
- https://developer.paypal.com/api/rest/authentication/
- https://developer.paypal.com/api/rest/responses/
- https://developer.paypal.com/security-guidelines
- https://developer.paypal.com/ai-tools/toolkit
