Skip to content

Generate and save an Enhance API key

Generate this token in Enhance when you want to use ApiMachine website bulk tools. Ordinary cPFence protection does not require it.

  1. Sign in to your Enhance control panel.
  2. Open Settings → Access tokens → Create Token.
  3. Choose Super admin and create the token. Keep it private.

To accept the token only from your server, turn on IP restricted. Then add each of these addresses to Allowed IPs and select Add after each one:

Address What to enter
The server itself 127.0.0.1/32
Main control panel server’s public IPv4 Its IPv4 address with /32, for example 203.0.113.10/32
Main control panel server’s public IPv6 Its IPv6 address with /128, for example 2001:db8::1/128. Skip this if the server has no IPv6.

Edit access token with Super admin, IP restricted on and three allowed IPs; 127.0.0.1/32 is highlighted.

Allowed IPs with 127.0.0.1/32 highlighted. The server's public IPv4 and IPv6 addresses are blurred. Select the image to enlarge it; use your browser's Back command to return.

Include 127.0.0.1/32 even though it is not a public address. cPFence sends its requests to your panel’s own address from the main control panel server, so Enhance can see them as coming from the server itself (127.0.0.1) or from its public address, depending on how that address resolves on the server. If the key does not validate while IP restricted is on, check these entries first.

  1. On the main control panel server’s WebUI, open Tools & Utilities → ApiMachine Bulk Tools → API key.
  2. Select Set a new key if a key is already saved, then enter the token privately.
  3. Select Save new API key, then check the validation result before running a bulk action.

Replace Enhance API Key form with an empty Enhance API Key field and Save new API key button.

Paste the token privately and save it. The screenshot leaves the key field empty; it does not show a submitted or validated token. Select the image to enlarge it; use your browser's Back command to return.

CLI alternative, from root on the main control panel server:

Terminal window
cpfence --set-enhance-api-key

Enter the key at the private prompt. cPFence validates it and stores the encrypted value locally. Keep the server’s configuration and your original token private. See how cPFence protects your Enhance API key for where it is stored and where it is sent.

In the WebUI, open Tools & Utilities → ApiMachine Bulk Tools → API key and select Test saved key. The result shows whether the key works and which control panel address cPFence uses.

CLI alternative:

Terminal window
cpfence --check-enhance-api-key

cPFence normally uses your control panel’s domain. If that domain does not resolve on the server, cannot be reached, or has no valid SSL certificate, cPFence uses the main control panel server’s local control panel API instead and says so. A main control panel server without a control panel domain uses the local API directly.

Message What to do
Invalid API key. Please check and try again. The token was mistyped, cut short or deleted. Copy the whole token again, or create a new one.
Invalid API key. Please check and try again. The token needs the Super admin role. Enhance also answers this way for a wrong or deleted token. Copy the whole token again and make sure it has the Super admin role. If IP restricted is on, add the addresses from the table above.
Could not check the API key: the control panel address … has no valid SSL certificate. Fix the control panel domain’s certificate in Enhance.
Could not check the API key: the control panel address … does not resolve on this server. Make the control panel domain resolve on the main control panel server (DNS or /etc/hosts).
Could not check the API key: the control panel address … is not reachable from this server. Allow the main control panel server to reach its own control panel on port 443.
Enhance refused the API key check (HTTP …) at … Enhance gave another reason, shown in the message. Contact support with the full message.
Sorry, this can only be run on your Main CP server Run the command on the main control panel server.

The three “Could not check” messages appear only when the local control panel API cannot be used either.

Next, follow website selection and bulk-action steps. If validation fails, check the token role, IP restriction, Enhance API access, and cPFence license before contacting support.