User Management

Overview

The User Management API allows you to manage user accounts and their permissions within the RCAMS system. Users can be assigned to specific districts, determining which schools, groups, and lights they can access and control. This section details the API endpoints for user management, including listing, creating, updating, and deleting users, as well as managing their district assignments.

Note: All user management endpoints require basic authentication. The user making these requests must have administrator permissions to manage other users.

User Management API Endpoints
Operation Endpoint Action Parameter
List Users /user.php list
Get User /user.php get
Create User /user.php insert
Update User /user.php update
Delete User /user.php remove
Assign Districts to User /userdistrict.php N/A
Get User Data /userdata.php N/A

List Users

Retrieves all users in the system.

POST/user.php

Returns a list of all user accounts in the system.

Request Parameters
Parameter Type Required Description
action String Yes Must be set to list
Response

Returns a list of user accounts with their details.

Example Response
{
  "status": "OK",
  "message": "Data retrieved successfully",
  "total": 5,
  "users": [
    {
      "user_token": "8ca38857213c9eec6689e9c86311c7ada086d44262bbc532444cb81e99d67c64",
      "user_name": "Noel Vanegas",
      "user_picture_url": "https://rcamsapi.spheronomics.com/images/ninja_developer.png",
      "user_phone": "",
      "user_email": "noel.vanegs@sph.com",
      "last_login": "2025-04-14 09:02:34",
      "enable": "yes"
    },
    {
      "user_token": "9865d065a4ec09e3de4755d02affdec5f6559833857df332c5c78efd48605a9a",
      "user_name": "Jacob Mata",
      "user_picture_url": "https://rcamsapi.spheronomics.com/images/users/jacob_samurai.png",
      "user_phone": "",
      "user_email": "jacob@sph.com",
      "last_login": "2025-04-09 15:46:40",
      "enable": "yes"
    },
    {
      "user_token": "21e2bc1297790f861b50d0868f256b450495edd69188107be2c8668918b37665",
      "user_name": "rap user",
      "user_picture_url": "",
      "user_phone": "",
      "user_email": "rap.user@sph.com",
      "last_login": "2025-04-09 16:17:52",
      "enable": "yes"
    }
  ]
}
Example Request (JavaScript)
// Set up the request
const jsonData = {
  "action": "list"
};

// Make the API call
fetch('https://rcamsapi.spheronomics.com/api/v2/user.php', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa('api_username:api_password')
  },
  body: jsonData
})
.then(response => response.json())
.then(data => {
  if (data.status === 'OK') {
    console.log(`Found ${data.total} users:`, data.users);
  } else {
    console.error('Error:', data.message);
  }
})
.catch(error => console.error('Error:', error));

Get User

Retrieves details for a specific user.

POST/user.php

Returns detailed information about a specific user.

Request Parameters
Parameter Type Required Description
action String Yes Must be set to get
usr_tokenid String Yes Token ID of the user to retrieve
Response

Returns the details of the specified user.

Example Response
{
  "status": "OK",
  "user_tokenid": "8a29379ea75f3afcb7def75070d51d6a8062976b8934eeab60ffe4b7aaa7955c",
  "user_names": "Test4 User4",
  "user_name": "user.test4",
  "user_email": "testuser4@email.test.con",
  "user_phone": "999-123-4562",
  "user_picture_url": "https://rcamsapi.spheronomics.com/images/ninja_developer.png",
  "last_login": "",
  "districts": "1,3,5"
}
Example Request (JavaScript)
// Set up the request
const jsonData = {
  "action": "get",
  "usr_tokenid": "8a29379ea75f3afcb7def75070d51d6a8062976b8934eeab60ffe4b7aaa7955c"
};

// Make the API call
fetch('https://rcamsapi.spheronomics.com/api/v2/user.php', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa('api_username:api_password')
  },
  body: jsonData
})
.then(response => response.json())
.then(data => {
  if (data.status === 'OK') {
    console.log('User details:', data);
  } else {
    console.error('Error:', data.message);
  }
})
.catch(error => console.error('Error:', error));

Create User

Creates a new user account in the system.

POST/user.php

Creates a new user account with the specified details.

Request Parameters
Parameter Type Required Description
action String Yes Must be set to insert
first_name String Yes User's first name
last_name String Yes User's last name
user_name String Yes Username for login
email String Yes Email address
password String Yes Password
phone String No Phone number
picture_url String No URL to profile picture
notes String No Additional notes
Response

Returns confirmation that the user was created and provides the new user token.

Example Response
{
  "status": "OK",
  "message": "User created successfully",
  "user_token": "8a29379ea75f3afcb7def75070d51d6a8062976b8934eeab60ffe4b7aaa7955c"
}
Example Request (JavaScript)
// Set up the request
const jsonData = {
  "action": "insert",
  "first_name": "John",
  "last_name": "Smith",
  "user_name": "jsmith",
  "email": "john.smith@example.com",
  "password": "securePassword123",
  "phone": "555-123-4567",
  "picture_url": "https://example.com/photos/jsmith.jpg",
  "notes": "Administrator for North Region"
};

// Make the API call
fetch('https://rcamsapi.spheronomics.com/api/v2/user.php', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa('api_username:api_password')
  },
  body: jsonData
})
.then(response => response.json())
.then(data => {
  if (data.status === 'OK') {
    console.log('User created with token:', data.user_token);
  } else {
    console.error('Error:', data.message);
  }
})
.catch(error => console.error('Error:', error));

Update User

Updates an existing user account's information.

POST/user.php

Updates the details of an existing user account.

Request Parameters
Parameter Type Required Description
action String Yes Must be set to update
usr_tokenid String Yes Token ID of the user to update
first_name String Yes Updated first name
last_name String Yes Updated last name
phone String No Updated phone number
picture_url String No Updated profile picture URL
notes String No Updated notes
Response

Returns confirmation that the user was updated.

Example Response
{
  "status": "OK",
  "message": "User updated successfully"
}
Example Request (JavaScript)
// Set up the request
const jsonData = {
  "action": "update",
  "usr_tokenid": "8a29379ea75f3afcb7def75070d51d6a8062976b8934eeab60ffe4b7aaa7955c",
  "first_name": "Jonathan",
  "last_name": "Smith",
  "phone": "555-987-6543",
  "picture_url": "https://example.com/photos/jonathan_smith.jpg",
  "notes": "Senior Administrator for North Region"
};

// Make the API call
fetch('https://rcamsapi.spheronomics.com/api/v2/user.php', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa('api_username:api_password')
  },
  body: jsonData
})
.then(response => response.json())
.then(data => {
  if (data.status === 'OK') {
    console.log('User updated successfully');
  } else {
    console.error('Error:', data.message);
  }
})
.catch(error => console.error('Error:', error));

Delete User

Removes a user account from the system.

Warning: Deleting a user account will permanently remove their access to the system. This action cannot be undone.

POST/user.php

Deletes a user account from the system.

Request Parameters
Parameter Type Required Description
action String Yes Must be set to remove
usr_tokenid String Yes Token ID of the user to delete
Response

Returns confirmation that the user was deleted.

Example Response
{
  "status": "OK",
  "message": "User removed successfully"
}
Example Request (JavaScript)
// Set up the request

const jsonData = {
  "action": "remove",
  "usr_tokenid": "8a29379ea75f3afcb7def75070d51d6a8062976b8934eeab60ffe4b7aaa7955c"
};

// Make the API call
fetch('https://rcamsapi.spheronomics.com/api/v2/user.php', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa('api_username:api_password')
  },
  body: jsonData
})
.then(response => response.json())
.then(data => {
  if (data.status === 'OK') {
    console.log('User removed successfully');
  } else {
    console.error('Error:', data.message);
  }
})
.catch(error => console.error('Error:', error));

Assign Districts to User

Assigns districts to a user, determining which districts they can access.

POST/userdistrict.php

Assigns a list of districts to a user for access control.

Request Parameters
Parameter Type Required Description
usr_tokenid String Yes Token ID of the user
district_list String Yes Comma-separated list of district IDs (e.g., "1,2,3")
Response

Returns confirmation that the districts were assigned to the user, with details for each district assignment.

Example Response
{
  "status": "OK",
  "message": "Districts added successfully",
  "result": [
    {
      "district_id": "4",
      "status": "OK",
      "message": "District already granted"
    },
    {
      "district_id": "5",
      "status": "OK",
      "message": "District added successfully"
    }
  ]
}
Example Request (JavaScript)
// Set up the request
const jsonData = {
  "action": "insert",
  "usr_tokenid": "8a29379ea75f3afcb7def75070d51d6a8062976b8934eeab60ffe4b7aaa7955c",
  "district_list": "1,2,3"
};

// Make the API call
fetch('https://rcamsapi.spheronomics.com/api/v2/userdistrict.php', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa('api_username:api_password')
  },
  body: jsonData
})
.then(response => response.json())
.then(data => {
  if (data.status === 'OK') {
    console.log('Districts assigned successfully:', data.result);
  } else {
    console.error('Error:', data.message);
  }
})
.catch(error => console.error('Error:', error));

Get User Data

Retrieves comprehensive data for the authenticated user, including districts, schools, groups, and WiFi settings they have access to.

POST/userdata.php

Returns detailed information about all resources the authenticated user has access to.

Request Parameters
Parameter Type Required Description
Response

Returns a hierarchical structure of all resources the user has access to, including districts, schools, groups, and WiFi settings.

Example Response
{
  "status": "OK",
  "districts": [
    {
      "district_id": 101,
      "district_name": "North County School District",
      "schools": [
        {
          "school_id": 1001,
          "school_name": "Lincoln High School",
          "school_address": "123 Education Ave",
          "wifi_ssids": [
            {
              "ssid_id": 7001,
              "ssid_name": "LHS-STAFF"
            },
            {
              "ssid_id": 7002,
              "ssid_name": "LHS-GUEST"
            }
          ],
          "groups": [
            {
              "group_id": 5001,
              "group_name": "Science Department"
            },
            {
              "group_id": 5002,
              "group_name": "Faculty Staff"
            }
          ]
        },
        {
          "school_id": 1002,
          "school_name": "Washington Elementary",
          "school_address": "456 Learning Blvd",
          "wifi_ssids": [
            {
              "ssid_id": 7003,
              "ssid_name": "WES-NETWORK"
            }
          ],
          "groups": [
            {
              "group_id": 5003,
              "group_name": "Administration"
            }
          ]
        }
      ]
    }
  ]
}
Example Request (JavaScript)
// Set up the request
// Make the API call
fetch('https://rcamsapi.spheronomics.com/api/v2/userdata.php', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa('api_username:api_password')
  }  
})
.then(response => response.json())
.then(data => {
  if (data.status === 'OK') {
    console.log('User data:', data.districts);
    
    // Process the hierarchical data
    data.districts.forEach(district => {
      console.log(`District: ${district.district_name}`);
      
      district.schools.forEach(school => {
        console.log(`  School: ${school.school_name}`);
        
        console.log('    WiFi Networks:');
        school.wifi_ssids.forEach(wifi => {
          console.log(`      - ${wifi.ssid_name}`);
        });
        
        console.log('    Groups:');
        school.groups.forEach(group => {
          console.log(`      - ${group.group_name}`);
        });
      });
    });
  } else {
    console.error('Error:', data.message);
  }
})
.catch(error => console.error('Error:', error));

Code Examples

User Management Example

The following example demonstrates a complete flow for user management, including creating a user, updating their information, assigning districts, and retrieving their data.

Complete User Management Example (JavaScript)
// Helper function for API requests
async function makeApiRequest(endpoint, params) {
  // API credentials - replace with actual values
  const apiUsername = 'your_api_username';
  const apiPassword = 'your_api_password';
  
  // Create form data from params
  const json = {};
  for (const [key, value] of Object.entries(params)) {
    json[key] = value;
  }
  const jsonString = JSON.stringify(json);
  
  try {
    const response = await fetch(`https://rcamsapi.spheronomics.com/api/v2/${endpoint}`, {
      method: 'POST',
      headers: {
        'Authorization': 'Basic ' + btoa(`${apiUsername}:${apiPassword}`)
      },
      body: jsonString
    });
    
    return await response.json();
  } catch (error) {
    console.error('API request failed:', error);
    throw error;
  }
}

// Example usage - User Management
async function userManagementExample() {
  try {
    // 1. List all users
    console.log('Listing all users...');
    const listResponse = await makeApiRequest('user.php', {
      action: 'list'
    });
    
    console.log(`Found ${listResponse.total} users:`, listResponse.users);
    
    // 2. Create a new user
    console.log('Creating a new user...');
    const createResponse = await makeApiRequest('user.php', {
      action: 'insert',
      first_name: 'Jane',
      last_name: 'Doe',
      user_name: 'jdoe',
      email: 'jane.doe@example.com',
      password: 'securePassword456',
      phone: '555-987-6543',
      picture_url: 'https://example.com/photos/jdoe.jpg',
      notes: 'School Administrator'
    });
    
    if (createResponse.status === 'OK') {
      const newUserToken = createResponse.user_token;
      console.log(`Created user with token: ${newUserToken}`);
      
      // 3. Update the user information
      console.log('Updating user information...');
      const updateResponse = await makeApiRequest('user.php', {
        action: 'update',
        usr_tokenid: newUserToken,
        first_name: 'Jane',
        last_name: 'Doe-Smith',
        phone: '555-987-6543',
        picture_url: 'https://example.com/photos/jdoe_updated.jpg',
        notes: 'Senior School Administrator'
      });
      
      console.log('Update result:', updateResponse.message);
      
      // 4. Assign districts to the user
      console.log('Assigning districts to user...');
      const districtResponse = await makeApiRequest('userdistrict.php', {
        usr_tokenid: newUserToken,
        district_list: '1,2,3'
      });
      
      console.log('District assignment result:', districtResponse);
      
      // 5. Get user data (using the new user's token)
      // In a real scenario, you would need to login as the new user to get their token
      // This is just for demonstration purposes
      console.log('Getting user data...');
      const userDataResponse = await makeApiRequest('userdata.php', {
      });
      
      console.log('User data:', userDataResponse);
      
      // 6. Delete the user (commented out for safety)
      // Uncomment to actually delete the user
      /*
      console.log('Deleting user...');
      const deleteResponse = await makeApiRequest('user.php', {
        action: 'remove',
        usr_tokenid: newUserToken
      });
      
      console.log('Delete result:', deleteResponse.message);
      */
    }
  } catch (error) {
    console.error('An error occurred:', error);
  }
}

// Run the example (you would need a valid token)
// First login to get a token, then run this example with the token
/*
async function runExample() {
  // Login to get a token
  const loginResponse = await makeApiRequest('login.php', {
    user: 'admin@example.com',
    pass: 'password123'
  });
  
  if (loginResponse.status === 'OK') {
    await userManagementExample();
  } else {
    console.error('Login failed:', loginResponse.message);
  }
}

runExample();
*/