APIs & Integrations

Phwilson17
Member

Service Ticket List Order

I'm trying to use the retrieve ticket get request with /crm/v3/objects/tickets but noticed that it only returns a small amount of tickets at once and from oldest to newest. It does provide a link to get the next batch but I'd rather not have to make call after call as I work my way to the most recent tickets. Is there a way to get the list to return from newest to oldest, or possibly just get all tickets in a single call?

2 Replies 2
GRajput
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Service Ticket List Order

Hi @Phwilson17 

Sure, there are a few ways to get all tickets in a single call or to get the list to return from newest to oldest.

**Get all tickets in a single call**

To get all tickets in a single call, you can use the following parameters in the request URL:

```
&offset=0
&limit=1000
```

The `offset` parameter specifies the starting point for the results, and the `limit` parameter specifies the maximum number of results to return. In this case, the request will return all tickets, starting with the most recent.

**Get the list to return from newest to oldest**

To get the list to return from newest to oldest, you can use the following parameter in the request URL:

```
&sort=created_at desc
```

The `sort` parameter specifies the order of the results, and the `desc` keyword specifies that the results should be sorted in descending order. In this case, the request will return the tickets in order from newest to oldest.

**Make multiple calls to get all tickets**

If you don't want to use the `offset` and `limit` parameters, you can make multiple calls to the API to get all tickets. In this case, you would use the `hasMore` property in the response to determine if there are more tickets to get. If `hasMore` is true, you would use the `nextOffset` property to get the offset for the next request.

Here is an example of how to make multiple calls to get all tickets:

```
// Get the first batch of tickets
const response = await hubspot.crm.tickets.get({
limit: 100,
});

// Check if there are more tickets
if (response.hasMore) {
// Get the next batch of tickets
const nextOffset = response.nextOffset;
await hubspot.crm.tickets.get({
limit: 100,
offset: nextOffset,
});
}
```

This code will get all tickets, in batches of 100 tickets at a time.

Hope this will helps you out. Please mark it as Solution Accepted to help other Community member.

Thanks!

 




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


Jaycee_Lewis
Community Manager
Community Manager

Service Ticket List Order

Hey, @Phwilson17 👋 Thanks for your question!

 

The short(ish) answer — To retrieve all tickets, you have to make multiple requests using the value returned for after to get all your Tickets. The HubSpot API uses this kind of pagination to ensure performance and stability, so there isn't a way to retrieve all tickets in a single call.

 

To sort the tickets by date from newest to oldest, you'll need to use the Search API endpoint for Tickets. The GET /crm/v3/objects/tickets endpoint you're using does not support sorting. Here's an example of how to sort using the Search API:

{
  "filterGroups": [],
  "sorts": [
    {
      "propertyName": "createdate",
      "direction": "DESCENDING"
    }
  ]
}

 

You'd POST this payload to /crm/v3/objects/tickets/search.

 

Have fun building! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes