Accessing property history in Json

SOLVE
Regular Contributor

Hi, I am trying to the property history for all my deals using propertiesWithHistory for one of my properties. The json comes out as follows:

dealstage={sourceId=retracted@retracted.com, versions=[{sourceId=retracted@retracted.com, sourceVid=[], name=dealstage, source=CRM_UI, value=retracted3, timestamp=retracted3E12}, {sourceId=retracted@retracted.com, sourceVid=[], name=dealstage, source=CRM_UI, value=retracted2, timestamp=retracted2E12}, {sourceId=retracted@retracted.com,, sourceVid=[], name=dealstage, source=CRM_UI, value=retracted, timestamp=retractedE12}], source=CRM_UI, value=retracted3, timestamp=retracted3E12}};

So what is the format to dive deep into the json and pull all the property history?

@IsaacTakushiThink you can help here?

Reply
0 Upvotes
2 Accepted solutions

Accepted Solutions
Highlighted
HubSpot Moderator

Hey, @kawyns1.

 

To retrieve and store all historical values, you need to loop through the JSON objects in the dealstage.versions array.

 

Per this article, your JavaScript could look something like this:

 

var dealstage = // Set this variable equal to the entire dealstage object for a deal.

for(var i = 0; i < dealstage.versions.length; i++) {
     var version = versions[i];
// Do whatever you need with the properties in each version object. For example: console.log(version.value); }

 

Isaac Takushi

HubSpot Developer Support
Regular Contributor

Hi @IsaacTakushi ,

 

I see what you mean. Thanks Smiley Happy

 

Regards,

Kawyn

4 Replies 4
HubSpot Moderator

Hi, @kawyns1.

 

Where are you encountering issues?

From what you shared, it looks like that deal has one current dealstage value (retracted3) and two historical values (retracted2 and retracted). Are you claiming that there are more historical values which are not returned?

 

If so, can you direct message me a link to an example deal and the full, unredacted JSON of what you see included in the Get all deals endpoint's response for that particular deal?

Isaac Takushi

HubSpot Developer Support
Reply
0 Upvotes
Regular Contributor

Hi @IsaacTakushi ,

 

Sorry for the delay on this. No all the dealstages get returned. I'm just not sure how to retrieve / store all of them. For example, one deal could have 4 stages and another could have 2. So I am not sure how exactly to retrieve and store them from the json output.

 

Thanks,

Kawyn

Reply
0 Upvotes
Highlighted
HubSpot Moderator

Hey, @kawyns1.

 

To retrieve and store all historical values, you need to loop through the JSON objects in the dealstage.versions array.

 

Per this article, your JavaScript could look something like this:

 

var dealstage = // Set this variable equal to the entire dealstage object for a deal.

for(var i = 0; i < dealstage.versions.length; i++) {
     var version = versions[i];
// Do whatever you need with the properties in each version object. For example: console.log(version.value); }

 

Isaac Takushi

HubSpot Developer Support
Regular Contributor

Hi @IsaacTakushi ,

 

I see what you mean. Thanks Smiley Happy

 

Regards,

Kawyn