APIs & Integrations

UnearthNick
メンバー

Getting TypeError: Cannot read property 'requestContent' of undefined passing Form GuID via function

解決

I've been working on setting up a connection for the Hubspot Forms API that will handle all of our website forms by reading the pathname and then passing the appropriate GuID for the form to the API. That way I can have one function that handles form connections for all the different forms we have on our website.

 
I got it working, but I am running into an issue. Essentially, I tried to setup a function that reads the pathname and then assigns a form id based on the page path. Like this: 
/**
SET THIS UP TO MATCH GUID TO PATHNAME
 */
  function lookUpGuId() {
  if (window.location.pathname = '/mobile-form-builder/') {
  return '0138de5f-3570-4628-9966-a04755d0bd5b';
  }
}
 
then in hubspotPost() I call that form the form ID like this:
function hubspotPost() {
 var portalId = '6973045';
 var formGuid = lookUpGuId();
 var url = 'https://api.hsforms.com/submissions/v3/integration/submit/'+portalId+'/'+formGuid;
 var hsData = getHubSpotData();
 var data = JSON.stringify(hsData);
 var xhr = new XMLHttpRequest();
 
But, when I set it up that way I get this error in the console:
 
Screen Shot 2020-01-30 at 11.26.03 AM.png
It looks like it's passing the ID correctly, but I am getting "TypeError: Cannot read property 'requestContent' of undefined" in the debugger.
 
However, if I just put the GuID string into the formGuid variable, everything works as expected.
 
Any thoughts as to what is going on here? 
0 いいね!
1件の承認済みベストアンサー
UnearthNick
解決策
メンバー

Getting TypeError: Cannot read property 'requestContent' of undefined passing Form GuID via function

解決

Needed to update the lookUpGuId operator to '==' from '=' (to be a comparison instead of an assignment), if anyone else runs into the problem.

 
 

元の投稿で解決策を見る

1件の返信
UnearthNick
解決策
メンバー

Getting TypeError: Cannot read property 'requestContent' of undefined passing Form GuID via function

解決

Needed to update the lookUpGuId operator to '==' from '=' (to be a comparison instead of an assignment), if anyone else runs into the problem.