# Authentication Failed

**URL:** <https://forum.builder.io/t/authentication-failed/5827>\
**Category:** Technical Questions\
**Created:** [June 20, 2024, 6:17am UTC](https://forum.builder.io/t/authentication-failed/5827 "2024-06-20T06:17:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aditi](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@aditi](https://forum.builder.io/u/aditi)\
**Post date:** [June 20, 2024, 6:17am UTC](https://forum.builder.io/t/authentication-failed/5827/1 "2024-06-20T06:17:31Z")

</div>

I am Trying to get Users of [Builder.io](http://Builder.io) using [https://cdn.builder.io/api/v1/users?apiKey=“{my\_public\_key}”&cachebust=true](https://cdn.builder.io/api/v1/users?apiKey=%22%7Bmy_public_key%7D%22&cachebust=true) , But There is no documentation for How to Authenticate using token ,Can Someone please help?

Responce:401 Authentication Required

---

<div class="post-metadata">

**Author:** ![anon43891756](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@anon43891756](https://forum.builder.io/u/anon43891756)\
**Post date:** [June 25, 2024, 9:35am UTC](https://forum.builder.io/t/authentication-failed/5827/2 "2024-06-25T09:35:07Z")

</div>

Hi @aditi Welcome to [Builder.io](http://Builder.io) Forum!

Fetching users from [Builder.io](http://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](http://Builder.io) Admin API with authentication.

### Steps to Authenticate and Fetch Users

1. **Generate an Admin API Key**
2. **Use the Admin API Endpoint with Proper Authentication Header**

### Step 1: Generate an Admin API Key

1. **Log in to Your [Builder.io](http://Builder.io) Account:**

2. **Access API Settings:**

### 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:

```sh
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:

```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);

```

### Example of Fetching Users in Node.js:

```javascript
const fetch = require('node-fetch');

const fetchUsers = async () => {
  try {
    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(`HTTP error! Status: ${response.status}`);
    }

    const users = await response.json();
    console.log(users);
  } catch (error) {
    console.error('Error fetching users:', error);
  }
};

fetchUsers();

```

### Verifying Permissions and Access

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](http://Builder.io) account.

### Troubleshooting Common Issues

1. **Invalid API Key** : Ensure you are using the correct admin API key and not the public API key.
2. **Permission Denied** : Verify that the API key has the necessary permissions.
3. **Endpoint URL** : Ensure you are hitting the correct endpoint for the user data.

### Documentation Links

- [Builder.io Admin API](https://www.builder.io/c/docs/admin-graphql-api)
- [API Key Management](https://www.builder.io/c/docs/using-your-api-key)

### Conclusion

By following these steps, you can securely fetch user information from [Builder.io](http://Builder.io) using the Admin API key. Ensure proper permissions and correct endpoint usage to avoid authentication errors such as the 401 status.
