Welcome to the Kinde community.

A
A
A
M
T

Finding a kinde user with a specific custom property value using node.js management api

Using the management api in node.js, how could I find a Kinde user with a specific custom property value?

K
1 comment

To find a Kinde user with a specific custom property value using the Kinde Management API in Node.js, you can follow these steps: 1. *Get an Access Token*: First, you need to obtain an access token using your client credentials. 2. *Retrieve Users*: Use the access token to call the `users` endpoint and filter the users based on the custom property value. Here is an example of how you can achieve this in Node.js: ``` const fetch = require('node-fetch'); // Function to get access token const getAccessToken = async () => { try { const searchParams = { grant_type: "client_credentials", client_id: "<your_client_id>", client_secret: "<your_secret_id>", audience: "https://<your_subdomain>." }; const res = await fetch("https://<your_subdomain>.", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams(searchParams) }); const token = await res.json(); return token.access_token; } catch (err) { console.error(err); } }; // Function to get users with a specific custom property value const getUsersWithCustomProperty = async (propertyKey, propertyValue) => { const accessToken = await getAccessToken(); const headers = { 'Accept': 'application/json', 'Authorization': `Bearer ${accessToken}` }; try { const res = await fetch('https://<your_subdomain>.', { method: 'GET', headers: headers }); const data = await res.json(); // Filter users based on custom property value const usersWithCustomProperty = data.users.filter(user => user.properties && user.properties[propertyKey] === propertyValue ); console.log(usersWithCustomProperty); } catch (err) { console.error(err); } }; // Example usage getUsersWithCustomProperty('custom_property_key', 'desired_value'); ``` Replace `<your_client_id>`, `<your_secret_id>`, and `<your_subdomain>` with your actual Kinde credentials and subdomain. Also, replace `'custom_property_key'` and `'desired_value'` with the actual custom property key and value you are looking for.

Add a reply
Sign up and join the conversation on Slack
Join