Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

This how-to article describes how you can manage your own sub-users on our platform. This allows you to have one main-user which can create new users and assign / un-assign specific BikeTrax’s to them.

  1. Make sure to first contact PowUnity in order to grant your account “Manager” rights.

  2. Note that new accounts created with this approach can not be used to login via the app. They are limited to be used for traccar.powunity.com and the API.

Manual Instructions

The following steps describe how to create a new user (steps 1-3) and assign / un-assign devices to a user (step 4)

  1. Open “User Management”

2. Open user creation dialog

3. Set name, email and password and confirm with checkmark

4. To assign / un-assign devices to users, select the user, open device dialog, check / uncheck desired devices

Implementation Instructions

With the AUTH_TOKEN provided by PowUnity you can directly access our GPS Backend (Traccar API).

User Creation

Javascript sample code for user creation:

  const TRACCAR_AUTH_TOKEN = 'AUTH_TOKEN_GIVEN_FROM_POWUNITY';
  const TRACCAR_API_URL = 'https://traccar.powunity-staging.com/api';

  var name = 'Max Mustermann';
  var email = 'max@mustermann.at';
  var password = require('crypto').randomBytes(16).toString('hex');

  // Authorization token for your management Traccar user 
  var headers = { 
    'Content-Type': 'application/json',
    'authorization': 'Basic ' + TRACCAR_AUTH_TOKEN
  };

  var json = {
    name,
    email,
    password,
    deviceLimit: -1
  };
  
  console.log('Calling traccar API at', TRACCAR_API_URL);
  request.post({
    url: TRACCAR_API_URL + '/users',
    headers: headers,
    json: json
  }, function (err, response, body) {
    if (err) {
      console.log('Traccar create user API call returned an error,', err);
      throw new Error("Error provisioning server resource, please contact support");
    }
    // user created, add sessionToken to user profile
    if (response.statusCode === 200) {
      console.log('New traccar password has been set');
      return;
    }
    console.log('Traccar returned an unknown error. Body: ' + body);
    throw new Error("Internal error provisioning your account, please contact support");
  });

Response from Traccar contains the user.id which has to be stored for later user deletion!

See: https://www.traccar.org/api-reference/#operation--users-post

User Deletion

Information for DELETE ‘/user’ endpoint: https://www.traccar.org/api-reference/#operation--users--id--delete

  • No labels