APIs & Integrations

cchristians
Membro

Ajax Form Submission

Hello,

 

I am trying to submit support data from our applications custom support page via the Ajax method desribed here: https://developers.hubspot.com/docs/methods/forms/submit_form_v3

However whenever I submit I am getting an error saying that the required submiect field is not in the request.

Here is the error response

{"status":"error","message":"The request is not valid","errors":[{"message":"Error in 'fields.subject'. Required field 'subject' is missing","errorType":"REQUIRED_FIELD"}],"requestId":"a1374efe-f791-48d0-83aa-413d55def461"}

Here is what I am Posting:

 

 submitToHubSpot = () => {
        let url: string = "https://api.hsforms.com/submissions/v3/integration/submit/<valid portal Id here>/<valid form id here>";
        var param: any = {
            fields: [
                {
                    "name": "email",
                    "value": "cchristians@innovasi.com"
                },
                {
                    "name": "firstname",
                    "value": "Chad"
                },
                {
                    "name": "lastname",
                    "value": "Chad"
                },
                {
                    "name": "subject",
                    "value": "Testing Subject"
                }
            ]
        }
// http.post is a wrapper for AJAX http.post(url, param).then((result: any) => { console.log(result); }); }

Any help would be appreciated.

 

Thank you,

Chad

0 Avaliação positiva
4 Respostas 4
lscanlan
Alunos da HubSpot
Alunos da HubSpot

Ajax Form Submission

Hi @cchristians,

 

Are you sure that you're using the correct internal name for the subject field? I wonder if you have another property labeled subject, but whose internal name is something different. Because in that case, the API wouldn't recognize that all of this form's required fields are actually being submitted, which is what that error message indicates.

 

Otherwise I'm happy to take a look. Just let me know the form ID and portal ID and I'll take a look. You can respond here or through a DM if you'd prefer.

 

Leland Scanlan

HubSpot Developer Support
0 Avaliação positiva
cchristians
Membro

Ajax Form Submission

Hi Leland,

 

Thanks for your reply.  Here is the portalId and FormId you requested.

portalId: "xxxxxxxxxx",
formId: "xxxxxxxxxxxxx",

Posting to  this: URL: "https://api.hsforms.com/submissions/v3/integration/submit/xxxxx/xxxxxxxxx";

 

0 Avaliação positiva
lscanlan
Alunos da HubSpot
Alunos da HubSpot

Ajax Form Submission

Hi @cchristians,

 

It looks like maybe you're using TypeScript? I honestly am not very familiar with it, but I believe TypeScript compiles down to vanilla JS. Is it possible for you to paste your compiled request? I just wonder if your code is compiling into something that we're not expecting. Because I can make a request using the following:

 

var data = {
  fields: [
    {
      name: "email",
      value: "testing@testing12345.com"
    },
    {
      name: "firstname",
      value: "Test"
    },
    {
      name: "lastname",
      value: "Tester"
    },
    {
      name: "subject",
      value: "Testing Subject"
    }
  ]
}

fetch("https://api.hsforms.com/submissions/v3/integration/submit/437004/7abcf0b1-d099-420d-8342-36da8d134260", {
  method: "POST",
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(data)
}).then(res => {
  console.log("Request complete! response:", res);
});

That's for a form in my own account, which you can use if you'd like, or feel free to plug in your account ID and form ID. And you should see that it submits correctly. So I don't know if that helps, but I suspect that your code is compiling into something that doesn't look right. So if it's possible to see that, I think that will help here. Or if I'm wrong about any of the above, let me know and I'll dig in a little more.

 

Thanks.

 

Leland Scanlan

HubSpot Developer Support
cchristians
Membro

Ajax Form Submission

Hi Leland,

 

So there must be some issue with our form as when I use your URL with my code everything works just fine.  I am not the creator of our support form so Ill have to talk to him to see if we can figure it out.

 

Thanks,
Chad

0 Avaliação positiva