# Hubspot Additional Properties not being set on API

**URL:** <https://community.hubspot.com/t/hubspot-additional-properties-not-being-set-on-api/42641>\
**Category:** APIs & Integrations\
**Tags:** events\
**Created:** [August 20, 2021, 2:42pm UTC](https://community.hubspot.com/t/hubspot-additional-properties-not-being-set-on-api/42641 "2021-08-20T14:42:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![YizSeg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/yizseg/32/63860_2.png) [@YizSeg](https://community.hubspot.com/u/YizSeg)\
**Post date:** [August 20, 2021, 2:42pm UTC](https://community.hubspot.com/t/hubspot-additional-properties-not-being-set-on-api/42641/1 "2021-08-20T14:42:15Z")

</div>

I have the following code in my API call

```lia-code-sample
let postPropertiesData = {};

if (data.additionalProperties) {
 for (let key in data.additionalProperties) {
 postPropertiesData[data.additionalProperties[key].key] = data.additionalProperties[key].value;
 }
}

const postProperties = JSON.stringify(postPropertiesData);

const setProperties = JSON.stringify({
 utk: data.userToken,
 eventName: data.eventName,
 properties: postProperties,
 ocurredAt: getTimestamp(),
});

```

Now this is the template code I use and then there is a form with an input fields where I can set the property name and the value (it’s set dynamically). It looks like this

 ![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/2/c/2c989304afee6a6e710f606d420acfa1d6f24ab4.png)

However, while it prepares the data is looks like this

 ![YizSeg_2-1629470108663.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/9/e/9edcdc2fa39c92fc70013260ba7a54d76a495034.png)

don’t mind the actual value itself, that’s dynamically populated and I have checked the variables and they are working.

My question is two-fold:

1. the structure seems off according to the presentation made in [Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/api/analytics/events)
  1. How do I fix that structure above

2. also the request doesn’t actually put any data as the request body has “properties”:“{}”,
  1. how do I make sure that it gets set and populated properly?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [August 23, 2021, 1:38pm UTC](https://community.hubspot.com/t/hubspot-additional-properties-not-being-set-on-api/42641/2 "2021-08-23T13:38:02Z")

</div>

@YizSeg , are you still working on this?

How does the json body look when you have run this?

@miljkovicmisa , wanna try your hand in this 😀

---

<div class="post-metadata">

**Author:** ![YizSeg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/yizseg/32/63860_2.png) [@YizSeg](https://community.hubspot.com/u/YizSeg)\
**Post date:** [August 23, 2021, 4:16pm UTC](https://community.hubspot.com/t/hubspot-additional-properties-not-being-set-on-api/42641/3 "2021-08-23T16:16:35Z")

</div>

G’day @dennisedson @miljkovicmisa

In the hubspot log I get no request header or body even though the call goes through and it works otherwise.

In the debug it put it as

`properties: {}`

For same reason I’m not getting the properties: {‘hs\_asset\_type’:‘PDF’} and the rest as planned. The table is functioning as you can see that Google Tag Manager is actually reading the variables properly in the table and I"ve checked in preview mode and the variables are functioning correctly.

Something is happening between that, where is isn’t being converted into an object properly containing all the property names and values. And isn’t being set as part of the request body.

---

<div class="post-metadata">

**Author:** ![miljkovicmisa](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/miljkovicmisa/32/86357_2.png) [@miljkovicmisa](https://community.hubspot.com/u/miljkovicmisa)\
**Post date:** [August 24, 2021, 8:33pm UTC](https://community.hubspot.com/t/hubspot-additional-properties-not-being-set-on-api/42641/4 "2021-08-24T20:33:05Z")

</div>

Hello @YizSeg , for your first question in order to create the right structure you will need to pass another object inside the object of the propertiesData so it needs to look like this:

```lia-code-sample
let postPropertiesData = {
 "properties" : []
};

```

So with the above you will be able to push all the constructed properties correctly inside the properties object as per the documentation, this will look like the following:

```lia-code-sample
// first we do an iteration of the data and store it temporarily in a variable
var tempProperties = {};
if (data.additionalProperties) {
 for (let key in data.additionalProperties) {
 tempProperties[data.additionalProperties[key].key] = data.additionalProperties[key].value;
 }
}

// then we insert all tempProperties in the correct object inside postPropertiesData
postPropertiesData.properties.push(tempProperties);

```

You can also add all the other key-value pairs in the same manner:

```lia-code-sample
postPropertiesData["utk"] = data.userToken;
postPropertiesData["eventName"] = data.eventName;
postPropertiesData["ocurredAt"] = getTimestamp();

```

For the second part I would dump the “data” and the “postPropertiesData” to see what data gets stored so you can easily debug this.

---

<div class="post-metadata">

**Author:** ![YizSeg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/yizseg/32/63860_2.png) [@YizSeg](https://community.hubspot.com/u/YizSeg)\
**Post date:** [August 25, 2021, 5:27pm UTC](https://community.hubspot.com/t/hubspot-additional-properties-not-being-set-on-api/42641/5 "2021-08-25T17:27:50Z")

</div>

@miljkovicmisa thanks for that I tried that, but it came back with a TypeError saying that TypeError: Object has no ‘push’ property. Either way, I found the answer.

I imported the API called makeTableMap

`const makeTableMap = require('makeTableMap');`

and then instead of using a if and for statements,

I used the API to attach it straight to the object

```lia-code-sample
const setBody = JSON.stringify({
 'portalId':data.portalID,
 'utk': data.userToken,
 'eventName': data.eventName,
 'properties': (data.additionalProperties) ? makeTableMap(data.additionalProperties,'property','value'):{},
 'ocurredAt': getTimestamp(),
});

```

I tested it, got a successful response and it sent the properties as part of the request body.

---

<div class="post-metadata">

**Author:** ![miljkovicmisa](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/miljkovicmisa/32/86357_2.png) [@miljkovicmisa](https://community.hubspot.com/u/miljkovicmisa)\
**Post date:** [August 26, 2021, 3:38pm UTC](https://community.hubspot.com/t/hubspot-additional-properties-not-being-set-on-api/42641/6 "2021-08-26T15:38:59Z")

</div>

Great news @YizSeg , this is a nice workaround, seems like I had a typo in my code and that’s why you got the “push” error, the “properties” key needs to be an object not a key-value pair so the preformatting of the variable should look like this (I also updated my answer):

```lia-code-sample
let postPropertiesData = {
 "properties" : []
};

```

Cheers!
