#Inertia form submission to API endpoint

7 messages · Page 1 of 1 (latest)

visual ridge
#

Currently facing some issues trying to integrate a Laravel 9 application with Mailcoach v6. I'm using Inertia for the first time.

#

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.

Mailcoach

Mailcoach is an email marketing platform that talks to an external outgoing mail provider to send out email campaigns reliably while keeping costs low.

#

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.

visual ridge
#

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.

visual ridge
#

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.