Get Users with Kind TS-SDK
I have just started out with the Typescript Sdk with Nestjs and the Kinde Api to get Users and I have few Questions about behaviour and usage (tried both from postman and SDK)
1. the documentation at https://kinde.com/api/docs/#list-users says
"Specify additional data to retrieve. Use "organizations" and/or "identities"."
what is the correct format to pass both Oganizations and Identities, tried some combinations and got 550s back
2. the
user_id
does not seem to do anything, is this a bug or am I using it incorrectly?
3. the next_token
always returns a value event when there is no more data to get, will this be changed to return null if there is no more data, or should I always call the api at least twice?
Thanks5 Replies
Hey @mariodebono thanks for reaching out.
For the first part of your question regarding the correct format to pass both "organizations" and "identities" in the expand parameter, you should use a comma-separated list without spaces. Here's an example of how to format the request:
GET https://{businessName}.kinde.com/api/v1/users?expand=organizations,identities
If you are receiving 550 errors, which are not standard HTTP status codes, it could be due to an issue with the server or a misconfiguration on your end. Please ensure that you are using the correct endpoint and that your request is properly formatted.
Regarding the user_id parameter, it should filter the results by the specified user ID. If it's not working as expected, please double-check that you are using a valid user ID and that it is correctly included in the query string. If the issue persists, let me know.
For the next_token behavior, it is common for APIs to return a token even when there are no more results to paginate through. This allows for a consistent interface. However, if the next_token is always returning a value even when there is no more data, you should check the response body to see if there are actually more users to retrieve. If the list of users is empty or the same data is returned, you can stop making further requests.
For any of these issues, if you continue to experience problems, please let me know
Hi @Andre @ Kinde
Sorry I wasn't clear, so the errors I get are 500 not 550,
calling through postman
{{kinde_domain}}/api/v1/users?expand=organizations,identities
returns
passing organizations
and identities
individually work as expected
The user_id
behaviour I was expecting is that if i pass the incorrect user_id
I should get no results back
{{kinde_domain}}/api/v1/users?user_id=kp_blablabla
This still returns users [{...}], although I only have one user, I would expect an empty array
About the next_token
, I wasn't clear, apologies.
The first request, I get the user, and a next_token
field populated, however when I call the api again with the next_token
I do get no results and next_token: null
with users set to null.
As you explained, this is intended behaviour, and I will always call the endpoint again with the next_token
and a page_size
of 1 to show if there is a next page or not.Hey @mariodebono - sorry to hear you're having trouble with the API - re: the expand organizations & identities, would you be able to try
https://domain.kinde.com/api/v1/users?expand=organizations&expand=identities
? It shouldn't return a 500 though, I'll have a look into that - thanks for flagging.
With the singular user one, you can use user?id=kp_blablabla&expand=organizations&expand=identities
- if the ID is incorrect, it'll return an INVALID_USER_ID
err.
Please let me know if I've missed anything / if you have any more qs or are running into anything else! Thanks 🙂Hi @viv (kinde)
Thanks for the update
The expands works correct like this
for the
user_id
maybe you can
update the documentation at https://kinde.com/api/docs/#list-users to reflect this, also the user
api requires id
not user_id
in case anyone else finds this messageHi @mariodebono - thanks for testing this out & getting back to us! I've pushed a change (not yet in prod) to update
users
( https://domain.kinde.com/api/v1/users?user_id=123
) to err out if an invalid user_id
is provided - let me know if that'd be what you're expecting ☺️ ?
& Yupp, https://kinde.com/api/docs/#get-user - uses id
at the moment, rather than user_id
- we'll look towards standardising in v2. Thanks for your help!