<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python API endpoint to get historical deal stages of deals in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Python-API-endpoint-to-get-historical-deal-stages-of-deals/m-p/790280#M63754</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to get the historical deal stages of deals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;1) Deal name = X --&amp;gt; Moved from stage A to B&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal id = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal owner = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal created datetime = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; * Deal stage = A --&amp;gt; Date moved = a&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; * Deal stage = B --&amp;gt; Date moved = b&lt;/P&gt;&lt;P&gt;2) Deal name = Y --&amp;gt; Moved from stage A to B to C&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal id = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal owner = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal created datetime = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; * Deal stage = A --&amp;gt; Date moved = a&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; * Deal stage = B --&amp;gt; Date moved = b&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; * Deal stage = C --&amp;gt; Date moved = c&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using this Python API endpoint from all the posts that I have read in the community:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;* URL = '&lt;A href="https://api.hubapi.com/crm/v3/objects/deal?properties=hubspot_owner_id&amp;amp;properties=dealstage&amp;amp;properties=dealname&amp;amp;includePropertyVersions=true&amp;amp;limit=100" target="_blank"&gt;https://api.hubapi.com/crm/v3/objects/deal?properties=hubspot_owner_id&amp;amp;properties=dealstage&amp;amp;properties=dealname&amp;amp;includePropertyVersions=true&amp;amp;limit=100&lt;/A&gt;'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;* I am using "GET" request&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I cannot get the historical deal stages of deals. I can only get their latest deal stages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Look forward to your advice on how I can do so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 May 2023 06:29:01 GMT</pubDate>
    <dc:creator>JohnWongCK</dc:creator>
    <dc:date>2023-05-05T06:29:01Z</dc:date>
    <item>
      <title>Python API endpoint to get historical deal stages of deals</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Python-API-endpoint-to-get-historical-deal-stages-of-deals/m-p/790280#M63754</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to get the historical deal stages of deals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;1) Deal name = X --&amp;gt; Moved from stage A to B&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal id = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal owner = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal created datetime = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; * Deal stage = A --&amp;gt; Date moved = a&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; * Deal stage = B --&amp;gt; Date moved = b&lt;/P&gt;&lt;P&gt;2) Deal name = Y --&amp;gt; Moved from stage A to B to C&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal id = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal owner = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Deal created datetime = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; * Deal stage = A --&amp;gt; Date moved = a&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; * Deal stage = B --&amp;gt; Date moved = b&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; * Deal stage = C --&amp;gt; Date moved = c&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using this Python API endpoint from all the posts that I have read in the community:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;* URL = '&lt;A href="https://api.hubapi.com/crm/v3/objects/deal?properties=hubspot_owner_id&amp;amp;properties=dealstage&amp;amp;properties=dealname&amp;amp;includePropertyVersions=true&amp;amp;limit=100" target="_blank"&gt;https://api.hubapi.com/crm/v3/objects/deal?properties=hubspot_owner_id&amp;amp;properties=dealstage&amp;amp;properties=dealname&amp;amp;includePropertyVersions=true&amp;amp;limit=100&lt;/A&gt;'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;* I am using "GET" request&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I cannot get the historical deal stages of deals. I can only get their latest deal stages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Look forward to your advice on how I can do so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 06:29:01 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Python-API-endpoint-to-get-historical-deal-stages-of-deals/m-p/790280#M63754</guid>
      <dc:creator>JohnWongCK</dc:creator>
      <dc:date>2023-05-05T06:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: Python API endpoint to get historical deal stages of deals</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Python-API-endpoint-to-get-historical-deal-stages-of-deals/m-p/790306#M63755</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/484974"&gt;@JohnWongCK&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;The API endpoint you are currently using only provides the latest deal stage of a deal. In order to get the historical deal stages, you will need to use a different endpoint and query parameter.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;One option is to use the "timeline" endpoint to get a timeline of all the activities associated with the deal, including changes to the deal stage. Here's an example code snippet that demonstrates how to use this endpoint.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import requests

deal_id = '123456789' # Replace with the ID of the deal you want to retrieve the historical stages for
hapikey = 'your_api_key_here' # Replace with your HubSpot API key

url = f'https://api.hubapi.com/engagements/v1/engagements/associated/deal/{deal_id}/paged?include=metadata&amp;amp;hapikey={hapikey}'
response = requests.get(url)

timeline = response.json()
deal_stages = []

for item in timeline['results']:
    if item['metadata']['type'] == 'NOTE':
        note_text = item['metadata']['body']
        if 'Deal stage changed from' in note_text:
            stage_change = note_text.split('Deal stage changed from ')[1].split(' to ')
            from_stage = stage_change[0]
            to_stage = stage_change[1].rstrip('.')
            timestamp = item['engagement']['createdAt']
            deal_stages.append({'from_stage': from_stage, 'to_stage': to_stage, 'timestamp': timestamp})

print(deal_stages)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code will retrieve all the activities associated with the specified deal and filter out the ones that represent changes to the deal stage. It will then extract the previous and current stages, as well as the timestamp of the stage change, and store them in a list of dictionaries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 07:47:06 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Python-API-endpoint-to-get-historical-deal-stages-of-deals/m-p/790306#M63755</guid>
      <dc:creator>himanshurauthan</dc:creator>
      <dc:date>2023-05-05T07:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python API endpoint to get historical deal stages of deals</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Python-API-endpoint-to-get-historical-deal-stages-of-deals/m-p/790338#M63756</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/20405"&gt;@himanshurauthan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your advice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the process will be:&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; Get all deals&lt;/P&gt;&lt;P&gt;2)&amp;nbsp; For each deal, input deal id into codes you have provided&lt;/P&gt;&lt;P&gt;3)&amp;nbsp; Repeat (2) for all deals&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope I got it correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you once again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 09:19:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Python-API-endpoint-to-get-historical-deal-stages-of-deals/m-p/790338#M63756</guid>
      <dc:creator>JohnWongCK</dc:creator>
      <dc:date>2023-05-05T09:19:32Z</dc:date>
    </item>
  </channel>
</rss>

