#Inertia form submission to API endpoint
7 messages · Page 1 of 1 (latest)
I want to create a new Mailcoach newsletter subscriber by sending a post request to the corresponding endpoint as per the Mailcoach documentation from my main application. A sample blade form for doing from the official documentation is available here https://mailcoach.app/docs/self-hosted/v6/using-mailcoach/email-lists/adding-subscribers . I need to send my info using a Vue component.
Here is my code right now in my script tag.
<script setup>
import {useForm} from "@inertiajs/inertia-vue3";
const baseUrl = `${import.meta.env.VITE_APP_URL}/mailcoach`;
// alert(baseUrl);
let form = useForm({
email: null,
first_name: null,
last_name: null,
// Mailcoach Confirmation Page Redirects and Double Opt-in
redirect_after_subscribed: `${baseUrl}/subscribed`,
redirect_after_already_subscribed: `${baseUrl}/already-subscribed`,
redirect_after_subscription_pending: `${baseUrl}/redirect-after-pending`,
// Apply Mailcoach Tags
tags: 'tagA;tagB'
});
let submit = () => {
form.post(`${baseUrl}/subscribe/b1b69aea-7b9f-48ce-a1a1-f2988be1cxxx`, {
onSuccess: () => {
form.reset();
alert('success');
},
onError: () => {
alert('failed');
},
})
};
</script>
I receive a 404 when I submit the form. I checked my routes list to make sure I'm sending the post request to the right mailcoach endpoint. I also whitelisted the route in my cors config file.
I've tried the following:
I can access the mailcoach submission endpoint in my code using the browser and simply navigating to it using the URL bar.
The Mailcoach package seems to be installed correctly and route:list shows the mailcoach route I'm trying to hit. All other UI routes work fine.
The UUID for my subscribe list is correct and I already have a list within Mailcoach.
I got it working. Apparently there was a checkbox in the Mailcoach configuration to allow external forms to post to the endpoint. Now I get Email, First Name, and Last Name coming through, but the tags don't get attached for some reason.
The other problem I have is that after I submit the form, I still get a blank modal screen saying there is a 404 error even though the subscriber appears in the backend.