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

Version 1 Next »

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