TheJumpCloud / jcapi-python

21 stars 20 forks source link

How to get a list of all jumpcloud users? #38

Closed zaro0508 closed 4 years ago

zaro0508 commented 4 years ago

How do I get a list of all jumpcloud users using the systems_list[1] python api? It looks like the number of records returned is limited to 100.

limit = 10 # int | The number of records to return at once. Limited to 100. (optional) (default to 10)

I get an error when requesting more than 100

{"message":"Bad Request: request parameter \"limit\" exceeds maximum value of 100"}

when i request 1 record it works, it returns info about that single record but no meta data on whether there's more records in the system. How do i get a complete list of all jumpcloud users?

[1] https://github.com/TheJumpCloud/jcapi-python/blob/master/jcapiv1/docs/SystemsApi.md#systems_list

kmoorehead-jc commented 4 years ago

Hello @zaro0508!

Thanks for reaching out! I want to start by making a quick note that it looks like you're using systems_list, but if you're trying to get a list of all your users, you'll want to use systemusers_list (link).

Now on to the crux of your issue. The systemusers_list returns a systemuserlist, which contains the results and the total_count. You can reference the total_count by taking a look at the response.total_count. I'm having a bit of a hard time wording that last part at the moment so I've included a slightly modified try/exception from the systemusers_list example below to hopefully better illustrate my point.

try:
    # List all system users
    api_response = api_instance.systemusers_list(content_type, accept, limit=limit, skip=skip)
    pprint(api_response.total_count)
except ApiException as e:
    print("Exception when calling SystemusersApi->systemusers_list: %s\n" % e)

Once you're able to grab that, you should be able to use a while loop and increment the skip variable to return all of your users.

Please let me know if this helps clarify or if you have additional questions.

zaro0508 commented 4 years ago

Sorry for the invalid references. I didn't see the meta data because I was only looking at the response.results object I see total_count in the complete api response now. Thank you.