Form Post 405 error

I’ve checked the other posts on this issue and can’t find where I am going wrong in there.

My form submissions are returning 405 errors. I’m not sure why.

The confusing thing is that while I (and others) are getting the 405 error. It seems others aren’t as when I check the form submission on Hubspot I’m still getting submissions coming through,

Here’s how I’m preparing the data:

const postData = {
 context: {
 hutk: Cookies.get('hubspotutk'),
 pageName: pageTitle,
 pageUri: window.location.href,
 },
 legalConsentOptions: {
 consent: {
 consentToProcess: true,
 text:
 'I agree to allow Company to store and process my personal data.',
 communications: [
 {
 value: true,
 subscriptionTypeId: 999,
 text: 'I agree to receive communications from Company.',
 },
 ],
 },
 },
 fields: [],
 };

 postData.fields = fieldData.map(field => {
 return { name: field.name, value: field.value };
 });

 const headers = {
 Accept: 'application/json',
 'Content-Type': 'application/json',
 'Content-Length': (Object.keys(postData).length).toString(),
 };

 fetch(hubspotAPIEndpoint, {
 method: 'POST',
 headers,
 body: JSON.stringify(postData),
 mode: 'cors',
 });

And here’s the data:

{
 body:  "{"context":{"pageName":"Mission Beyond","pageUri":"http://localhost:8000/"},"legalConsentOptions":{"consent":{"consentToProcess":true,"text":"I agree to allow Company to store and process my personal data.","communications":[{"value":true,"subscriptionTypeId":999,"text":"I agree to receive communications from Company."}]}},"fields":[{"name":"firstname","value":"test"},{"name":"lastname","value":"test"},{"name":"email","value":"test@example.com"}]}",
 headers: {
 Accept: "application/json",
 Content-Length: "3",
 Content-Type: "application/json", },
 method: "POST",
 mode: "cors",}

Let me know if I can clarify anything further, thanks for any help.

Is there any chance this is rejecting example emails like test@example.com? Using my own email produces no error but using test@example.com returns the 405.

Hey @RB_Simon,

I believe this is likely because the email: test@example.com is invalid. The form response body will return a list of errors which you can learn more here: Submit data for a form | Forms API.

If you’d like to skip validation, you’d need to set

"skipValidation": true

on the form request body.

Thanks Wendy