Creating a Task
Function
This API is used to create tasks.
URI
POST /v2/{project_id}/services/{service_name}/tasks
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID. For details, see Obtaining a Project ID and Name. |
service_name |
Yes |
String |
Service API name Minimum: 1 Maximum: 100 |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
User token. For details about how to obtain a user token, see Authentication. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
Yes |
String |
Task name. It can contain up to 100 characters and can include letters, digits, hyphens (-), and underscores (_). |
description |
No |
String |
Task description, which is optional. Enter a maximum of 500 characters. Minimum: 0 Maximum: 500 |
schedule |
No |
TaskSchedule object |
Task schedule. Only the weekly mode is supported. |
input |
Yes |
TaskInput object |
Input configuration of a task |
output |
Yes |
TaskOutput object |
Output configuration of a task |
config |
No |
TaskServiceConfig object |
Task configuration parameters |
service_version |
Yes |
String |
Service version. The value must match the regular expression ^[a-z0-9.]{3,32}$. Minimum: 3 Maximum: 32 |
is_saved_as_template |
No |
Boolean |
Whether to save as a template Default: false |
resource_order_id |
No |
String |
Resource order ID, which corresponds to the associated algorithm. This parameter is only mandatory for commercial algorithms and must match the regular expression ^[a-z0-9-_]{4,36}$. Minimum: 4 Maximum: 36 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
type |
Yes |
String |
Type of a scheduled task. This parameter is mandatory for scheduled tasks. The value can be weekly, indicating that the task is executed every week. |
timezone |
Yes |
String |
Time zone where a user is located. This parameter is mandatory for scheduled tasks. The value is accurate to the minute. |
days_of_week |
No |
Array of integers |
Days in a week when a task is executed. This parameter is mandatory only for weekly tasks. The values 1 to 7 indicate Monday to Sunday respectively. Minimum: 1 Maximum: 7 Array Length: 1 - 7 |
days_of_month |
No |
Array of integers |
Days in a month when a task is executed. This parameter is mandatory only for monthly tasks. The values 1 to 31 indicate the first day to the 31st day of a month. Currently, the system does not support this parameter. Minimum: 1 Maximum: 31 |
periods |
No |
Array<Array<>> |
Time segment configuration. Select at least one time segment for executing a weekly or monthly task. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
type |
Yes |
String |
Task input type, which is mandatory when you create a task. The video_source type cannot be changed to other types. The following types are supported: obs (files stored in OBS, supported only by cloud tasks), url (specified file URL or stream request URL, supported only by cloud tasks), edgecamera (edge camera bound to IEF, supported only by edge tasks), restful (stream request URL obtained from a user-specified streaming server through a RESTful API, supported by both cloud and edge jobs) vcn (VCN device, supported only by edge tasks), and video_source (video sources managed in VIAS, supported by both cloud and edge tasks). You are advised to use the video_source type. Other types will be discontinued in the future. The outputs of tasks whose input type is obs, url, edgecamera, or restful can be sent to webhook. Options:
|
data |
Yes |
Array of TaskInputData objects |
Input details of a task, which is mandatory. The configuration varies depending on the input type. Multiple inputs are allowed during creation, but only one input is allowed for update. If the input type is obs, you must configure bucket, path, and index. Example: bucket: aicam, path: 3rdpartylicenses.txt, index: 0 If the input type is url, you must configure url and index. Example: url: https://xxx-xxx.com, index: 0 If the input type is restful, you must configure certificate_check, rtsp_path_in_response, url, index, and headers. Example: certificate_check: true, url: https://hsaij-dasahbi.com, rtsp_path_in_response: data/url, index: 0, headers: { AAA: AAA } If the input type is vcn, you must configure device_id, stream_type, and index. Example: device_id: 21356478954612546874#gdhjkiushdgdksjhslmhscjsckjhdbnk, stream_type: 1, index: 0 If the input type is EdgeCamera, you must configure id and index. Example: id: 007cdafc-6000-47ce-b0e3-870b4a0db65e, index: 0. Array Length: 1 - 50 |
vcn |
No |
TaskInputVcn object |
VCN server. This parameter is mandatory only when the input type is vcn. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
video_source_id |
No |
String |
Video source ID. This parameter is mandatory when the input type is video_source. |
stream_name |
No |
String |
Name of a video stream |
bucket |
No |
String |
OBS bucket name. This parameter is mandatory when the input type is obs. Maximum: 64 |
path |
No |
String |
OBS path. This parameter is mandatory when the input type is obs. Maximum: 1023 |
url |
No |
String |
File URL or RESTful request URL for obtaining a video stream. This parameter is mandatory when the input type is url or edgerestful. The value contains a maximum of 1000 characters. Maximum: 1000 |
headers |
No |
Object |
Headers carried in the RESTful request for obtaining a video stream. This parameter is optional when the input type is edgerestful. The value is key-value pairs in JSON format. A maximum of 10 key-value pairs are allowed. |
rtsp_path_in_response |
No |
String |
Video stream address in the response body for the RESTful request. This parameter is mandatory when the input type is edgerestful. The value contains a maximum of 1024 characters. Maximum: 1024 |
device_id |
No |
String |
VCN ID. This parameter is mandatory when the input type is vcn. |
stream_type |
No |
Integer |
Stream type used for analysis. This parameter is mandatory when the input type is vcn. The value ranges from 1 to 3. The value 1 indicates primary stream, the value 2 indicates secondary stream 1, and the value 3 indicates secondary stream 2. Minimum: 1 Maximum: 3 |
id |
No |
String |
ID of the edge device mounted to IEF. This parameter is mandatory when the input type is edgecamera. Maximum: 63 |
certificate_check |
No |
Boolean |
Whether to verify the certificate of the HTTPS request. This parameter is mandatory when the input type is edgerestful. The value can be true or false. Default: false |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
ip |
Yes |
String |
IP address of a VCN server. This parameter is mandatory only when the input type is vcn. |
port |
Yes |
Integer |
Port number of a VCN server. This parameter is mandatory only when the input type is vcn. Minimum: 0 Maximum: 65535 |
username |
Yes |
String |
Account name of a VCN server. This parameter is mandatory only when the input type is vcn. The value must match the regular expression ^.{1,100}$. |
password |
Yes |
String |
Password of a VCN server account. This parameter is mandatory only when the input type is vcn. The value must match the regular expression ^.{1,1000}$. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
obs |
No |
TaskOutputObs object |
Configuration information when the output type is obs. |
dis |
No |
TaskOutputDis object |
Configuration information when the output type is dis. |
webhook |
No |
TaskOutputWebhook object |
Configuration information when the output type is webhook. |
event_center |
No |
Boolean |
Whether to set the output mode to Event Center. true or 1 indicates yes. false indicates no. Default: false |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
bucket |
Yes |
String |
OBS bucket name. This parameter is mandatory when the OBS output type is used. The verification rule is (pattern: " ^[a-z0-9](?!.[-.][-.].)([a-z0-9-.]{1,61})[a-z0-9]$ "). Maximum: 63 |
path |
Yes |
String |
OBS path. This parameter is mandatory when the OBS output type is used. The verification rule is ^(?![/.\s])(?!.//.)([^:*?"<>|\]{0,1023})(?<![.\s])$. Maximum: 1023 |
data_category |
No |
Array of strings |
List of task output types. This parameter is optional and is required only for some services. The output contains data in the dataCategory list. Array Length: 0 - 10 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
stream_name |
Yes |
String |
Name of a DIS stream. This parameter is mandatory when the DIS output type is used. The verification rule is ^[-A-Za-z0-9_]{1,64}$. Maximum: 64 |
data_category |
No |
Array of strings |
List of task output types. This parameter is optional and is required only for some services. The output contains data in the dataCategory list. For example, in the API for creating edge face-related tasks, the output contains dataCategory, with a value range of [FaceImage, OriginImage], indicating whether to send the face image or original image. Array Length: 0 - 10 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
url |
Yes |
String |
Result callback address. This parameter is mandatory when the output type is webhook. Maximum: 1000 |
headers |
Yes |
Object |
Headers carried in result callback. This parameter is mandatory when the output type is webhook. The value is key-value pairs in JSON format. A maximum of 10 key-value pairs are allowed, and a minimum of 1 key-value pair is allowed. |
data_category |
No |
Array of strings |
List of task output types. This parameter is optional and is required only for some services. The output contains data in the dataCategory list. Array Length: 0 - 10 |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
id |
String |
ID of a created task |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code |
error_msg |
String |
Error description |
detail |
String |
Error details |
params |
Array of strings |
Error parameters Array Length: 0 - 1 |
reason |
String |
Error cause |
advice |
String |
Suggestion |
Status code: 500
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code |
error_msg |
String |
Error description |
detail |
String |
Error details |
params |
Array of strings |
Error parameters Array Length: 0 - 1 |
reason |
String |
Error cause |
advice |
String |
Suggestion |
Example Requests
-
This request is used to create a task whose input type is video_source and output type is webhook. The algorithm service version is 1.1. No task startup parameters are configured. The configuration is not saved as a template.
/v2/{project_id}/services/{service_name}/tasks { "name" : "Test", "input" : { "type" : "video_source", "data" : [ { "video_source_id" : "xxxxxxx-xxxxxxx-xxxxxxx-xxxxx-xxxxxx" } ] }, "output" : { "webhook" : { "url" : "http://test", "headers" : { "a" : "a" } } }, "config" : { "common" : { } }, "service_version" : "1.1", "is_saved_as_template" : false }
-
This request body is used to adapt old IVA APIs.
/v2/{project_id}/services/{service_name}/tasks { "name" : "test-alg-819", "input" : { "type" : "url", "data" : [ { "url" : "https://iuwhediue-input.com", "index" : 0 } ] }, "output" : { "webhook" : { "url" : "https://iuwhediue-output.com", "headers" : { "AA" : "AA" } } }, "config" : { "common" : { "viewpoint" : 1 } }, "service_version" : "3.0", "is_saved_as_template" : false, "resource_order_id" : "029b34a69efd48769215e429deff0cec" }
-
This request creates a scheduled task. If the end time of one day is 23:59:00 and the start time of the next day is 00:00:00, the task does not stop until it is completed.
/v2/{project_id}/services/{service_name}/tasks { "name" : "test-alg-819", "schedule" : { "type" : "weekly", "timezone" : "+08:00", "days_of_week" : [ 1, 2, 3, 4, 5, 6, 7 ], "periods" : [ [ ], [ ], [ ], [ ], [ { "begin_at" : "22:15:00", "end_at" : "23:59:00" } ], [ { "begin_at" : "00:00:00", "end_at" : "23:59:00" } ], [ { "begin_at" : "22:15:00", "end_at" : "23:59:00" } ] ] }, "input" : { "type" : "url", "data" : [ { "url" : "https://iuwhediue-input.com", "index" : 0 } ] }, "output" : { "webhook" : { "url" : "https://iuwhediue-output.com", "headers" : { "AA" : "AA" } } }, "config" : { "common" : { "viewpoint" : 1 } }, "service_version" : "3.0", "is_saved_as_template" : false, "resource_order_id" : "029b34a69efd48769215e429deff0cec" }
Example Responses
Status code: 200
Operation successful
{ "tasks" : [ { "id" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } ] }
Status Codes
Status Code |
Description |
---|---|
200 |
Operation successful |
400 |
Request error |
500 |
Internal error |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot