Fetching users from Builder.io using the API requires proper authentication, and typically the endpoints that allow you to access user information may need an authentication token rather than the public API key alone. To securely access user data, you will likely need to use the Builder.io Admin API with authentication.
Steps to Authenticate and Fetch Users
Generate an Admin API Key
Use the Admin API Endpoint with Proper Authentication Header
Navigate to Builder.io and log in to your account.
Access API Settings:
Go to Account Settings or Space Settings.
Find the section for API Keys.
Generate a new Private/Admin API Key if you don’t already have one.
Step 2: Use the Admin API Endpoint with Proper Authentication Header
With the Admin API key, you can access secure endpoints. Here is an example of how to do this using a tool like curl or a compatible HTTP client in your language of choice.
Using Curl:
curl -X GET "https://api.builder.io/v1/admin/users" \
-H "Authorization: Bearer YOUR_ADMIN_API_KEY"
Replace YOUR_ADMIN_API_KEY with your actual Admin API key.
Using Fetch in JavaScript:
const fetchUsers = async () => {
const response = await fetch('https://api.builder.io/v1/admin/users', {
method: 'GET',
headers: {
'Authorization': `Bearer YOUR_ADMIN_API_KEY`,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
const data = await response.json();
console.log(data);
};
fetchUsers().catch(console.error);
Ensure that the Admin API key has the required permissions to access user data. Double-check the settings and permissions for the API key in your Builder.io account.
Troubleshooting Common Issues
Invalid API Key: Ensure you are using the correct admin API key and not the public API key.
Permission Denied: Verify that the API key has the necessary permissions.
Endpoint URL: Ensure you are hitting the correct endpoint for the user data.
By following these steps, you can securely fetch user information from Builder.io using the Admin API key. Ensure proper permissions and correct endpoint usage to avoid authentication errors such as the 401 status.