Neowit developer docs
API referenceSupportKnowledge baseStatusApp
  • Overview
  • REST API
    • Introduction
    • Authentication
      • OAuth2
      • Basic Auth
    • Error codes
    • API reference
    • Coordinate systems
    • Query Language
      • Query Language Reference
  • Service Accounts
    • Introduction
    • Creating service accounts
  • Integrations
    • Introduction
    • MQTT
      • Native Sparkplug
      • Custom Starlark
  • Starlark
    • Introduction
    • Modules
      • time module
      • json module
      • math module
      • devices module
      • series module
      • sensors module
  • Tutorials
    • Introduction
    • Create users using API
Powered by GitBook
On this page
  • Overview
  • Prerequistes
  • Example
  • Environment Setup
  • Source Code
  • Customizing user authentication
  1. Tutorials

Create users using API

A guide on how to create users with our API

PreviousIntroduction

Last updated 3 months ago

Overview

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

API Reference:

Prerequistes

To use this API you must have an access token to a principal that is an organization admin (see ).

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.

pip install requests

Source Code

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

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 then select your Idp and get the ID from the URL, it will have the following format <ID>.

https://app.neowit.io/api/swagger/index.html#/user/post_user_v1_user
REST API/Authentication
https://app.neowit.io/settings/idps
https://app.neowit.io/settings/idps/edit/