solspace / craft-freeform

Freeform for Craft: The most reliable form builder that's ready for wherever your project takes you.
https://docs.solspace.com/craft/freeform/v5/
Other
47 stars 61 forks source link

Mailchimp integration 400 "Invalid Resource" errors #1167

Closed Ticolyle closed 6 months ago

Ticolyle commented 7 months ago

Describe the bug or issue you're experiencing

I have an 'authorized' marketing integration setup with our client's Mailchimp account. For some submissions we get a successful form submission in the database, however the frontend freeform AJAX submission gets a 500 bad request response and I see a mailchimp response of 400 'Invalid Resource' errors in the Freeform error log. The 400 error from mailchimp doesn't seem to have any useful details and it's truncated.

The response in the storage/logs/freeform.php as well as the craft CMS web log are also truncated. Not seeing any php or console errors.

I also tried this setup using page redirection for success and no redirect happened on submit, but also no errors were presented on the frontend.

Steps to reproduce

  1. Upgrade to Freeform 5 on Craft 4
  2. Connect a Mailchimp integration
  3. Submit forms via ajax. Possibly with a duplicated email address that is already in mailchimp?

Expected behavior

Since the form submits successfully Craft shouldn't return a 500 response despite a Mailchimp response error. I would expect a quiet failure to sign the user up to the marketing list, and hopefully a more useful version of the Mailchimp error. I recall in Freeform v4 we would sometime see Mailchimp errors such as "User already exits" or "looks like spam".

Craft & Plugin Info (please complete the following information):

Additional context

Freeform Error log example from CMS view (list url redacted): Mailchimp Client error: PUT https://us9.api.mailchimp.com/3.0/lists/XXXXXXXXX/members/XXXXXXXXX resulted in a 400 Bad Request response: {"type":"https://mailchimp.com/developer/marketing/docs/errors/","title":"Invalid Resource","status":400,"detail":"The r (truncated...) {"exception":"Client error: PUT https://us9.api.mailchimp.com/3.0/lists/XXXXXXXXX/members/XXXXXXXXX resulted in a 400 Bad Request response:\n{\"type\":\"https://mailchimp.com/developer/marketing/docs/errors/\",\"title\":\"Invalid Resource\",\"status\":400,\"detail\":\"The r (truncated...)\n"} []

freeform.php error: [2024-03-26T13:32:15.299837-05:00] Integration.ERROR: Mailchimp Client error: PUT https://us9.api.mailchimp.com/3.0/lists/XXXXXXXXX/members/XXXXXXXXX resulted in a 400 Bad Request response: {"type":"https://mailchimp.com/developer/marketing/docs/errors/","title":"Invalid Resource","status":400,"detail":"The r (truncated...) {"exception":"Client error: PUT https://us9.api.mailchimp.com/3.0/lists/XXXXXXXXX/members/XXXXXXXXX resulted in a 400 Bad Request response:\n{\"type\":\"https://mailchimp.com/developer/marketing/docs/errors/\",\"title\":\"Invalid Resource\",\"status\":400,\"detail\":\"The r (truncated...)\n"} []

storage/logs/web-DATE.log error: 2024-03-26 13:50:12 [web.ERROR] [GuzzleHttp\Exception\ClientException] Client error: PUT https://us9.api.mailchimp.com/3.0/lists/XXXXXXXXX/members/XXXXXXXXX resulted in a 400 Bad Request response: {"type":"https://mailchimp.com/developer/marketing/docs/errors/","title":"Invalid Resource","status":400,"detail":"The r (truncated...) {"trace":["#0 /XXXXXXXXX/vendor/guzzlehttp/guzzle/src/Middleware.php(72): GuzzleHttp\Exception\RequestException::create()","#1 /XXXXXXXXX/vendor/guzzlehttp/promises/src/Promise.php(209): GuzzleHttp\Middleware::GuzzleHttp\{closure}()","#2 /XXXXXXXXX/vendor/guzzlehttp/promises/src/Promise.php(158): GuzzleHttp\Promise\Promise::callHandler()","#3 /XXXXXXXXX/vendor/guzzlehttp/promises/src/TaskQueue.php(52): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()","#4 /XXXXXXXXX/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Promise\TaskQueue->run()","#5 /XXXXXXXXX/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise->invokeWaitFn()","#6 /XXXXXXXXX/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()","#7 /XXXXXXXXX/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()","#8 /XXXXXXXXX/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise->waitIfPending()","#9 /XXXXXXXXX/vendor/guzzlehttp/guzzle/src/Client.php(189): GuzzleHttp\Promise\Promise->wait()","#10 /XXXXXXXXX/vendor/guzzlehttp/guzzle/src/ClientTrait.php(78): GuzzleHttp\Client->request()","#11 /XXXXXXXXX/vendor/solspace/craft-freeform/packages/plugin/src/Integrations/EmailMarketing/Mailchimp/Versions/MailchimpV3.php(234): GuzzleHttp\Client->put()","#12 /XXXXXXXXXvendor/solspace/craft-freeform/packages/plugin/src/Integrations/EmailMarketing/EmailMarketingBundle.php(76): Solspace\Freeform\Integrations\EmailMarketing\Mailchimp\Versions\MailchimpV3->push()","#13 [internal function]: Solspace\Freeform\Integrations\EmailMarketing\EmailMarketingBundle->handleIntegrations()","#14 /XXXXXXXXX/vendor/yiisoft/yii2/base/Event.php(312): call_user_func()","#15 /XXXXXXXXX/vendor/solspace/craft-freeform/packages/plugin/src/Services/SubmissionsService.php(200): yii\base\Event::trigger()","#16 /XXXXXXXXXvendor/solspace/craft-freeform/packages/plugin/src/Services/SubmissionsService.php(170): Solspace\Freeform\Services\SubmissionsService->postProcessSubmission()","#17 /XXXXXXXXX/vendor/solspace/craft-freeform/packages/plugin/src/controllers/SubmitController.php(45): Solspace\Freeform\Services\SubmissionsService->handleSubmission()","#18 [internal function]: Solspace\Freeform\controllers\SubmitController->actionIndex()","#19 /XXXXXXXXX/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()","#20 /XXXXXXXXX/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()","#21 /XXXXXXXXX/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()","#22 /XXXXXXXXX/vendor/craftcms/cms/src/web/Application.php(341): yii\base\Module->runAction()","#23 /XXXXXXXXX/vendor/craftcms/cms/src/web/Application.php(642): craft\web\Application->runAction()","#24 /XXXXXXXXX/vendor/craftcms/cms/src/web/Application.php(303): craft\web\Application->_processActionRequest()","#25 /XXXXXXXXX/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()","#26 /XXXXXXXXXpublic_html/index.php(12): yii\base\Application->run()","#27 {main}"],"memory":6096400,"exception":"[object] (GuzzleHttp\Exception\ClientException(code: 400): Client error: PUT https://us9.api.mailchimp.com/3.0/lists/2cecac8efe/members/446de8c92cc38267248abd38ddf8e9e7 resulted in a 400 Bad Request response:\n{\"type\":\"https://mailchimp.com/developer/marketing/docs/errors/\",\"title\":\"Invalid Resource\",\"status\":400,\"detail\":\"The r (truncated...)\n at /XXXXXXXXX/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113)"}

kjmartens commented 7 months ago

Hi @Ticolyle,

I tried duplicating this issue in my testing and I can get it to fail. Just to be clear, this always fails for you, even if you enter a unique email address?

Also, can you include a screenshot of what your Mailchimp settings look like inside the Integrations tab of the form builder? 🙂

Ticolyle commented 7 months ago

Hey @kjmartens, sure thing.

So the logged error only seems to occur when mailchimp rejects the address outright but Freeform accepts it as non-spam.

For instance using spam@pharma.org as the email address in my form I was able to replicate the error. In this example Freeform did not mark the address as spam, so it was successfully submitted to our database. However, we use a page redirect on success on this site, and the redirect did not happen, and the same error was logged again in the Freeform error log as I posted previously. We are using Honeypot and JS Test on the forms.

Duplicate submissions with identical email address does not produce an error.

We also use 'simulate success' for spam behaviour, don't know if thats relevant.

It would be nice if the error message from Mailchimp wasn't truncated. Is there a setting or config I could maybe change to increase the log message length if that's what is causing the issue? I realize thats probably not a Freeform controlled setting.

Here's a redacted screenshot of the settings page. Auth seemed to work fine. craft-mailchimp-freeform-config

Thanks! Lyle

kjmartens commented 7 months ago

Thanks for the additional information and sorry for the delay...

Interestingly, I am only able to encounter this issue if my email address contains the word spam in it, e.g. spam@test.net, test@spam.net, etc. I tried various other words like viagra, bitcoin, etc, and none of them trigger it. But spam triggers it 100% of the time for me.

Is this the case for you too? Do the submissions that are failing for you all contain spam in them, and submitted by yourself or another team member? 🙂

I also don't see any error presented to the user submitting the form.

I agree that it'd be better if the logged error would not be truncated so that it could show a more meaningful error. We'll definitely look into that part, but please let me know about my other questions. 🙂