import os
from cognite.client.data_classes import ClientCredentials
schedule = client.functions.schedules.create(
name="My schedule",
function_id=123,
cron_expression="*/5 * * * *",
client_credentials=ClientCredentials("my-client-id", os.environ["MY_CLIENT_SECRET"]),
description="This schedule does magic stuff.",
data={"magic": "stuff"},
)
schedule = client.functions.schedules.create(
name="My schedule",
function_id=456,
cron_expression="*/5 * * * *",
description="A schedule just used for some temporary testing.",
)curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"name": "My schedule",
"cronExpression": "* * * * *",
"functionId": 4503599627370496,
"nonce": "<string>",
"description": "This is a nice schedule",
"data": {
"timeSeriesId1": 13435351,
"maxValue": 4
}
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
items: [
{
name: 'My schedule',
cronExpression: '* * * * *',
functionId: 4503599627370496,
nonce: '<string>',
description: 'This is a nice schedule',
data: {timeSeriesId1: 13435351, maxValue: 4}
}
]
})
};
fetch('https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'items' => [
[
'name' => 'My schedule',
'cronExpression' => '* * * * *',
'functionId' => 4503599627370496,
'nonce' => '<string>',
'description' => 'This is a nice schedule',
'data' => [
'timeSeriesId1' => 13435351,
'maxValue' => 4
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules"
payload := strings.NewReader("{\n \"items\": [\n {\n \"name\": \"My schedule\",\n \"cronExpression\": \"* * * * *\",\n \"functionId\": 4503599627370496,\n \"nonce\": \"<string>\",\n \"description\": \"This is a nice schedule\",\n \"data\": {\n \"timeSeriesId1\": 13435351,\n \"maxValue\": 4\n }\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\n \"name\": \"My schedule\",\n \"cronExpression\": \"* * * * *\",\n \"functionId\": 4503599627370496,\n \"nonce\": \"<string>\",\n \"description\": \"This is a nice schedule\",\n \"data\": {\n \"timeSeriesId1\": 13435351,\n \"maxValue\": 4\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"items\": [\n {\n \"name\": \"My schedule\",\n \"cronExpression\": \"* * * * *\",\n \"functionId\": 4503599627370496,\n \"nonce\": \"<string>\",\n \"description\": \"This is a nice schedule\",\n \"data\": {\n \"timeSeriesId1\": 13435351,\n \"maxValue\": 4\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"id": 4503599627370496,
"name": "My schedule",
"createdTime": 1730204346000,
"cronExpression": "* * * * *",
"when": "Every hour",
"functionId": 4503599627370496,
"sessionId": "<string>",
"description": "This is a nice schedule"
}
]
}{
"error": {
"code": 401,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}Required capabilities:
functionsAcl:WRITE
Create function schedules. Function schedules trigger asynchronous calls with specific input data, based on a cron expression that determines when these triggers should be fired. Use e.g. http://www.cronmaker.com to be guided on how to generate a cron expression. One of FunctionId or FunctionExternalId (deprecated) must be set (but not both). When creating a schedule with a session, i.e. with a nonce, FunctionId must be used. The nonce will be used to bind the session before function execution, and the session will be kept alive for the lifetime of the schedule. WARNING: Secrets or other confidential information should not be passed via the data object. There is a dedicated secrets object in the request body to “Create functions” for this purpose.
import os
from cognite.client.data_classes import ClientCredentials
schedule = client.functions.schedules.create(
name="My schedule",
function_id=123,
cron_expression="*/5 * * * *",
client_credentials=ClientCredentials("my-client-id", os.environ["MY_CLIENT_SECRET"]),
description="This schedule does magic stuff.",
data={"magic": "stuff"},
)
schedule = client.functions.schedules.create(
name="My schedule",
function_id=456,
cron_expression="*/5 * * * *",
description="A schedule just used for some temporary testing.",
)curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"name": "My schedule",
"cronExpression": "* * * * *",
"functionId": 4503599627370496,
"nonce": "<string>",
"description": "This is a nice schedule",
"data": {
"timeSeriesId1": 13435351,
"maxValue": 4
}
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
items: [
{
name: 'My schedule',
cronExpression: '* * * * *',
functionId: 4503599627370496,
nonce: '<string>',
description: 'This is a nice schedule',
data: {timeSeriesId1: 13435351, maxValue: 4}
}
]
})
};
fetch('https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'items' => [
[
'name' => 'My schedule',
'cronExpression' => '* * * * *',
'functionId' => 4503599627370496,
'nonce' => '<string>',
'description' => 'This is a nice schedule',
'data' => [
'timeSeriesId1' => 13435351,
'maxValue' => 4
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules"
payload := strings.NewReader("{\n \"items\": [\n {\n \"name\": \"My schedule\",\n \"cronExpression\": \"* * * * *\",\n \"functionId\": 4503599627370496,\n \"nonce\": \"<string>\",\n \"description\": \"This is a nice schedule\",\n \"data\": {\n \"timeSeriesId1\": 13435351,\n \"maxValue\": 4\n }\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\n \"name\": \"My schedule\",\n \"cronExpression\": \"* * * * *\",\n \"functionId\": 4503599627370496,\n \"nonce\": \"<string>\",\n \"description\": \"This is a nice schedule\",\n \"data\": {\n \"timeSeriesId1\": 13435351,\n \"maxValue\": 4\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/functions/schedules")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"items\": [\n {\n \"name\": \"My schedule\",\n \"cronExpression\": \"* * * * *\",\n \"functionId\": 4503599627370496,\n \"nonce\": \"<string>\",\n \"description\": \"This is a nice schedule\",\n \"data\": {\n \"timeSeriesId1\": 13435351,\n \"maxValue\": 4\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"id": 4503599627370496,
"name": "My schedule",
"createdTime": 1730204346000,
"cronExpression": "* * * * *",
"when": "Every hour",
"functionId": 4503599627370496,
"sessionId": "<string>",
"description": "This is a nice schedule"
}
]
}{
"error": {
"code": 401,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}Authorizations
Access token issued by the CDF project's configured identity provider. Access token must be an OpenID Connect token, and the project must be configured to accept OpenID Connect tokens. Use a header key of 'Authorization' with a value of 'Bearer $accesstoken'. The token can be obtained through any flow supported by the identity provider.
Body
1 elementShow child attributes
Show child attributes
Response
Created
Show child attributes
Show child attributes
Was this page helpful?