createScheduledTask method
Future<String>
createScheduledTask({
- required String projectId,
- required String roomName,
- required ScheduledTaskSpec spec,
POST /accounts/projects/{project_id}/rooms/{room_name}/scheduled-tasks Returns { "task_id" }
Implementation
Future<String> createScheduledTask({required String projectId, required String roomName, required ScheduledTaskSpec spec}) async {
final encodedProjectId = Uri.encodeComponent(projectId);
final encodedRoomName = Uri.encodeComponent(roomName);
final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/rooms/$encodedRoomName/scheduled-tasks');
final body = _CreateScheduledTaskRequest(spec: spec).toJson();
final resp = await httpClient.post(uri, body: jsonEncode(body));
if (resp.statusCode >= 400) {
// mirror your python client’s "ensure_success" style
throw MeshagentException('Failed to create scheduled task. Status code: ${resp.statusCode}, body: ${resp.body}');
}
final data = jsonDecode(resp.body) as Map<String, dynamic>;
final tid = data['task_id'];
if (tid is! String) {
throw MeshagentException('Invalid create scheduled task response: missing "task_id"');
}
return tid;
}