Events v3 api sorting

Hi there

I am following the documentation here in order to retrieve custom events:

I am successfully retrieving the data set that I need via my request but the sort parameter is not working as expected. The documentation says:

sort
string[]
Sort direction based on the timestamp of the event instance, ASCENDING or DESCENDING.

my request looks like this:

https://api.hubapi.com/events/v3/events?eventType=pe145140026_landing_page_cta_click&sort=DESCENDING

but the response is:

{
 "status": "error",
 "message": "Only a single sort field 'occurredAt' is supported",
 "correlationId": "bdae94a4-10a5-4782-93e1-1e33ff9b312b",
 "category": "VALIDATION_ERROR"
}

Please could someone advise on the correct sort parameter for this request? I’m just trying to do a simple descending sort based on the event date.

Hey @KElliott81 and welcome, we are so glad you are here! :hugs:
Thanks for reaching out to the HubSpot Community!
Here is a documentation “Events API | Event Analytics” that might help you!
Now, let’s consult our Top Experts: Hi @RubenBurdin, @SteveHTM and @sylvain_tirreau do you have suggestions to help @KElliott81, please?
Thanks so much and have a lovely day!
Bérangère

Hi there

Thanks for the warm welcome. I did read the docs originally but there’s not much detail and no example of the sort param and the error message is not super clear. But after trying a number of different patterns and combinations for it, I found that this was effective for a descending sort:

https://api.hubapi.com/events/v3/events?eventType={{event type name}}&objectId={{object id}}&objectType=contact&sort=-occurredAt

I wonder if the documentation might benefit from an example for that one?

cheers

Kat

Hi @KElliott81 and thanks for the valuable feedback, I have passed it along internally.
Based on the documentation, the error message is correct. The Events v3 API only supports sorting by the occurredAt field, and you need to use a dash prefix for descending sort.

The correct format is: sort=-occurredAt (for descending) or sort=occurredAt (for ascending).

Your request should look like:
https://api.hubapi.com/events/v3/events?eventType=pe145140026_landing_page_cta_click&sort=-occurredAt

I hope this helps!
Bérangère
This post was created with the assistance of AI tools.