shopify - Can I submit a new subscriber to Campaign Monitor with an AJAX request?
I have a form on a Shopify site that has a name and email field as well as other fields. The form submits to a Shopify url. Before it submits, I want to send the name and email fields to a Campaign Monitor list.
- I have tried embedding a form generated by Campaign Monitor, and submitting it using jQuery.ajax(), but that encountered a CORS error indicating that Campaign Monitor will not accept the request.
- I cannot submit the embedded form directly in a way that will reload the page as I need to also submit the other form to Shopify.
I would create a middleware accepting CORS requests that will receive subscriber data via AJAX from your Shopify website, process/validate it and then submit it to Campaign Monitor.
You can also avoid CORS by creating a custom app (https://shopify.dev/concepts/apps#custom-apps) and adding a proxy extension (https://shopify.dev/tutorials/display-data-on-an-online-store-with-an-application-proxy-app-extension) pointing to a specific path on your server. Then you can send AJAX requests to a path within the Shopify e.g.
/tools/campaign-monitor/subscribe which will actually be proxied to your server script that will send subscriber to Campaign Monitor.
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.