---
updatedAt: 2026-05-27T10:18:53.000Z
agentTools:
  projectIndex: https://gethapn.readme.io/llms.txt
---

# Create new task schedule

Creates a new task schedule.

A task schedule is the base set of rules that generates device tasks.
A task schedule determines whether a task needs to be created and the criteria a task needs to follow to know when is due.

For repeating usage-based schedules, every device carries the starting value matching the
schedule's repeat type: startingActiveHours when the schedule repeats by intervalActiveHours,
startingOdometer when it repeats by intervalOdometer. Date-based and one-time schedules take
imei-only entries. Each device's first task is anchored to its own starting value.


# OpenAPI definition

```json
{
  "openapi": "3.0.3",
  "info": {
    "description": "The Hapn API is an HTTP interface for managing devices, accounts, and cloud data.",
    "version": "1.0.0",
    "title": "Hapn API",
    "termsOfService": "https://gethapn.com/terms",
    "contact": {
      "name": "Dev",
      "email": "developer@gethapn.com",
      "url": "http://gethapn.com"
    },
    "license": {
      "name": "Apache 2.0",
      "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
    }
  },
  "servers": [
    {
      "url": "https://api.iotgps.io/v1",
      "description": "Prod"
    },
    {
      "url": "https://api-dev.iotgps.io/v1",
      "description": "Dev"
    }
  ],
  "paths": {
    "/tasks/schedule": {
      "post": {
        "summary": "Create new task schedule",
        "tags": [
          "Tasks"
        ],
        "operationId": "post-taskSchedules",
        "description": "Creates a new task schedule.\n\nA task schedule is the base set of rules that generates device tasks.\nA task schedule determines whether a task needs to be created and the criteria a task needs to follow to know when is due.\n\nFor repeating usage-based schedules, every device carries the starting value matching the\nschedule's repeat type: startingActiveHours when the schedule repeats by intervalActiveHours,\nstartingOdometer when it repeats by intervalOdometer. Date-based and one-time schedules take\nimei-only entries. Each device's first task is anchored to its own starting value.\n",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTaskScheduleBody"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Task Schedule creation result",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "result": {
                          "$ref": "#/components/schemas/TaskSchedule"
                        }
                      }
                    }
                  ]
                },
                "examples": {
                  "example-1": {
                    "value": {
                      "success": true,
                      "message": "ok",
                      "result": {
                        "id": 1,
                        "clientId": 123,
                        "title": "Task Schedule 1",
                        "description": "Task Schedule 1 description",
                        "repeats": true,
                        "dueDate": "2022-01-02T17:44:02.000Z",
                        "dueOdometer": 1000,
                        "dueActiveHours": 100,
                        "intervalDays": 5,
                        "intervalStartDate": "2022-01-02T17:44:02.000Z",
                        "intervalOdometer": 1000,
                        "intervalStartingOdometer": 1000,
                        "intervalActiveHours": 100,
                        "intervalStartingActiveHours": 100,
                        "notes": "Task notes",
                        "createdBy": "user",
                        "createdAt": "2022-01-02T17:44:02.000Z",
                        "modifiedBy": "user",
                        "modifiedAt": "2022-01-02T17:44:02.000Z",
                        "deletedBy": "user",
                        "deletedAt": "2022-01-02T17:44:02.000Z",
                        "status": "active"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "500": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "SuccessResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          },
          "result": {
            "type": "object"
          }
        },
        "required": [
          "message",
          "success"
        ],
        "x-examples": {
          "example-1": {
            "value": {
              "success": true,
              "message": "ok",
              "result": {
                "imei": "12345"
              }
            }
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "success",
          "message"
        ],
        "x-examples": {
          "example-1": {
            "value": {
              "success": false,
              "message": "Unauthorized"
            }
          }
        }
      },
      "TaskSchedule": {
        "description": "A task schedule",
        "type": "object",
        "x-examples": {
          "example-1": {
            "id": 1,
            "clientId": 123,
            "title": "Task Schedule 1",
            "description": "Task Schedule 1 description",
            "repeats": true,
            "dueDate": "2022-01-02T17:44:02.000Z",
            "dueOdometer": 1000,
            "dueActiveHours": 100,
            "intervalDays": 5,
            "intervalStartDate": "2022-01-02T17:44:02.000Z",
            "intervalOdometer": 1000,
            "intervalStartingOdometer": 1000,
            "intervalActiveHours": 100,
            "intervalStartingActiveHours": 100,
            "notes": "Task notes",
            "createdBy": "user",
            "createdAt": "2022-01-02T17:44:02.000Z",
            "modifiedBy": "user",
            "modifiedAt": "2022-01-02T17:44:02.000Z",
            "deletedBy": "user",
            "deletedAt": "2022-01-02T17:44:02.000Z",
            "status": "active"
          }
        },
        "title": "Task Schedule",
        "properties": {
          "id": {
            "type": "number",
            "description": "The task schedule identifier"
          },
          "clientId": {
            "type": "number",
            "description": "The client identifier"
          },
          "title": {
            "type": "string",
            "description": "The task schedule title"
          },
          "description": {
            "type": "string",
            "description": "The task schedule description"
          },
          "repeats": {
            "type": "boolean",
            "description": "Determines if the task schedule repeats or not"
          },
          "dueDate": {
            "type": "string",
            "description": "Date the tasks in this schedule are due. Relevant when repeat is false"
          },
          "dueOdometer": {
            "type": "number",
            "description": "Odometer number (in km) that makes the tasks in the schedule due. Relevant when repeat is false"
          },
          "dueActiveHours": {
            "type": "number",
            "description": "Hours of operation that make the tasks in the schedule due. Relevant when repeat is false"
          },
          "intervalDays": {
            "type": "number",
            "description": "Tasks in the schedule repeats every interval days. Relevant when repeat is true"
          },
          "intervalStartDate": {
            "type": "string",
            "description": "Tasks interval starts at this startDate. Relevant when repeat is true"
          },
          "intervalOdometer": {
            "type": "number",
            "description": "Tasks in the schedule repeats every number of miles. Relevant when repeat is true"
          },
          "intervalStartingOdometer": {
            "type": "number",
            "description": "The task interval starts after this odometer has been reached (km). Relevant when repeat is true"
          },
          "intervalActiveHours": {
            "type": "number",
            "description": "The task interval repeats every active hours. Relevant when repeat is true"
          },
          "intervalStartingActiveHours": {
            "type": "number",
            "description": "the task interval starts after this number of active hours is reached. Relevant when repeat is true"
          },
          "notes": {
            "type": "string",
            "description": "The task schedule notes and instructions"
          },
          "createdBy": {
            "type": "string",
            "description": "The task schedule creator"
          },
          "createdAt": {
            "type": "string",
            "description": "The task schedule creation date"
          },
          "modifiedBy": {
            "type": "string",
            "description": "The task schedule last modifier"
          },
          "modifiedAt": {
            "type": "string",
            "description": "The task schedule modification date"
          },
          "deletedBy": {
            "type": "string",
            "description": "The task schedule deleter"
          },
          "deletedAt": {
            "type": "string",
            "description": "The task schedule deletion date"
          },
          "status": {
            "type": "string",
            "description": "The task schedule status",
            "enum": [
              "active",
              "deleted"
            ]
          },
          "devices": {
            "type": "array",
            "description": "The task schedule associated devices",
            "items": {
              "type": "string"
            }
          },
          "totalDevicesCount": {
            "type": "number",
            "description": "The task schedule total devices count"
          }
        },
        "required": [
          "id",
          "clientId",
          "title",
          "description"
        ]
      },
      "CreateTaskScheduleBody": {
        "description": "Parameters to create a task schedule",
        "type": "object",
        "x-examples": {
          "date-schedule": {
            "taskSchedule": {
              "title": "Monthly inspection",
              "description": "Visual inspection every 30 days",
              "repeats": true,
              "intervalDays": 30,
              "intervalStartDate": "2022-01-02T17:44:02.000Z",
              "notes": "Task notes"
            },
            "devices": [
              {
                "imei": "868239050345326"
              },
              {
                "imei": "868239050345327"
              }
            ]
          },
          "engine-hours-schedule": {
            "taskSchedule": {
              "title": "Oil change",
              "description": "Oil and filters every 250 engine hours",
              "repeats": true,
              "intervalActiveHours": 250
            },
            "devices": [
              {
                "imei": "868239050345326",
                "startingActiveHours": 1355
              },
              {
                "imei": "868239050345327",
                "startingActiveHours": 980
              }
            ]
          },
          "odometer-schedule": {
            "taskSchedule": {
              "title": "Tire rotation",
              "description": "Rotate tires every 10000 km",
              "repeats": true,
              "intervalOdometer": 10000
            },
            "devices": [
              {
                "imei": "868239050345326",
                "startingOdometer": 48631
              },
              {
                "imei": "868239050345327",
                "startingOdometer": 5088
              }
            ]
          }
        },
        "title": "Create task schedule body",
        "properties": {
          "taskSchedule": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string",
                "description": "The task schedule title"
              },
              "description": {
                "type": "string",
                "description": "The task schedule description"
              },
              "repeats": {
                "type": "boolean",
                "description": "Determines if the task schedule repeats or not"
              },
              "dueDate": {
                "type": "string",
                "description": "Date the tasks in this schedule are due. Relevant when repeat is false"
              },
              "dueOdometer": {
                "type": "number",
                "description": "Odometer number (in km) that makes the tasks in the schedule due. Relevant when repeat is false"
              },
              "dueActiveHours": {
                "type": "number",
                "description": "Hours of operation that make the tasks in the schedule due. Relevant when repeat is false"
              },
              "intervalDays": {
                "type": "number",
                "description": "Tasks in the schedule repeats every interval days. Relevant when repeat is true"
              },
              "intervalStartDate": {
                "type": "string",
                "description": "Tasks interval starts at this startDate. Relevant when repeat is true"
              },
              "intervalOdometer": {
                "type": "number",
                "description": "Tasks in the schedule repeats every number of miles. Relevant when repeat is true"
              },
              "intervalStartingOdometer": {
                "type": "number",
                "description": "The task interval starts after this odometer has been reached (km). Relevant when repeat is true"
              },
              "intervalActiveHours": {
                "type": "number",
                "description": "The task interval repeats every active hours. Relevant when repeat is true"
              },
              "intervalStartingActiveHours": {
                "type": "number",
                "description": "the task interval starts after this number of active hours is reached. Relevant when repeat is true"
              },
              "notes": {
                "type": "string",
                "description": "The task schedule notes and instructions"
              }
            }
          },
          "devices": {
            "type": "array",
            "description": "The devices to associate with the task schedule, each with per-device starting\nvalues for repeating usage-based schedules. The starting value matching the\nschedule's repeat type is required for every device: startingActiveHours when the\nschedule repeats by intervalActiveHours, startingOdometer when it repeats by\nintervalOdometer. Date-based and one-time schedules take neither. A per-device\nstarting value takes precedence over the schedule-level intervalStartingOdometer /\nintervalStartingActiveHours for that device's first task. On updates, omitting the\nfield keeps the device's stored value; an explicit null clears it.\n",
            "items": {
              "$ref": "#/components/schemas/TaskScheduleDeviceInput"
            }
          }
        }
      },
      "TaskScheduleDeviceInput": {
        "description": "A device to associate with a task schedule. Provide the starting value matching the schedule's repeat type for every device",
        "title": "Task schedule device input",
        "type": "object",
        "required": [
          "imei"
        ],
        "properties": {
          "imei": {
            "type": "string",
            "description": "The device imei"
          },
          "startingOdometer": {
            "type": "number",
            "nullable": true,
            "description": "Per-device odometer reading (in km) the repeating interval starts from. Required for every device when the schedule repeats by intervalOdometer. Overrides intervalStartingOdometer for this device. On updates, omit to keep the stored value; null clears it"
          },
          "startingActiveHours": {
            "type": "number",
            "nullable": true,
            "description": "Per-device hours of operation the repeating interval starts from. Required for every device when the schedule repeats by intervalActiveHours. Overrides intervalStartingActiveHours for this device. On updates, omit to keep the stored value; null clears it"
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Unauthorized",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "example-1": {
                "value": {
                  "success": false,
                  "message": "Unauthorized"
                }
              }
            }
          }
        }
      },
      "Error": {
        "description": "Server error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "example-1": {
                "value": {
                  "success": false,
                  "message": "Error"
                }
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "OAuth2": {
        "type": "oauth2",
        "flows": {
          "clientCredentials": {
            "tokenUrl": "https://auth.usehapn.com/oauth2/token",
            "scopes": {}
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Tasks",
      "description": "Maintenance tasks"
    }
  ],
  "security": [
    {
      "OAuth2": []
    }
  ]
}
```