---
title: "Create a job"
method: POST
path: "/api/jobs"
tags: ["Jobs"]
---

# Create a job

`POST /api/jobs`

Create a job and schedule its execution. Jobs are processed asynchronously, meaning that once a job is created, it will run in background on Gorgias's servers. According to the type and size of the task, a job can take a few minutes or several hours to be executed. You can use our API to check the status of the job.

## Request body

- object
  - `meta` object, nullable — Metadata associated with the job. You can use this parameter to store structured information (key-value data) about the job. This field is not used by Gorgias.
  - `params` object, required — The parameters of the job.
    - `apply_and_close` boolean — Whether the ticket should be closed once the macro is applied on it. Only applies to `applyMacro` jobs.
    - `end_datetime` string, nullable — End of the interval from which to select tickets when the parameter `view` is used.
    - `macro_id` integer — The ID of the macro to apply on the selected tickets. Only applies to `applyMacro` jobs.
    - `start_datetime` string, nullable — Beginning of the interval from which to select tickets when the parameter `view` is used.
    - `ticket_ids` integer[] — A list of ticket IDs to be processed by the job.
    - `url` string — The path to the file to import.
    - `updates` object — Object (key-value) containing all the changes to apply on the selected tickets. Only applies to `updateTicket` jobs.
    - `view` object — A [view](#the-view-object)-like object used to select the tickets to be processed by the job.
    - `view_id` integer — The ID of an existing [view](#the-view-object) used to select the tickets to be processed by the job.
    - `context` object — Object (key-value) containing extra context for the job
  - `scheduled_datetime` string, date-time, nullable — When the job was scheduled to be started. A job cannot be scheduled more than 60 minutes in the future. If unspecified, the job is queued for execution immediately after creation.
  - `type` 'applyMacro' | 'deleteTicket' | 'exportTicket' | 'importMacro' | 'exportMacro' | 'updateTicket' | 'exportTicketDrilldown' | 'exportConvertCampaignSalesDrilldown', required — The type of the job. Options: applyMacro, deleteTicket, exportTicket, importMacro, exportMacro, updateTicket, exportTicketDrilldown, exportConvertCampaignSalesDrilldown

## Response `201`

The created job.

- Job — A job is an object used to perform long-running tasks. For example, closing 10k tickets, exporting 500k tickets, and more. Jobs are processed asynchronously, meaning that once a job is created, it will run in background on Gorgias's servers. According to the type and size of the task, a job can take a few minutes or several hours to be executed. You can use our API to check the status of the job. Jobs can be canceled at any time but be aware that if a job already started, changes done by this one won't be reverted. For example, if you created a job to close 10k tickets and you cancel it at some point, the already closed tickets won't be reopened.
  - `id` integer — ID of the job.
  - `cancel_requested_datetime` string, date-time, nullable — When the job cancellation was requested.
  - `cancelled_datetime` string, date-time, nullable — When the job was canceled.
  - `created_datetime` string, date-time, nullable — When the job was created.
  - `ended_datetime` string, date-time, nullable — When the job ended.
  - `failed_datetime` string, date-time, nullable — When the job failed.
  - `info` object — Data concerning the progress of the job. E.g: how many objects the job has already processed.
  - `locked_datetime` string, date-time, nullable — When the job was locked. A job is only locked while it's actively running.
  - `meta` object, nullable — Metadata associated with the job. You can use this parameter to store structured information (key-value data) about the job. This field is not used by Gorgias.
  - `params` object — The parameters of the job.
    - `apply_and_close` boolean — Whether the ticket should be closed once the macro is applied on it. Only applies to `applyMacro` jobs.
    - `end_datetime` string, nullable — End of the interval from which to select tickets when the parameter `view` is used.
    - `macro_id` integer — The ID of the macro to apply on the selected tickets. Only applies to `applyMacro` jobs.
    - `start_datetime` string, nullable — Beginning of the interval from which to select tickets when the parameter `view` is used.
    - `ticket_ids` integer[] — A list of ticket IDs to be processed by the job.
    - `url` string — The path to the file to import.
    - `updates` object — Object (key-value) containing all the changes to apply on the selected tickets. Only applies to `updateTicket` jobs.
    - `view` object — A [view](#the-view-object)-like object used to select the tickets to be processed by the job.
    - `view_id` integer — The ID of an existing [view](#the-view-object) used to select the tickets to be processed by the job.
    - `context` object — Object (key-value) containing extra context for the job
  - `scheduled_datetime` string, date-time, nullable — When the job was scheduled to be started. A job cannot be scheduled more than 60 minutes in the future. If unspecified, the job is queued for execution immediately after creation.
  - `started_datetime` string, date-time, nullable — When the job started.
  - `status` 'cancel_requested' | 'canceled' | 'done' | 'errored' | 'fatal_errored' | 'pending' | 'running' | 'scheduled' — The status of the job. Options: cancel_requested, canceled, done, errored, fatal_errored, pending, running, scheduled
  - `type` 'applyMacro' | 'deleteTicket' | 'exportTicket' | 'importMacro' | 'exportMacro' | 'updateTicket' | 'exportTicketDrilldown' | 'exportConvertCampaignSalesDrilldown' — The type of the job. Options: applyMacro, deleteTicket, exportTicket, importMacro, exportMacro, updateTicket, exportTicketDrilldown, exportConvertCampaignSalesDrilldown
  - `user_id` integer — The ID of the user who created this job.
  - `uri` string — URI of the job.

---

[API](https://skmtc.net/gorgias/apis/gorgias-rest-api.md) · [All operations](https://skmtc.net/gorgias/apis/gorgias-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/gorgias/gorgias-rest-api/versions/36f2e31f4e81/schema)
