APIs & Integrations

webcitron
Member

Tickets API search endpoint - sort by updatedAt

SOLVE

I'm trying to use endpoint `POST /crm/v3/objects/tickets/search` and receive list of tickets sorted by updatedAt descending. I've tried many combinations of "sorts" property but my tries seems to be ignored by API. Documentation does not contains so many informations about how "sorts" parameter should be used. 

Anyony could give me any clue about that ?

0 Upvotes
1 Accepted solution
ChehakWadhdwa
Solution
Member | Diamond Partner
Member | Diamond Partner

Tickets API search endpoint - sort by updatedAt

SOLVE

Hey @webcitron 

 

Could you please try using the below property

{

"propertyName": "hs_lastmodifieddate",

"direction": "DESCENDING"

}

 

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

View solution in original post

0 Upvotes
7 Replies 7
ChehakWadhdwa
Member | Diamond Partner
Member | Diamond Partner

Tickets API search endpoint - sort by updatedAt

SOLVE

Hey @webcitron

 

Can you try the below curl code

curl https://api.hubapi.com/crm/v3/objects/tickets/search?hapikey=YOUR_HUBSPOT_API_KEY \

  --request POST \

  --header "Content-Type: application/json" \

  --data '{

    "sorts": [

      {

        "propertyName": "lastmodifieddate",

        "direction": "DESCENDING"

      }

    ]

  }'



Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

0 Upvotes
webcitron
Member

Tickets API search endpoint - sort by updatedAt

SOLVE

 

@ChehakWadhdwa , thanks a lot of involvement. Please check out below listings. I've tried with 3 different payloads, all of them resulting with same (and not expected) ordering or the tickets. 

Script just executing api call and displaying "updatedAt" property for each returned ticket (its displays them in the order as they came from api):


```

$ curl -s --location --request POST 'https://api.hubapi.com/crm/v3/objects/tickets/search' --header 'Content-Type: application/json' --header 'Authorization: Bearer pat-na1-***' --data-raw '{
"limit": 5,
"sorts": [
{
"propertyName": "lastmodifieddate",
"direction": "DESCENDING"
}
]
}' | jq '.results[] | .updatedAt'
"2022-09-14T04:09:53.553Z"
"2022-09-14T04:09:53.562Z"
"2022-08-08T09:55:56.104Z"
"2022-09-14T04:09:53.553Z"
"2021-10-25T09:27:37.640Z"

 

$ curl -s --location --request POST 'https://api.hubapi.com/crm/v3/objects/tickets/search' --header 'Content-Type: application/json' --header 'Authorization: Bearer pat-na1-***' --data-raw '{
"limit": 5,
"sorts": [
{
"propertyName": "updatedAt",
"direction": "DESCENDING"
}
]
}' | jq '.results[] | .updatedAt'
"2022-09-14T04:09:53.553Z"
"2022-09-14T04:09:53.562Z"
"2022-08-08T09:55:56.104Z"
"2022-09-14T04:09:53.553Z"
"2021-10-25T09:27:37.640Z"

 

$ curl -s --location --request POST 'https://api.hubapi.com/crm/v3/objects/tickets/search' --header 'Content-Type: application/json' --header 'Authorization: Bearer pat-na1-***' --data-raw '{
"limit": 5,
"sorts": [
{
"propertyName": "updatedat",
"direction": "DESCENDING"
}
]
}' | jq '.results[] | .updatedAt'
"2022-09-14T04:09:53.553Z"
"2022-09-14T04:09:53.562Z"
"2022-08-08T09:55:56.104Z"
"2022-09-14T04:09:53.553Z"
"2021-10-25T09:27:37.640Z"

```

 

0 Upvotes
ChehakWadhdwa
Member | Diamond Partner
Member | Diamond Partner

Tickets API search endpoint - sort by updatedAt

SOLVE

Hey @webcitron

 

Looking at the results you got :

It's fetching the results based on recent results modifies.

Could you please elaborate exactly what you want with the API ? How you want the data to come ?

 

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

0 Upvotes
webcitron
Member

Tickets API search endpoint - sort by updatedAt

SOLVE

@ChehakWadhdwa , its not. look at updatedAt values which are returned by API (orginal ordering): 

```

"2022-09-14T04:09:53.553Z" (row1)
"2022-09-14T04:09:53.562Z" (row2)
"2022-08-08T09:55:56.104Z" (row3)
"2022-09-14T04:09:53.553Z" (row4)
"2021-10-25T09:27:37.640Z" (row5)

```

 

Note year and month especially. Expected return should be:

```

"2022-09-14T04:09:53.562Z" (row2)

"2022-09-14T04:09:53.553Z" (row1)

"2022-09-14T04:09:53.553Z" (row4)
"2022-08-08T09:55:56.104Z" (row3)
"2021-10-25T09:27:37.640Z" (row5)

```

 

Just reminding - im trying to fetch tickets ordered/sorted by updatedAt property value descending

 

 

ChehakWadhdwa
Solution
Member | Diamond Partner
Member | Diamond Partner

Tickets API search endpoint - sort by updatedAt

SOLVE

Hey @webcitron 

 

Could you please try using the below property

{

"propertyName": "hs_lastmodifieddate",

"direction": "DESCENDING"

}

 

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

0 Upvotes
FSoto8
Participant

Tickets API search endpoint - sort by updatedAt

SOLVE

doestn work.

 

the response is the same without order. 

0 Upvotes
webcitron
Member

Tickets API search endpoint - sort by updatedAt

SOLVE

Yes, thats works 🙂 Thanks a lot @ChehakWadhdwa 🍻

0 Upvotes