Get user by id
Hello
Trying to get a user by Id using the managment api, but the docs only explain HTML queries and not the JS library. How can i provide arguments in to the function?
Example:
import { Users, init } from "@kinde/management-api-js";
export default defineEventHandler(async (event) => {
init();
const data = await Users.getUserData();
return data
})
8 Replies
Just confirming you are not seeing the JS example on the right panel in our API docs? https://kinde.com/api/docs/#get-user
To get a user by ID using the Kinde Management API in JavaScript, you need to provide the user ID as an argument to the getUserData function.
Below is some general guidance based on the API documentation: API Endpoint The API endpoint for getting user data is GET /api/v1/user. This endpoint requires a user ID as a query parameter. General Approach You would typically need to pass the user ID when calling the getUserData function. The function should then use this ID to make the API request. Here's a general approach you might follow: Import the necessary functions from the Kinde Management API library. Initialize the API client. Call the getUserData function with the user ID as an argument.
Below is some general guidance based on the API documentation: API Endpoint The API endpoint for getting user data is GET /api/v1/user. This endpoint requires a user ID as a query parameter. General Approach You would typically need to pass the user ID when calling the getUserData function. The function should then use this ID to make the API request. Here's a general approach you might follow: Import the necessary functions from the Kinde Management API library. Initialize the API client. Call the getUserData function with the user ID as an argument.
the api returns a 500 error when using the library how i would expect
await User.getUserData('kp_xxx')
User.getUsers()
correctly retrieves all users so I know it is installed correctly
Sorry for tagging but can you provide any help on this @Daniel_Kinde? I see you wrote most of the library.Hi @isakwang ,
getUserData takes the type
GetUserDataData
(https://github.com/kinde-oss/management-api-js/blob/main/lib/api/types.gen.ts#L2786C1-L2795C3)
So you would need to use like this
Let me know if you have any further issuesThat worked. Thanks
Let me know if improvements can be made, was there an issue with how the typing for the inputs was being presented?
I have added a pull request to add it to the readme. Long term it would be nice if the docs for the managment api included the library
and it would be nice if functions that only return one object had an option for it to not be an array like Supabases .single()
Thank you 🙏 I will check the PR shortly
nevermind this. I was using the wrong api route in my codespace