Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

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, 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"
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.

Activity

Total releases
1
First release
Apr 2026
Latest release
16 hours ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
1.0.0 Stable Apr 16, 2026