Creates a new task.
All fields in the task
object are optional. If you don't pass any fields in the task
object, the function returns a task with the following core properties:
_id
_createdDate
_updatedDate
status
source
revision
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function createTask(task: Task): Promise<Task>;
Task to create.
import { tasks } from "wix-crm.v2";
/* Sample task value:
* {
* contact: {
* _id: '5518ee7f-270e-40c4-b756-dad56e8f0ffc'
* },
* description: 'Send a follow up email',
* dueDate: new Date(2024, 1, 31),
* status: 'ACTION_NEEDED',
* title: 'Follow up'
* }
*/
export async function myCreateTaskFunction(task) {
try {
const newTask = await tasks.createTask(task);
console.log("Successfully created a new task:", newTask);
return newTask;
} catch (error) {
console.log(error);
// Handle the error
}
}
/* Promise resolves to:
* {
* "revision": "1",
* "title": "Follow up",
* "description": "Send a follow up email",
* "dueDate": "2024-01-31T00:00:00.000Z",
* "status": "ACTION_NEEDED",
* "source": {
* "sourceType": "APP",
* "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
* },
* "contact": {
* "firstName": "Sally",
* "lastName": "Smith",
* "email": "sally.smith@example.com",
* "phone": "+1 524-624-2486",
* "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc"
* },
* "_id": "37c2c378-8085-4ef7-8a3e-6f341248e757",
* "_createdDate": "2024-01-18T12:16:37.452Z",
* "_updatedDate": "2024-01-18T12:16:37.452Z"
* }
*/
There is 1 error with this status code.
This method may also return standard errors. Learn more about standard Wix errors.