Problems with your Magento 2 integration?
Learn how to troubleshoot issues with your Magento 2 OAuth setup by following the steps below. If you still encounter problems after reading the steps, please contact Klaviyo's Community or Support Team.
Before you begin
Read the guide "How to integrate with Magento 2" before you start. This guide contains step-by-step instructions to set up your Magento integration. Have you already gone through these instructions? Then you can proceed with the tips in this article.
Klaviyo uses the OAuth protocol to create an access token and retrieve data from your Magento 2 store. If you have customized your Magento 2 installation, this can cause the Klaviyo OAuth procedure to fail. This article will guide you through a series of steps to determine where the error messages occur and how to resolve them.
Publicly accessible site
Klaviyo's OAuth procedure requires that your website is publicly accessible; otherwise, the necessary API calls to generate access codes will fail. You can make your site publicly accessible as follows:
- Ensure that access to your website is not secured with a password or IP restriction;
- Ensure that your store is accessible via HTTPS with a valid SSL certificate. You can test your certificate here.
Check your Magento 2 and Klaviyo extension versions
If you are using Magento 2.2.0 or earlier, you must enable OAuth manually. Make sure you install and activate the Klaviyo extension version 3.0.3 or higher.
Magento 2.4.2 specific issue
If you are using Magento 2.4.2, there is a known issue where OAuth activations fail. When activating the integration, you may see an error message like the one below. Even if you do not see this error message, the OAuth activation may still fail. You usually find this error in your "Magento logs."
To resolve this error, you need to:
- Upgrade to Magento 2.4.3. Check the documentation on Magento 2 to upgrade your current version, or
- Apply a patch as described in Klaviyo’s GitHub archive for Magento 2.
Ensure accessible OAuth endpoints
Additionally, you may have extra or missing rewrite rules that make the default Magento 2 OAuth endpoints inaccessible. You need to grant Klaviyo access to these endpoints to generate the necessary credentials for the authorization process. Ensure that the following URLs are accessible for your store:
https://[Store URL]/oauth/token/request
https://[Store URL]/oauth/token/access
- You confirm that the URLs are accessible by making a POST request as shown below:
curl --location --url 'https://[Store URL]/oauth/token/request' --request 'POST' -v
curl --location --url 'https://[Store URL]/oauth/token/access' --request 'POST' -v
- It is normal to see an error when making a request this way. Therefore, you can expect a response that looks like the following:
3. If you do not receive an OAuth-related response, check for any redirects, invalid rewrite rules, or internal server errors that may be preventing access to these URLs.
A 'store' subpath in your URL can also cause the above issue. Test for a problem with a 'store' subpath by accessing the endpoints at:
https://[Store URL]/[Store Path]/oauth/token/request
https://[Store URL]/[Store Path]/oauth/token/access
If these endpoints appear, include the following rewrite rules in your .htaccess file to resolve the issue:
RewriteEngine on
RewriteRule /oauth/token/request$ https://%{HTTP_HOST}/[Store Path]/oauth/token/request [L,R=301]
RewriteRule /oauth/token/access$ https://%{HTTP_HOST}/[Store Path]/oauth/token/access [L,R=301]
If you use a firewall or a similar service (like Cloudflare), Klaviyo's servers may be blocked from accessing relevant endpoints on your server. If you're using a firewall, add a rule to whitelist the Klaviyo user agent. All requests from Klaviyo have the user agent header Klaviyo/1.0.
Remove the integration and reintegrate
If you make changes after a previously failed integration attempt, it's a good idea to remove the original OAuth integration. The keys used may be invalid and might need to be regenerated. You can remove an integration as follows:
- Navigate to ‘Systems’ in Magento.
- Select ‘Integrations’.
- Find the Klaviyo integration record and delete it.
After you've removed the integration, follow the steps in the ‘how to integrate with Magento 2’ guide to create a new integration record and try again.
Want to know more?
- Read ‘reviewing your Magento 2 data’
- Read the ‘guide to supporting multiple Magento stores (for Magento 2.x)’
Do you have any questions after reading this article about WhatsApp automations? Feel free to contact us for more advice.
Find the original article here.