# Get all contacts API order by addedAt

**URL:** <https://community.hubspot.com/t/get-all-contacts-api-order-by-addedat/12003>\
**Category:** APIs & Integrations\
**Created:** [September 23, 2016, 3:47am UTC](https://community.hubspot.com/t/get-all-contacts-api-order-by-addedat/12003 "2016-09-23T03:47:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 23, 2016, 3:47am UTC](https://community.hubspot.com/t/get-all-contacts-api-order-by-addedat/12003/1 "2016-09-23T03:47:59Z")

</div>

I’m trying to get all the contacts and I used Get all contacts API. Everything is fine except I cannot find an option to get the latest data first (order by addedAt). Please help!!!

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 23, 2016, 9:47am UTC](https://community.hubspot.com/t/get-all-contacts-api-order-by-addedat/12003/2 "2016-09-23T09:47:06Z")

</div>

[@thethlaing](https://community.hubspot.com/u/thethlaing) Not sure if the API itself comes with the ability to sort.

Otherwise, perhaps you can deal with it at code level. What I’d do is:

1. Decode JSON (to array)
2. Do sorting on the array based on key (addedAt); You can do custom sorting with PHP on datetime ([http://stackoverflow.com/questions/8121241/sort-array-based-on-the-datetime-in-php](http://stackoverflow.com/questions/8121241/sort-array-based-on-the-datetime-in-php))

Hope it helps!

---

<div class="post-metadata">

**Author:** ![Dadams](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dadams/32/21752_2.png) [@Dadams](https://community.hubspot.com/u/Dadams)\
**Post date:** [September 23, 2016, 4:22pm UTC](https://community.hubspot.com/t/get-all-contacts-api-order-by-addedat/12003/3 "2016-09-23T16:22:32Z")

</div>

Hi [@thethlaing](https://community.hubspot.com/u/thethlaing)

[@jerome.kwek](https://community.hubspot.com/u/jerome.kwek) is correct in that the Contacts API doesn’t support sorting, but we do have an endpoint that you can use to get contacts ordered by when they were created:  
`GET /contacts/v1/lists/all/contacts/recent`  
For example, this will get you the most recently created contacts from the demo portal:  
[https://api.hubapi.com/contacts/v1/lists/all/contacts/recent?hapikey=demo](https://api.hubapi.com/contacts/v1/lists/all/contacts/recent?hapikey=demo)

This endpoint follows the same rules as getting recently updated contacts, so you’ll need to use the 1vid-offset`and`time-offset` to page through the records.  
[Accounts Dashboard | HubSpot](http://developers.hubspot.com/docs/faq/how-do-i-use-vidoffset-and-timeoffset)
