TypeError: Argument 1 passed to Mailgun\Mailgun::create() must be of the type string, null given, called in /var/www/html/web/modules/contrib/mailgun/src/MailgunFactory.php on line 41 in Mailgun\Mailgun::create() (line 68 of /var/www/html/vendor/mailgun/mailgun-php/src/Mailgun.php).

D9 , Mailgun version 1.0
Nearly vanilla install. installed some other module before like commerce.

Comments

bennos created an issue. See original summary.

sokru’s picture

Status: Active » Postponed (maintainer needs more info)

Is your api_key correctly set? Your error log indicates its missing.

41       return Mailgun::create($this->mailgunConfig->get('api_key'));
bennos’s picture

Could not enter the API key, because the URL
admin/config/services/mailgun/settings

is the path where the error above appears.

sokru’s picture

Not being able to reproduce the issue with these steps.
1. git clone --branch 9.2.x https://git.drupalcode.org/project/drupal.git
2. composer install
3. composer require drupal/mailgun
4. php core/scripts/drupal quick-start standard
5. Enable mailgun module.
6. Go to admin/config/services/mailgun/settings, no error displayed nor on dblog.

You can bypass the problem by adding the API key to end of your settings.php file as $config['mailgun.settings']['api_key'] = 'key-123';

bennos’s picture

hmm, setting the API in settings.php works. no error. hmm

matroskeen’s picture

I cannot reproduce it either.

Besides,

  • mailgun.mailgun_client_factory is not executed on admin/config/services/mailgun/settings page;
  • Even if I execute the factory with empty api_key, it's still works because the default value is empty string '', which is still string as expected in Mailgun::create();

Another thing that bothers me is the fact that it has occurred in line 41 of MailgunFactory.php. It means that api_endpoint config property is empty as well.

Given that, I think that the config object (mailgun.settings) wasn't properly installed during the module installation.

@bennos, can you try to uninstall and install the module again?
Once it's done, you can inspect active mailgun.settings config object. It can be done via drush:
drush cget mailgun.settings

It should be like this:

api_endpoint: 'https://api.mailgun.net'
api_key: ''
working_domain: _sender
debug_mode: false
test_mode: false
tracking_opens: ''
tracking_clicks: ''
tracking_exception: 'user:password_reset'
format_filter: plain_text
use_queue: false
use_theme: false
tagging_mailkey: false
bennos’s picture

yeah, mailgun wasn't correct installed. there was an error during installation, raised from an other module in dev. Didn't know it. Looked in the logs and found the problem.
after uninstall mailgun and re-install it works correct.

matroskeen’s picture

Status: Postponed (maintainer needs more info) » Fixed

Great, mystery solved!

I'm marking this as "Fixed" and giving credit to @sokru for being helpful.
Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.