APIs & Integrations

Carol_Saldanha
Member

Forms API error

I have created a Hubspot form with over more than 10 properties and I'm using that to push contact information via API. I don't have any properties set as required, but if any of the data is "null", it doesn't push the data. I have attched a screenshot of my error.
29%20pm

0 Upvotes
6 Replies 6
cbarley
HubSpot Alumni
HubSpot Alumni

Forms API error

Hi @Carol_Saldanha, which endpoint are you using? The V2 or V3 endpoint? Could you also share the request URL and payload you're sending to HubSpot? Thanks!

0 Upvotes
Carol_Saldanha
Member

Forms API error

Hi @Connor_Barley. Thanks for your reply.
I'm using v3.
Here is an example of the data. One of the fields is null. If I remove that field, it does work. But, I want it to work even if there is any null data that is being passed.

data = {
"fields": [
{
"name": "email",
"value": email
},
{
"name": "firstname",
"value": firstname
},
{
"name": "lastname",
"value": lastname
},
{
"name": "zip",
"value": postcode
},
{
"name":"phone",
"value": phone
},
{
"name":"mobilephone",
"value": mobile
},
{
"name": "nmi",
"value": nmi
},
{
"name": "client_type",
"value": clienttype
},
{
"name": "date_of_birth",
"value": dob
},
{
"name": "solar",
"value": solar
},
{
"name": "transfer_type",
"value": transfertype
},
{
"name": "state",
"value": state
},
{
"name": "suburb",
"value": suburb
},
{
"name": "life_support",
"value": lifesupport
},
{
"name": "address",
"value": staddress
}
]
}

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Forms API error

Awesome thank you! I actually was able to reproduce this issue when using null as a value with the V3 endpoint. We don't allow fields that are null or undefined to be sent through the V3 API. They either need to be present or they can be set to an empty string. When I set a field to an empty string in my example, it works (does not clear the value either). You should make sure that all fields you're sending have values or have a default.

0 Upvotes
Carol_Saldanha
Member

Forms API error

@Connor_Barley Also, the problem here is we do not know which value would exactly be null as it comes to us in a Google sheet form, and there are too many values to be set to an empty string.

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Forms API error

Hi @Carol_Saldanha, the formatting for your request are a bit off. Per the V2 endpoint docs, you'll need to URL encode the fields and make a request like this: https://forms.hubspot.com/uploads/form/v2/3430672/983fd305-bdd3-40be-bc25-59be5f5650a8?firstname=tes....

Here's an example I created that takes the inputs from the fields and puts them into a request: https://repl.it/@cbarley10/BlondMortifiedMath

To solve your issue of not knowing which value will be null, you could always use the || operator in javascript to set the value of that field to either the value entered, or "". I did something similar in a test file for the V3 endpoint which works!

0 Upvotes
Carol_Saldanha
Member

Forms API error

@Connor_Barley : I figured this out and tried using the v2 endpoint instead that allows null field values. The script did run without any errors, but data did not get posted to the Hubspot form. I might be going wrong here with the "v2 endpoint" format. Please could you check the same.

var url = "https://forms.hubspot.com/uploads/form/v2/4987314/f40c328f-e01c-459b-8dd1-d854131dc49c";

data = {

"fields": [

{

"name": "email",

"value": email

},

{

"name": "firstname",

"value": firstname

},

{

"name": "lastname",

"value": lastname

},

{

"name": "zip",

"value": postcode

},

{

"name":"phone",

"value": phone

},

{

"name":"mobilephone",

"value": mobile

},

{

"name": "nmi",

"value": nmi

},

{

"name": "client_type",

"value": clienttype

},

{

"name": "date_of_birth",

"value": dob

},

{

"name": "solar",

"value": solar

},

{

"name": "transfer_type",

"value": transfertype

},

{

"name": "state",

"value": state

},

{

"name": "suburb",

"value": suburb

},

{

"name": "life_support",

"value": lifesupport

},

{

"name": "licence_number",

"value": DL

},

{

"name": "message",

"value": offeringcode

},

{

"name": "how_did_you_hear_about_us_",

"value": how_did_you_hear_about_us

},

{

"name": "address",

"value": staddress

}

]

}

0 Upvotes