Skip to content

API Documentation

Reffx edited this page Aug 26, 2021 · 10 revisions

General Use

All API methods can be called via .../method_name. The authentication involved in this software happens using a token, which is required for every call apart from the login call. The token is provided by the backend environment in response to the login. Since the token is necessary to do any calls, the API methods make use of the HTTP methods POST. As a user of type admin, data can be retrieved as well as altered. Where applicable, is specified below.

API methods

Authentication

/login

This method is used to login the user.

  • username string

An username for uniquely identifying the user.

  • password string

The password to confirm the identity of the user.

Example of a login request (dart):

final String url = '$activeHost/login';
     final response = await http.post(
       Uri.parse(url),
       headers: {
         "content-type": "application/json",
       },
       body: json.encode({
         "username": "admin_xxx",
         "password": "password_xxx",
       });

The response is a JSON object. Two HTML codes are important for this method:

  • 200: Everything was okay.
  • 400: Oops, something went wrong. Check the error message and make sure data is correctly submitted.

Example of a login response:

{
  "username": "admin_xxx",
  "password": null,
  "token": "197bfc45-5e85-4e19-9208-814f05ec7dc3",
  "usertype": "admin",
  "activeOpeningHours": false,
  "openingHours": null,
  "activeGreetingConfiguration": false,
  "greetingConfiguration": null
}

/changePassword

This method is used to change the password of a existing user.

  • token string

The token for uniquely identifying the user.

  • oldPassword string

The current password to confirm that an authorized person wants to change it.

  • newPassword string

The new password.

Example of a changePassword request (dart):

final String url = '$activeHost/changePassword';
     final response = await http.post(
       Uri.parse(url),
       headers: {
         "content-type": "application/json",
       },
       body: json.encode({
          "token": "cf28b9cb-e8e0-488d-9970-702067ac3b62",
          "oldPassword": "1234",
          "newPassword": "1236",
       });

The response is a string. Two HTML codes are important for this method:

  • 200: Everything was okay.
  • 400: Oops, something went wrong. Check the error message and make sure data is correctly submitted.

Example of a changePassword response:

"updated password of User admin_xxx"

/logout

This method is used to logout an user. As a result, the token can no longer be used.

  • token string

The token for uniquely identifying the user.

Example of a logout request (dart):

final String url = '$activeHost/logout';
     final response = await http.post(
       Uri.parse(url),
       headers: {
         "content-type": "application/json",
       },
       body: json.encode({
          "token": "cf28b9cb-e8e0-488d-9970-702067ac3b62",
       });

The response is a string. Two HTML codes are important for this method:

  • 200: Everything was okay.
  • 400: Oops, something went wrong. Check the error message and make sure data is correctly submitted.

Example of a logout response:

"logged out admin_xxx"

Number management

/createUser

This method is used to create a new user in the database for calls. It does not provide the user an account that can be used for a login.

  • token string

The token for uniquely identifying the user.

  • number string

The number on which the person should be called.

  • bureau string

The bureau the user belongs to.

Note: The bureau already needs to in the database. No new bureau can be created by the user due to falsification of statistics. If necessary, the developer can do this directly in the database.

  • department string

The department the user belongs to.

  • firstname string

The firstname of the user.

  • lastname string

The lastname of the user.

  • email string

The email of the user.

Example of a createUser request (dart):

final String url = '$activeHost/createUser';
     final response = await http.post(
       Uri.parse(url),
       headers: {
         "content-type": "application/json",
       },
       body: json.encode({
         "token": "6bdf00ee-3492-4f2e-9570-4b9aa8b4d3ca",
         "number": "+497009999",
         "bureau": "Hauptamt",
         "department": "Sport",
         "firstname": "Hans",
         "lastname": "Muster",
         "email": "hans.muster@verwaltung.de"
       });

The response is a string. Two HTML codes are important for this method:

  • 200: Everything was okay.
  • 400: Oops, something went wrong. Check the error message and make sure data is correctly submitted.

Example of a createUser response:

"created new User"

/getAllUsers

This method is used to get a list of all users that can be called. As long as the active is true, the user can potentially be called.

  • token string

The token for uniquely identifying the user.

Example of a getAllUsers request (dart):

final String url = '$activeHost/getAllUsers';
     final response = await http.post(
       Uri.parse(url),
       headers: {
         "content-type": "application/json",
       },
       body: json.encode({
         "token": "6bdf00ee-3492-4f2e-9570-4b9aa8b4d3ca",
       });

The response is a JSON object. Two HTML codes are important for this method:

  • 200: Everything was okay.
  • 400: Oops, something went wrong. Check the error message and make sure data is correctly submitted.

Example of a getAllUsers response:

[
  {
    "basepool_id": "60bdf47d5949a33630f8ffa2",
    "user_id": "60bdf47d5949a33630f8ffa3",
    "number": "+49703194661",
    "firstname": "Sven",
    "lastname": "Meier",
    "bureau": "Amt für Bildung und Betreuung",
    "department": "Service und Steuerung",
    "email": "sven.meier@rngtrainer.de",
    "active": true
  },
  {
    "basepool_id": "60bdf47d5949a33630f8ff70",
    "user_id": "60bdf47d5949a33630f8ff71",
    "number": "+49703194262",
    "firstname": "Stefanie",
    "lastname": "Müller",
    "bureau": "Amt für Bildung und Betreuung",
    "department": "Service und Steuerung",
    "email": "stefanie.mueller@rngtrainer.de",
    "active": true
  },
  {
    "basepool_id": "60bdf47d5949a33630f8ff7f",
    "user_id": "60bdf47d5949a33630f8ff80",
    "number": "+49703194359",
    "firstname": "Joe",
    "lastname": "Herlimann",
    "bureau": "Amt für Bildung und Betreuung",
    "department": "Service und Steuerung",
    "email": "joe.herlimann@rngtrainer.de",
    "active": true
  }
]

/updateUser

This method is used to update an existing user. Only department, firstname, lastname, email can be updated.

  • token string

The token for uniquely identifying the user.

  • basepool_idstring

Unique id identifying the entry in the database.

  • user_id string

Not necessarily unique id. Users with the same phone number and email (both has to be the same) have the same user_id.

  • department string

The department the user belongs to.

  • firstname string

The firstname of the user.

  • lastname string

The lastname of the user.

  • email string

The email of the user.

Example of a updateUser request (dart):

final String url = '$activeHost/updateUser';
     final response = await http.post(
       Uri.parse(url),
       headers: {
         "content-type": "application/json",
       },
       body: json.encode({
         "token": "6bdf00ee-3492-4f2e-9570-4b9aa8b4d3ca",
         "basepool_id": "611d52ebc508ed29e0562875",
         "user_id": "611d7b79c508ed12fc34e1d8",
         "department": "Sport",
         "firstname": "Peter",
         "lastname": "Muster",
         "email": "peter.muster@rngtrainer.de"
      });

The response is a string. Two HTML codes are important for this method:

  • 200: Everything was okay.
  • 400: Oops, something went wrong. Check the error message and make sure data is correctly submitted.

Example of a updateUser response:

User updated, please Refresh User list with /getAllUsers

/setUserState

This method is used to set the userState to active/inactive. A user in the database (according unique basepoo_id) can't be deleted according he falsification of the statistics. However, the user can be set to inactive.

  • token string

The token for uniquely identifying the user.

  • basepool_id string

Unique id identifying the entry in the database.

  • active boolean

Status of the user.

Example of a updateUser request (dart):

final String url = '$activeHost/setUserState';
     final response = await http.post(
       Uri.parse(url),
       headers: {
         "content-type": "application/json",
       },
       body: json.encode({
         "token": "6bdf00ee-3492-4f2e-9570-4b9aa8b4d3ca",
         "basepool_id": "611d52ebc508ed29e0562875",
         "active": "false",
      });

The response is a string. Two HTML codes are important for this method:

  • 200: Everything was okay.
  • 400: Oops, something went wrong. Check the error message and make sure data is correctly submitted.

Example of a setUserState response:

Set User State

Clone this wiki locally