APIs & Integrations

kawyns1
Participant

Accessing property history in Json

SOLVE

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?

0 Upvotes
2 Accepted solutions
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Accessing property history in Json

SOLVE

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

Associate Certification Manager

View solution in original post

kawyns1
Solution
Participant

Accessing property history in Json

SOLVE

Hi @IsaacTakushi ,

 

I see what you mean. Thanks 🙂

 

Regards,

Kawyn

View solution in original post

4 Replies 4
IsaacTakushi
HubSpot Employee
HubSpot Employee

Accessing property history in Json

SOLVE

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

Associate Certification Manager
0 Upvotes
kawyns1
Participant

Accessing property history in Json

SOLVE

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

0 Upvotes
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Accessing property history in Json

SOLVE

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

Associate Certification Manager
kawyns1
Solution
Participant

Accessing property history in Json

SOLVE

Hi @IsaacTakushi ,

 

I see what you mean. Thanks 🙂

 

Regards,

Kawyn