# Create users using API

## Overview

This guide aims to provide the basic understanding and ability to add users to the Neowit platform using the API.

API Reference: <https://app.neowit.io/api/swagger/index.html#/user/post_user_v1_user>

## Prerequistes

To use this API you must have an access token to a principal that is an organization admin (see [REST API/Authentication](/rest-api/authentication/oauth2.md)).

## Example

The example code in this page is provided as is, it may not work in your environment and should be used as a quick guide for implementation rather than code to be used in a production environment.

### Environment Setup

The following packages are required by the example code and must be installed.

```bash
pip install requests
```

### Source Code

If you wish to run the code locally, make sure you have a working runtime environment.

```python
import requests # pip install requests

user_endpoint = 'https://app.neowit.io/api/user/v1/user'
token='' # add token here

def create_user(access_token):
    data = {
        'email':    'testuser321@contoso.com',
        'name':     'testuser321',
        'locale':   'en-US',
        'role':     'ROLE_MEMBER', # ROLE_MEMBER or ROLE_ADMIN
        'timezone': 'Europe/Oslo',
        'idpId':    '', # blank if username/password
    }

    return requests.post(
        url=user_endpoint,
        headers={
            'Authorization': 'Bearer ' + access_token,
            'Content-Type':  'application/json',
        },
        json=data,
    )
    
def main():
    print(create_user(token).json())

if __name__ == '__main__':
    main()
```

### Customizing user authentication

If you wish to add a specific Idp you can go to <https://app.neowit.io/settings/idps> then select your Idp and get the ID from the URL, it will have the following format <https://app.neowit.io/settings/idps/edit/>*\<ID>.*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.neowit.io/tutorials/create-users-using-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
