Select to view content in your preferred language sort_field doesn't work

10-24-2019 05:19 PM
New Contributor


I'm using the Python API for arcgis and I'm trying to get information on all our items on arcgis online. However, when I use the the sort_field option doesn't actually seem to sort the data no matter what I choose. I wrote a test to prove this, and sure enough when choosing to sort by numViews, an item with a lower view count comes before one with a higher view count in the array. Is is not supposed to work this way? Or did I do something wrong? My function looks like this:

def getData(urlusernamepassworditemTypesortTypenumResults😞
    #Send creds to ArcGIS 
    gis = GIS(url=url, username=username, password=password) 
    #Check if we want to search by item type or if we wanted all 
    if itemType.lower() == 'all':

    return""item_type=itemType, sort_field=sortType,
0 Kudos
2 Replies
Esri Contributor

Have you tried changing the sort_order in your query? It can be "asc" or "desc".

0 Kudos
New Contributor III

I agree with you, the using a sort_field (sort_order desc or asc) does not work as expected. On the API example page (scroll down to the "Searching for content in ArcGIS Online" section), it doesn’t even order it correctly.

I made a simple workaround that will order your result by the number of views as you can see in the screenshots below.

The standard search doesn't order the results:

After the workaround, the result is sorted by the number of views:

0 Kudos