Skip to content

Ticket Crons — API

Cron endpoints for automated ticket lifecycle management. All endpoints are triggered by the cron scheduler and require token_cron authentication.

Endpoints

MethodPathHandlerAuthDescription
GET/notify/tickets/follow-up-incompletenotifyFollowUpAndIncompleteTicketstoken_cronSend reminders for incomplete tickets and Slack alerts for follow-up tickets
GET/notify/tickets/autoclosenotifyAutocloseTicketstoken_cronAuto-accept tickets whose shipment was delivered
GET/notify/tickets/incompletecloseTicketsIncompletetoken_cronAuto-decline incomplete claim tickets after 10 days

Route Definitions

All routes are defined in backend/routes/crons.routes.js and use the CronController from backend/controllers/crons.controller.js.

GET /notify/tickets/follow-up-incomplete

Sends multi-channel reminders to clients with incomplete tickets and Slack SLA alerts for follow-up tickets.

Request: No payload or query parameters.

Response:

json
{
  "success": true
}

Processing: Runs asynchronously via setImmediate. The HTTP response is returned immediately.

Side effects:

  • Sends reminder emails to ticket creators
  • Sends platform notifications
  • Inserts admin comments on incomplete tickets
  • Sends WhatsApp notifications for incomplete tickets
  • Sends Slack messages to #alert-cs-tickets for follow-up tickets
  • Updates ticket timestamps and inserts history records

GET /notify/tickets/autoclose

Automatically accepts tickets whose associated shipment has been delivered, then sends CSAT surveys.

Request: No payload or query parameters.

Response:

json
{
  "data": true
}

Processing: Runs asynchronously via setImmediate.

Ticket types affected:

  • Shipment Created Without Changes (12)
  • Delay (8)
  • Redirection (14)
  • Delivery Attempt (25)

Shipment statuses that trigger autoclose:

  • Delivered
  • Delivered at Origin

Side effects:

  • Updates ticket status to ACCEPTED (2)
  • Inserts translated "delivered" comment
  • Inserts ticket history record
  • Sends CSAT: in-platform rating, email, and WhatsApp

GET /notify/tickets/incomplete

Automatically declines claim tickets that have been incomplete for more than 10 days, then sends CSAT surveys.

Request: No payload or query parameters.

Response:

json
{
  "success": true
}

Processing: Runs asynchronously via setImmediate.

Ticket types affected (claim types only):

  • Lost (4)
  • Theft (13)
  • Damaged (5)
  • Overweight (3)
  • Irregular Package (21)

Exclusions:

  • India locale (locale_id = 11) is excluded from the query
  • India locale is also excluded from CSAT notifications

Side effects:

  • Bulk updates ticket status to DECLINED (3)
  • Batch inserts history records
  • Inserts personalized close comment per ticket
  • Sends CSAT: in-platform rating, email, and WhatsApp

Error Handling

All three crons follow the same error handling pattern:

  1. Outer try/catch: Catches errors during route setup. Returns Boom.badRequest or Boom.badData.
  2. Inner try/catch (inside setImmediate): Catches errors during async processing. Reports to observability.captureError (Datadog).
  3. Per-notification catch: Individual notification failures are caught independently so one failure doesn't block others.

Authentication

All cron routes use auth: 'token_cron', a bearer token strategy specifically for scheduled job triggers. This token is separate from admin and client authentication tokens.

Source Files

FilePurpose
backend/routes/crons.routes.jsRoute definitions for all cron endpoints
backend/controllers/crons.controller.jsController with cron handler methods
backend/libraries/ticketsV2.util.jsNotification logic, message generation, CSAT pipeline
backend/libraries/companies.util.jsTicket comments, rating notifications
backend/constants/tickets.contstants.jsTicket type and status constants
backend/libraries/translate.util.jsTranslation/i18n utilities

Envia Admin