Question about getting appointment slots and blocking slots already taken

Originally posted by Ralp Dexter Bongato\n\nHi, just to confirm, is there a way we could book an appointment through the API and also get the list of available slots we could book? Or is the right approach to use the Job allocation API? Our main concern about using the job allocation API is that it would allow customers to book the same staff, same day, and same time, is there a way we could limit this so it blocks out the slot if someone has already booked?

Thanks,
Ralp

Hi Ralp,

Great questions about appointment booking through the API! Let me clarify the correct approach based on your specific use case:

Choosing the Right Endpoint for Appointments

For fixed booking times (specific date/time appointments), you should use the JobActivity endpoint, not JobAllocations. JobAllocations is designed for queue-based bookings where there’s just an order with no fixed booking time.

Available Endpoints for Appointment Management

ServiceM8 provides several endpoints through the REST API:

  • /jobactivity - For fixed-time appointments with specific dates/times
    • /joballocation - For queue-based bookings (no fixed time)
      • /job - For creating and managing the underlying job records

Getting Available Slots

To get a list of available slots, you would typically:

  1. Query existing JobActivity records using filtering capabilities to check what’s already booked for specific staff members and date/time ranges
    2. Apply your business logic to determine which time slots are still available
    3. Cross-reference with staff working hours or availability windows if needed

Preventing Double-Booking - Critical Implementation Detail

Regarding your concern about preventing customers from booking the same staff at the same time - the API will not automatically block or restrict duplicate bookings, so you must implement this logic in your application.

Recommended Approach:

  1. Before offering any times to a customer, query JobActivity records to check existing bookings for that staff member and date using filtering: $filter=staff_uuid eq 'STAFF_UUID' and date eq 'DATE'
    2. Check for time conflicts in your application logic before presenting available slots to customers
    3. Only proceed with creating new JobActivity records if no conflicts exist
    4. Consider implementing atomic operations or database-level locking to prevent race conditions in high-concurrency scenarios

Required OAuth Scopes

Ensure your integration has appropriate OAuth scopes for the endpoints you’re using.

Key TakeawayThe critical point is that you must query JobActivity prior to offering any times to customers to ensure those slots aren’t already taken. The API won’t prevent duplicates automatically.Hope this clarifies the approach! Let me know if you need more details about any of these points.Thanks,
Cody

Thanks for the insights Cody, I’ll give this a try.

Kind regards,

Ralp