DEV Community

DEV-AI
DEV-AI

Posted on

Dynamic User Task Assignment with REST API: Querying Users by Role and Attributes for Candidate Groups

Modern business process management requires flexible and dynamic task assignment capabilities. Instead of static user assignments, organizations need to dynamically determine who should handle specific tasks based on current user availability, roles, and custom attributes. This article demonstrates how to leverage REST APIs to query user lists with specific criteria and use those results as dynamic candidate groups for task assignment in process automation platforms.

The Challenge: Static vs. Dynamic Assignment

Traditional task assignment approaches often rely on:

  • Static groups defined at design time
  • Hard-coded user lists that become outdated
  • Manual reassignment when team structures change

Dynamic assignment offers significant advantages:

  • Real-time user availability checking
  • Attribute-based filtering (skills, location, workload)
  • Automatic adaptation to organizational changes
  • Load balancing across available users

Architecture Overview

The dynamic assignment architecture consists of three main components:

1. User Management System

  • Maintains user profiles with roles and custom attributes
  • Exposes REST API endpoints for user queries
  • Handles authentication and authorization

2. Process Engine Integration

  • Makes REST API calls during process execution
  • Transforms user data into candidate groups
  • Assigns tasks dynamically based on retrieved users

3. Task Management Interface

  • Displays tasks to appropriate users
  • Handles task claiming and completion
  • Updates user availability status

REST API Design for User Queries

API Endpoint Structure

GET /api/users/search
Enter fullscreen mode Exit fullscreen mode

Query Parameters:

  • role: Required user role (e.g., "manager", "specialist")
  • attributes: JSON object with custom attribute filters
  • available: Boolean to filter only available users
  • limit: Maximum number of users to return

Request Examples

Basic Role-based Query:

GET /api/users/search?role=approver&available=true&limit=10
Enter fullscreen mode Exit fullscreen mode

Advanced Attribute Filtering:

GET /api/users/search?role=specialist&attributes={"department":"finance","skill_level":"senior","location":"europe"}&available=true
Enter fullscreen mode Exit fullscreen mode

Response Format

{
  "users": [
    {
      "id": "user123",
      "username": "john.doe",
      "email": "john.doe@company.com",
      "role": "manager",
      "attributes": {
        "department": "finance",
        "skill_level": "senior",
        "location": "europe",
        "workload": "medium"
      },
      "available": true,
      "last_active": "2025-08-17T08:30:00Z"
    }
  ],
  "total_count": 5,
  "query_time": "2025-08-17T10:30:00Z"
}
Enter fullscreen mode Exit fullscreen mode

Implementation Approaches

Approach 1: Pre-Task Service Call

Use a service task before the user task to fetch eligible users:

BPMN Process Flow:

  1. Service Task: "Fetch Eligible Users"
  2. User Task: "Process Request" (with dynamic assignment)

Service Task Configuration:












Enter fullscreen mode Exit fullscreen mode

User Task Assignment:






Enter fullscreen mode Exit fullscreen mode

Approach 2: Dynamic Group Creation

Transform user lists into logical groups for assignment:



     0, 
        'dynamic-group-' + string(now()), 
        'fallback-group')" />


Enter fullscreen mode Exit fullscreen mode

Advanced Filtering Logic

Complex Attribute Queries

Multi-criteria Filtering:

// REST API call with complex filtering
const queryParams = {
  role: "analyst",
  attributes: JSON.stringify({
    department: ["finance", "accounting"],
    certification: "cpa",
    experience_years: { min: 3, max: 10 },
    languages: { includes: ["english", "spanish"] }
  }),
  available: true,
  workload: { max: "high" }
};
Enter fullscreen mode Exit fullscreen mode

Geographic and Time-based Filtering:

const locationBasedQuery = {
  role: "support_specialist",
  attributes: JSON.stringify({
    timezone: "GMT+1",
    shift: "day",
    location: { radius: 50, center: "london" }
  }),
  available_during: {
    start: "2025-08-17T09:00:00Z",
    end: "2025-08-17T17:00:00Z"
  }
};
Enter fullscreen mode Exit fullscreen mode

Error Handling and Fallbacks

Graceful Degradation Strategy







       0, 
        response.body.users, 
        [])" target="eligibleUsers" />







     0, 
        for user in eligibleUsers return user.username, 
        [])"
      candidateGroups="=if(count(eligibleUsers) = 0, 
        'default-processors', 
        null)" />


Enter fullscreen mode Exit fullscreen mode

Performance Optimization

Caching Strategy

// User query service with caching
class UserQueryService {
  constructor() {
    this.cache = new Map();
    this.cacheTimeout = 5 * 60 * 1000; // 5 minutes
  }

  async queryUsers(criteria) {
    const cacheKey = JSON.stringify(criteria);
    const cached = this.cache.get(cacheKey);

    if (cached && (Date.now() - cached.timestamp)  ({
      id: generateId(),
      criteria: query
    }))
  };

  const response = await fetch('/api/users/batch-search', {
    method: 'POST',
    body: JSON.stringify(batchRequest)
  });

  return response.json();
}
Enter fullscreen mode Exit fullscreen mode

Security Considerations

API Security Best Practices

// Secure API call configuration
const secureApiCall = {
  url: 'https://api.company.com/users/search',
  headers: {
    'Authorization': 'Bearer ${accessToken}',
    'X-API-Key': '${apiKey}',
    'Content-Type': 'application/json'
  },
  timeout: 30000,
  retry: {
    attempts: 3,
    backoff: 'exponential'
  }
};
Enter fullscreen mode Exit fullscreen mode

Data Privacy Protection

{
  "users": [
    {
      "id": "hashed_user_id",
      "username": "john.doe",
      "role": "manager",
      "attributes": {
        "department": "finance",
        "clearance_level": "confidential"
      }
    }
  ],
  "pii_excluded": true,
  "query_audit_id": "audit_12345"
}
Enter fullscreen mode Exit fullscreen mode

Monitoring and Analytics

Query Performance Tracking

// API call with performance monitoring
async function monitoredUserQuery(criteria) {
  const startTime = Date.now();
  const queryId = generateQueryId();

  try {
    const result = await queryUsers(criteria);

    logMetrics({
      queryId,
      criteria,
      resultCount: result.users.length,
      responseTime: Date.now() - startTime,
      status: 'success'
    });

    return result;
  } catch (error) {
    logMetrics({
      queryId,
      criteria,
      responseTime: Date.now() - startTime,
      status: 'error',
      error: error.message
    });
    throw error;
  }
}
Enter fullscreen mode Exit fullscreen mode

Complete Example: Finance Approval Process

Process Requirements

  • Route high-value transactions to senior managers
  • Consider geographic location for compliance
  • Load balance across available users
  • Fallback to regional managers if no specialists available

Implementation

Step 1: Define Query Logic

function buildApprovalQuery(transactionAmount, region, priority) {
  let role = "finance_specialist";
  let attributes = {
    region: region,
    approval_limit: { min: transactionAmount }
  };

  if (transactionAmount > 100000) {
    role = "senior_manager";
    attributes.clearance = "high_value";
  }

  if (priority === "urgent") {
    attributes.availability = "immediate";
  }

  return { role, attributes };
}
Enter fullscreen mode Exit fullscreen mode

Step 2: BPMN Process Configuration









         100000, 'senior_manager', 'finance_specialist'),
          'attributes': JSON.stringify({
            'region': transactionRegion,
            'approval_limit': { 'min': transactionAmount },
            'availability': if(priority = 'urgent', 'immediate', 'standard')
          }),
          'available': true,
          'limit': 5
        }" target="body" />












Enter fullscreen mode Exit fullscreen mode

Best Practices and Recommendations

API Design

  • Standardize response formats across all user query endpoints
  • Implement comprehensive filtering capabilities
  • Provide batch query options for performance
  • Include metadata (query time, total count, cache status)

Process Design

  • Always implement fallback mechanisms for failed API calls
  • Use caching strategically to reduce API load
  • Monitor query performance and optimize accordingly
  • Log all assignment decisions for audit purposes

Security and Compliance

  • Validate all API responses before using in assignments
  • Implement proper error handling for API failures
  • Audit all user queries for compliance requirements
  • Protect sensitive user attributes in transit and storage

Top comments (0)