APIs & Integrations

rinova
Member

Passing the hubspot tracking cookie with form api

SOLVE

Hello, I am using the following request to post form data to my hubspotforms:

https://developers.hubspot.com/docs/methods/forms/submit_form

In the documentation it says i need to add my hubspotutk to the hutk field under context like this:
"context": {

"hutk": ":hutk", 

"pageUri": "www.example.com/page",

"pageName": "Example page"

},

 

 Hower when i try to post my data i am getting the following message:

message":"Error in 'context'. Unexpected attribute 'htuk' of 'context' object","errorType":"INVALID_METADATA"}]

Am I missing something here?  

Thank you.

0 Upvotes
1 Accepted solution
rinova
Solution
Member

Passing the hubspot tracking cookie with form api

SOLVE

Nevermind... Looks like I read it wrong. there was an error in my field just like the error said "htuk" is indeed not a valid attribute it needs to be "hutk".

It works now. Thank you for your time to respond Matthew.

View solution in original post

4 Replies 4
rinova
Solution
Member

Passing the hubspot tracking cookie with form api

SOLVE

Nevermind... Looks like I read it wrong. there was an error in my field just like the error said "htuk" is indeed not a valid attribute it needs to be "hutk".

It works now. Thank you for your time to respond Matthew.

Willson
HubSpot Employee
HubSpot Employee

Passing the hubspot tracking cookie with form api

SOLVE

Hi @rinova 

 

Can you confirm, that you're actually capturing and pushing the hutk value rather than just adding this code? This code is not complete but is rather used as a template of how data should be submitted.

 

In this case, we show how the request payload should be structured when using this endpoint. You will still need to design the functionality to handle the hutk cookie and pass it in this payload. 

 

To assist, you'll need something that functions similar to this code:

function getCookie(cname) {
  var name = cname + "=";
  var decodedCookie = decodeURIComponent(document.cookie);
  var ca = decodedCookie.split(';');
  for(var i = 0; i <ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}

This is a simple script to retrieve a cookie value (cname). You'll need to create something similar to handle the hutk value, once returned, you'll need to ensure it is passed in the request payload. 

 

I hope this helps!

 

 

Product Manager @ HubSpot
0 Upvotes
rinova
Member

Passing the hubspot tracking cookie with form api

SOLVE

Hello! 

 

Thank you for your reply.

 

sorry for the confusion,  I knew it was a snippet/example but I retrieved the cookie value just like the way you suggested and passed it in  like this:

"context": {

       "hutk": "retrievedcookievalue", 

       "pageUri":  document.URL

       "pageName":  document.title

},

I have a hunch that i need to put something else instead of "hutk"? 

edit: contacted chat and told me i need to use hs_context. Is this the right approach?

0 Upvotes
ABayer
Member

Passing the hubspot tracking cookie with form api

SOLVE

do does the field need to be hs_context ? Im continually getting 400 when i try to pass "hutk" within "context" object.

 

0 Upvotes