Skip to main content
Drupal is a registered trademark of Dries Buytaert
EOL Warning: Drupal 11.0 has reached end of life and no longer receives security updates. Release: Private content 3.1.0 Minor update available for module private_content (3.1.0). Release: Webform Analysis 2.0.0 Major update available for module webform_analysis (2.0.0). Usage Milestone: Focal Point Module focal_point crossed 1,000 active installs. Release: Changelogify 1.8.1 Minor update available for module changelogify (1.8.1). Release: Block Content Visibility 1.0.0 Initial release available for module block_content_visibility (1.0.0)! Release: Opensolr Search 4.3.1 Minor update available for module opensolr_search (4.3.1). Release: Opensolr Search 4.3.0 Minor update available for module opensolr_search (4.3.0). Release: Palette🎨 1.0.3 Minor update available for module canvas_palette (1.0.3). Release: Opensolr Search 4.2.4 Minor update available for module opensolr_search (4.2.4).

Migrate API Key

5 sites No security coverage Drupal 11 · not 10
View on drupal.org

This module allows you to securely add an API key to Drupal migration source URLs, making it useful for Drupal-to-Drupal migrations or querying any remote content that requires an API key. It prioritizes Pantheon secrets and falls back to environment variables for the API key.

Add an API key to Drupal migration source URLs

This module was created to support Drupal-to-Drupal migrations, but theoretically should work when querying any remote content that requires an API key to be passed as a query parameter.

How it works

It checks for the API key in Pantheon secrets first, then falls back to environment variables.

If the API key is not found or is empty, it adds a warning message in Drupal's logs but proceeds with the migration.

If you want to set up API keys for individual Drupal users, you can use the Key Auth module..

Security

To stay out of trouble (probably):

  • Never use the API keys of elevated users or Admins, lest they ever get intercepted.
  • This plugin does not encrypt or secure your API key in any way, it simply appends it to the source URLs of your migrations before they are sent as GET requests.
  • If migrating content from another Drupal site, it is advisable to create an 'API' Role with the bare minimum 'view' permissions of whatever entities your migration is fetching.
  • Only use it if your migrations are hitting HTTPS URLs!

Usage

  1. Ensure that the MIGRATE_API_KEY is set either as an environment variable or as a Pantheon secret. If developing locally, you may need to restart your dev environment after setting the environment variable.
  2. To any URL-based migration that requires the API key to be appended to its source URLs:
    1. Add the migration tag add_api_key (no longer required from 1.1.x), and
    2. Change the source plugin from url to migrate_api_key_url_plugin.
  3. Run your migrations as usual. The plugin will automatically append your provided API key to the source URLs.

Example

Setting environment variables for DDEV, in config.local.yml:

name: my-project
type: drupal10
web_environment:
  - MIGRATE_API_KEY=12345
...

Configuring a migration

id: example_migration
label: "Example Migration"
migration_group: example_group
migration_tags:
  - "add_api_key" <<< not required in 1.1.x onwards
source:
  plugin: migrate_api_key_url_plugin
  urls:
    - "https://example.com/api/data"
...

The above configuration will result in the source URL:

https://example.com/api/data

being transformed to

https://example.com/api/data?api-key=12345

Troubleshooting

My environment variable is not being detected!

This module checks for Pantheon secrets first via pantheon_get_secret(), then falls back to getenv() and $_ENV[VAR]. If you are running your migrations in an environment that does not support these methods, it will not be retrieved.

It was also built using DDEV and has not been tested on other local development stacks e.g. Lando.

Ensure your variable is set in a place discoverable to your environment. If developing locally, ensure you have restarted your local environment after changing environment variables.

Known issues

PHP Unit tests are present but have not been run and are therefore untested. Ironic, I know.

Depends on

Dependencies of the latest stable release

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
Apr 2026
Latest release
3 months ago
Releases (12 mo)
3 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Core Release date
1.1.0-alpha2 Pre-release 10–11 May 1, 2026
1.1.0-alpha1 Pre-release 10–11 Apr 17, 2026
1.0.0 Stable 11 Apr 16, 2026