APIs & Integrations

JohnWongCK
Participant

Get a trail of pipeline stages that a ticket has gone through

SOLVE

Hi,

 

I would like to get a trail of pipeline stages that a ticket has gone through using python code. Which API endpoint should I use?

 

For example, Ticket_ID = 12345 in "Call Centre Ticket Board"

> 1 Jan 2023: Pipeline stage created as "New"

> 3 Jan 2023: Pipeline stage updated to "Waiting on contacts"

> 10 Jan 2023: Pipeline stage updated to "Waiting on us"

> 20 Jan 2023: Pipeline stage updated to "Waiting on contacts"

> 21 Jan 2023: Pipeline stage updated to "Closed"

I would like to get all the pipeline stages above, not just the last one on 21 Jan 2023.

 

When I these API endpoints, I can only get the last pipeline stage.

0 Upvotes
2 Accepted solutions
LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

Get a trail of pipeline stages that a ticket has gone through

SOLVE

Hi @JohnWongCK,


You can add the query parameter "propertiesWithHistory=dealstage" in your GET call to the deals endpoint to include the history of the deal stages as well as timestamps : 

GET

{{Hubspot API}}/crm/v3/objects/deals/[INSERT_DEAL_ID_HERE]?propertiesWithHistory=dealstage

 

{
    "id": "11555711869",
    "properties": {
        "amount": "1000",
        "closedate": "2023-02-07T05:00:00Z",
        "createdate": "2023-01-02T17:14:36.790Z",
        "dealname": "Big Opp",
        "dealstage": "df327ce6-4ada-4429-b555-c1d24fc9ba88",
        "hs_lastmodifieddate": "2023-02-07T09:21:12.616Z",
        "hs_object_id": "11555711869",
        "pipeline": "fde9427f-a98a-4d49-a9f4-2f22bef770cc"
    },
    "propertiesWithHistory": {
        "dealstage": [
            {
                "value": "df327ce6-4ada-4429-b555-c1d24fc9ba88",
                "timestamp": "2023-02-07T09:21:09.171Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "e04ad861-4350-4cb6-beb1-a82e7a7d1198",
                "timestamp": "2023-02-07T09:21:07.330Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "4df7402e-19c8-4a93-953b-aa3f27572ee4",
                "timestamp": "2023-02-07T09:21:04.746Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "b8551ba8-a6f1-4abb-a154-4cf1b75a0045",
                "timestamp": "2023-02-07T09:21:02.233Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "3ceaf523-57eb-4f58-a9eb-8a001abce581",
                "timestamp": "2023-02-07T09:20:59.527Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "fc86fda4-d9d2-4ef2-ac8e-46f12fde7a84",
                "timestamp": "2023-02-07T09:20:56.907Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "9fd3c833-3c52-488a-ad60-38bcffef1b98",
                "timestamp": "2023-02-07T09:16:22.504Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "ce1614b3-0a18-4fc6-a714-f0ca9795a49e",
                "timestamp": "2023-01-02T17:14:36.790Z",
                "sourceType": "SALESFORCE"
            }
        ]
    },
    "createdAt": "2023-01-02T17:14:36.790Z",
    "updatedAt": "2023-02-07T09:21:12.616Z",
    "archived": false
}

 

As you can see in the example above, there are 9 values for the property "dealstage", you'll need to get the id of the different stages to get the stage name though.

I tested up to 9 property changes for the same property and as you can see they're all present in the API response so I'd say that's pretty safe but if you feel like you'll need more than that, you should test a higher max just to be sure.

 

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

 

 

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

View solution in original post

LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

Get a trail of pipeline stages that a ticket has gone through

SOLVE

Hi @JohnWongCK,

Well, you can batch request several tickets but you'll have to use a property with a unique value to do so (ticket ID or else), check out this endpoint from the tickets API page/crm/v3/objects/tickets/batch/read

 

You can use two calls then :
- a search the CRM call to get all tickets within a certain timeframe

- a batch read on all the ticket IDs returned

 

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

View solution in original post

6 Replies 6
LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

Get a trail of pipeline stages that a ticket has gone through

SOLVE

Hi @JohnWongCK,


You can add the query parameter "propertiesWithHistory=dealstage" in your GET call to the deals endpoint to include the history of the deal stages as well as timestamps : 

GET

{{Hubspot API}}/crm/v3/objects/deals/[INSERT_DEAL_ID_HERE]?propertiesWithHistory=dealstage

 

{
    "id": "11555711869",
    "properties": {
        "amount": "1000",
        "closedate": "2023-02-07T05:00:00Z",
        "createdate": "2023-01-02T17:14:36.790Z",
        "dealname": "Big Opp",
        "dealstage": "df327ce6-4ada-4429-b555-c1d24fc9ba88",
        "hs_lastmodifieddate": "2023-02-07T09:21:12.616Z",
        "hs_object_id": "11555711869",
        "pipeline": "fde9427f-a98a-4d49-a9f4-2f22bef770cc"
    },
    "propertiesWithHistory": {
        "dealstage": [
            {
                "value": "df327ce6-4ada-4429-b555-c1d24fc9ba88",
                "timestamp": "2023-02-07T09:21:09.171Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "e04ad861-4350-4cb6-beb1-a82e7a7d1198",
                "timestamp": "2023-02-07T09:21:07.330Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "4df7402e-19c8-4a93-953b-aa3f27572ee4",
                "timestamp": "2023-02-07T09:21:04.746Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "b8551ba8-a6f1-4abb-a154-4cf1b75a0045",
                "timestamp": "2023-02-07T09:21:02.233Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "3ceaf523-57eb-4f58-a9eb-8a001abce581",
                "timestamp": "2023-02-07T09:20:59.527Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "fc86fda4-d9d2-4ef2-ac8e-46f12fde7a84",
                "timestamp": "2023-02-07T09:20:56.907Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "9fd3c833-3c52-488a-ad60-38bcffef1b98",
                "timestamp": "2023-02-07T09:16:22.504Z",
                "sourceType": "CRM_UI",
                "sourceId": "userId:26386356",
                "updatedByUserId": 26386356
            },
            {
                "value": "ce1614b3-0a18-4fc6-a714-f0ca9795a49e",
                "timestamp": "2023-01-02T17:14:36.790Z",
                "sourceType": "SALESFORCE"
            }
        ]
    },
    "createdAt": "2023-01-02T17:14:36.790Z",
    "updatedAt": "2023-02-07T09:21:12.616Z",
    "archived": false
}

 

As you can see in the example above, there are 9 values for the property "dealstage", you'll need to get the id of the different stages to get the stage name though.

I tested up to 9 property changes for the same property and as you can see they're all present in the API response so I'd say that's pretty safe but if you feel like you'll need more than that, you should test a higher max just to be sure.

 

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

 

 

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

JohnWongCK
Participant

Get a trail of pipeline stages that a ticket has gone through

SOLVE

Hi Ludwig,

 

I have one more question.

If I want to get the pipeline stages of all tickets created between X and Y all at once, is there another API endpoint that I can use instead of using the above and changing the ticket ID again and again?

Thank you.

 

John

 

0 Upvotes
LMeert
Solution
Guide | Platinum Partner
Guide | Platinum Partner

Get a trail of pipeline stages that a ticket has gone through

SOLVE

Hi @JohnWongCK,

Well, you can batch request several tickets but you'll have to use a property with a unique value to do so (ticket ID or else), check out this endpoint from the tickets API page/crm/v3/objects/tickets/batch/read

 

You can use two calls then :
- a search the CRM call to get all tickets within a certain timeframe

- a batch read on all the ticket IDs returned

 

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

JohnWongCK
Participant

Get a trail of pipeline stages that a ticket has gone through

SOLVE

Hi Ludwig,

 

Just to close the loop.

Your solution worked.

Now I just have to figure out how to put everything together in python.

 

For completeness, here is the code that I used to test:

 

HEADER = {'content-type' : 'application/json',
'authorization' : 'Bearer ' + access_token}
PARAM = {'properties' : ['subject','hs_object_id','createdate','hs_lastmodifieddate','hs_pipeline','hs_pipeline_stage'],
'propertiesWithHistory': ['hs_pipeline_stage'],
'id_property': 'id',
'inputs': [{'id': ticket_id_1},{'id': ticket_id_2}]}
response = requests.post(url=URL, headers=HEADER, json=PARAM)
 
Thank you very much.
Have a great day and week ahead 🙂
 
John
 
0 Upvotes
JohnWongCK
Participant

Get a trail of pipeline stages that a ticket has gone through

SOLVE

Thank you once again, Ludwig. Let me try it tomorrow. I am confident that your solution will work. Have a great day :).

0 Upvotes
JohnWongCK
Participant

Get a trail of pipeline stages that a ticket has gone through

SOLVE

Hi Ludwig,

 

Thank you very much for your solution.

Since I am looking at tickets, I replaced "dealstage" with "hs_pipeline_stage".

It worked perfectly and I have verified the history with the movement of the same ticket.

Great to learn from you.

Have a good day!

 

John

 

0 Upvotes