Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in lead-form.js : JSON data sent to server is malformed #53

Open
webhype opened this issue Jul 26, 2022 · 0 comments
Open

Bug in lead-form.js : JSON data sent to server is malformed #53

webhype opened this issue Jul 26, 2022 · 0 comments

Comments

@webhype
Copy link

webhype commented Jul 26, 2022

Email lead form submissions fail in the Corporate Starter Template because the JSON data sent to http://localhost:1337/api/lead-form-submissions isn't wrapped in { data: { <payload> }}, leading to 400 BAD REQUEST errors.

Buggy code:

await fetchAPI(
	"/lead-form-submissions",
	{},
	{
		method: "POST",
		body: JSON.stringify({
			email: values.email,
			location: data.location,
		}),
	}
)

Fixed code:

await fetchAPI(
	"/lead-form-submissions",
	{},
	{
		method: "POST",
		body: JSON.stringify({
			data: {
				email: values.email,
				location: data.location,
			}
		}),
	}
)

At first I couldn't replicate this behavior with Postman either. Turns out Strapi expects its POSTDATA in a very peculiar way (at least peculiar to me 😂).

Mad props to Arsiki at https://stackoverflow.com/questions/71187083/problem-with-post-action-on-strapi-via-postman for figuring out how to send POSTDATA to Strapi via Postman. (I am sure the proper way is documented somewhere also.)

After that, it became clear that the data field was missing in the JSON submitted back home via the lead form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant