# Getting identification data for multiple user\_ids through iNaturalist API

**URL:** <https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105>\
**Category:** General\
**Tags:** api\
**Created:** [June 26, 2022, 10:50am UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105 "2022-06-26T10:50:27Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![babellleee](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@babellleee](https://forum.inaturalist.org/u/babellleee)\
**Post date:** [June 26, 2022, 10:50am UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/1 "2022-06-26T10:50:27Z")

</div>

I’m trying to get identifications of multiple user\_ids through the iNaturalist API ([https://api.inaturalist.org/v1/docs/#!/Identifications/get\_identifications\_categories](https://api.inaturalist.org/v1/docs/#!/Identifications/get_identifications_categories)). When I enter multiple user\_ids into the ‘GET/identifications/categories’ function, I keep getting 0 results, even though when I try for one of the user\_ids, there clearly are results. I have tried entering these multiple user\_ids both as a string separated by commas, and as multiple values in new lines as instructed in the text box for entering the user\_ids. However, I get the same null results each time. Grateful for any advice on this.

---

<div class="post-metadata">

**Author:** ![pisum](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@pisum](https://forum.inaturalist.org/u/pisum)\
**Post date:** [June 26, 2022, 3:04pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/2 "2022-06-26T15:04:48Z")

</div>

what is the Request URL generated on that page when you click the Try It button?

i don’t see any issues:

- [https://api.inaturalist.org/v1/identifications/categories?user\_id=pisum](https://api.inaturalist.org/v1/identifications/categories?user_id=pisum)
- [https://api.inaturalist.org/v1/identifications/categories?user\_id=tiwane](https://api.inaturalist.org/v1/identifications/categories?user_id=tiwane)
- [https://api.inaturalist.org/v1/identifications/categories?user\_id=pisum,tiwane](https://api.inaturalist.org/v1/identifications/categories?user_id=pisum,tiwane)

…

not sure what you’re trying to do, but this page may or may not be useful: [https://forum.inaturalist.org/t/many-ids-have-id-category-null/19061/4](https://forum.inaturalist.org/t/many-ids-have-id-category-null/19061/4)

---

<div class="post-metadata">

**Author:** ![babellleee](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@babellleee](https://forum.inaturalist.org/u/babellleee)\
**Post date:** [June 26, 2022, 3:16pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/3 "2022-06-26T15:16:20Z")

</div>

The request URL generated is: [https://api.inaturalist.org/v1/identifications/categories?user\_id=1756341%2C1617933&current=true&order=desc&order\_by=created\_at](https://api.inaturalist.org/v1/identifications/categories?user_id=1756341%2C1617933&current=true&order=desc&order_by=created_at)

I entered the following user\_id into the user\_id text box (whether as same line or separate lines):  
1756341,1617933

---

<div class="post-metadata">

**Author:** ![pisum](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@pisum](https://forum.inaturalist.org/u/pisum)\
**Post date:** [June 26, 2022, 3:25pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/4 "2022-06-26T15:25:37Z")

</div>

it looks like /v1/identifications/categories has a problem parsing multiple numeric user\_ids for whatever reason. i would just use the string-based (login) user\_ids instead of the numeric ids in this case. for example, use `&user_id=pisum,tiwane` instead of `&user_id=779571,28`.

i suppose this could be turned into a bug report so that someone could fix whatever the underlying problem is, but honestly, i’m not sure it’s worth the effort.

---

<div class="post-metadata">

**Author:** ![babellleee](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@babellleee](https://forum.inaturalist.org/u/babellleee)\
**Post date:** [June 26, 2022, 3:49pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/5 "2022-06-26T15:49:24Z")

</div>

Thanks, this works. I actually would like the breakdown of results by both user\_id and identification category. Do you happen to know if this is possible as well?

---

<div class="post-metadata">

**Author:** ![pisum](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@pisum](https://forum.inaturalist.org/u/pisum)\
**Post date:** [June 26, 2022, 3:58pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/6 "2022-06-26T15:58:42Z")

</div>

you’d have to just make one request per user. then you can either manually aggregate those, or issue another request for the aggregate.

---

<div class="post-metadata">

**Author:** ![babellleee](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@babellleee](https://forum.inaturalist.org/u/babellleee)\
**Post date:** [June 26, 2022, 4:26pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/7 "2022-06-26T16:26:47Z")

</div>

I see. Do you know how I can programme a loop if let’s say I have thousands of user\_id.

Tried the following code in Python, but something seems wrong somewhere:

USER\_IDS\_SAMPLE\_2 = [‘pisum’,‘tiwane’]

responses\_sample = list()

for user\_id in USER\_IDS\_SAMPLE\_2:  
response\_sample = requests.get(“[https://api.inaturalist.org/v1/identifications/categories?user\_id=user\_id&current=true&order=desc&order\_by=created\_at](https://api.inaturalist.org/v1/identifications/categories?user_id=user_id&current=true&order=desc&order_by=created_at)”).json()  
responses\_sample.append(response\_sample)

---

<div class="post-metadata">

**Author:** ![pisum](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@pisum](https://forum.inaturalist.org/u/pisum)\
**Post date:** [June 26, 2022, 4:35pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/8 "2022-06-26T16:35:40Z")

</div>

i’m not much of a py user (@jcook is usually the guy i would ask about py), but your request URL seems to be using a hardcoded =user\_id string value rather than referencing the user\_id variable from your loop. i bet if you fix that, things will work fine.

i would suggest that you incorporate a 1sec delay in the loop. iNat will throttle and potentially block you altogether if you send too many requests too quickly. here are more recommended practices for developers: [https://www.inaturalist.org/pages/api+recommended+practices](https://www.inaturalist.org/pages/api+recommended+practices).

> [@babellleee](#):
>
> let’s say I have thousands of user\_id

just curious, but what are you trying to do here that you would need to look up this information for this many users?

---

<div class="post-metadata">

**Author:** ![babellleee](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@babellleee](https://forum.inaturalist.org/u/babellleee)\
**Post date:** [June 26, 2022, 5:34pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/9 "2022-06-26T17:34:42Z")

</div>

Thanks. This is actually part of a class research project that I’m analysing various parameters of participation (e.g. no. of observations, species) in a particular area, in addition to identification.

---

<div class="post-metadata">

**Author:** ![jcook](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.inaturalist.org/jcook/32/19121_2.png) [@jcook](https://forum.inaturalist.org/u/jcook)\
**Post date:** [June 26, 2022, 6:03pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/10 "2022-06-26T18:03:52Z")

</div>

Here’s an example:

```python
import requests
from time import sleep

USER_IDS = ['pisum', 'tiwane']

def get_id_categories(user_id):
    """Get a summary of total identifications by category for a given user"""
    response = requests.get(
        'https://api.inaturalist.org/v1/identifications/categories',
        params={'user_id': user_id, 'current': 'true'},
    ).json()
    return {
        result['category']: result['count']
        for result in response.get('results', [])
    }

id_categories = {}
for user_id in USER_IDS:
    id_categories[user_id] = get_id_categories(user_id)
    sleep(1)

```

Which will give you a result like:

```python
{
    'pisum': {
        'improving': 8546,
        'leading': 4395,
        'supporting': 3262,
        'maverick': 30,
    },
    'tiwane': {
        'supporting': 50213,
        'improving': 49764,
        'leading': 14290,
        'maverick': 67,
    },
}

```

---

<div class="post-metadata">

**Author:** ![babellleee](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@babellleee](https://forum.inaturalist.org/u/babellleee)\
**Post date:** [June 27, 2022, 9:45pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/11 "2022-06-27T21:45:53Z")

</div>

Thanks @jcook. I’ll try it.

---

<div class="post-metadata">

**Author:** ![babellleee](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@babellleee](https://forum.inaturalist.org/u/babellleee)\
**Post date:** [July 8, 2022, 4:42pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/12 "2022-07-08T16:42:11Z")

</div>

Hi @jcook,

When using the above code, it runs successfully for about an hour before it finally gives the following message “KeyError: ‘results’”. I managed to get desired output for the data only up to the point that the code ran until. At other times, when I tried the code on different data samples, it immediately returns the error “KeyError: ‘results’”.

I thought you might have an idea for how to rectify this, given your expertise. Thanks very much in advance.

---

<div class="post-metadata">

**Author:** ![jcook](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.inaturalist.org/jcook/32/19121_2.png) [@jcook](https://forum.inaturalist.org/u/jcook)\
**Post date:** [July 8, 2022, 7:58pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/13 "2022-07-08T19:58:36Z")

</div>

That just means one or more of the requests return 0 results. You can use [dict.get()](https://docs.python.org/3/library/stdtypes.html#dict.get) to handle that. I updated the example above.

---

<div class="post-metadata">

**Author:** ![babellleee](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@babellleee](https://forum.inaturalist.org/u/babellleee)\
**Post date:** [July 12, 2022, 12:06pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/14 "2022-07-12T12:06:44Z")

</div>

Thanks @jcook

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/inaturalist/original/2X/7/7831452cf7f0d653ff1ffd34176334b7ef1b6a17.png) [@system](https://forum.inaturalist.org/u/system)\
**Post date:** [September 10, 2022, 12:07pm UTC](https://forum.inaturalist.org/t/getting-identification-data-for-multiple-user-ids-through-inaturalist-api/33105/15 "2022-09-10T12:07:40Z")

</div>

Closed on September 10, 2022, 12:07pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
