Indexes, videos, and tasks
The GET
methods of the /indexes
, /indexes/videos
, and /tasks
endpoints support filtering.
To filter the results of a query, specify one or more conditions after the endpoint in the URL of the call. Use a ?
symbol to separate the endpoint and the conditions. If you add multiple conditions, you must separate them using the &
symbol. Each condition follows the field=value
format and the platform returns results where the fields equal the specified values.
For example, if you want to filter all the video indexing tasks created on a specific date and whose status is pending, you must specify both the created_at
and status
fields, as shown in this example: created_at=2022-05-17&status=pending
.
The examples in this section are specific to using the /tasks
endpoint. However, the principles demonstrated are similar when using the /indexes
and /indexes/videos
endpoints.
You can interact with the platform using one of the available SDKs or an HTTP client like requests
or axios
. This guide demonstrates how to use the SDKs, the recommended approach for most scenarios. If you need to make direct HTTP requests, refer to the corresponding pages in API Reference section for details
Note
Depending on the endpoint, you can filter on various fields. For details, see the API Reference section.
Prerequisites
- You're familiar with the concepts that are described on the Platform overview page.
- You've already created an index and uploaded at least one video to it.
Examples
Filter on a specific date
The following example code uses the created_at
parameter to return all the tasks created on a specific date:
from twelvelabs import TwelveLabs
client = TwelveLabs(api_key="<YOUR_API_KEY>")
tasks = client.task.list_pagination(
created_at="2022-05-17"
)
# Utility function to print a specific page
def print_page(page):
for task in page:
print(f"id={task.id} status={task.status} created_at={task.created_at}")
print_page(tasks.data)
while True:
try:
print_page(next(tasks))
except StopIteration:
break
import { TwelveLabs, Task } from 'twelvelabs-js';
const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>'});
const tasks = await client.task.listPagination({ createdAt: '2022-05-17' });
tasks.data.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status}`);
});
while (true) {
const nextPageData = await tasks.next();
if (!nextPageData) {
break;
}
nextPageData.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status} created_at=${task.createdAt}`);
});
}
The following example output was truncated for brevity:
id=6283ab5ef18e21febd160bc3 status=ready created_at=2022-05-17T14:04:14.001Z
id=6283a0a8f18e21febd160bbf status=ready created_at=2022-05-17T13:18:32.388Z
id=6283a00df18e21febd160bbc status=ready created_at=2022-05-17T13:15:57.053Z
Filter based on a file name
To filter based on a file name, use the filename
parameter as shown in the example below:
from twelvelabs import TwelveLabs
client = TwelveLabs(api_key="<YOUR_API_KEY>")
tasks = client.task.list_pagination(
filename="<YOUR_FILENAME>" # Example: filename="01.mp4"
)
# Utility function to print a specific page
def print_page(page):
for task in page:
print(f"id={task.id} status={task.status} created_at={task.created_at} metadata={task.metadata}")
print_page(tasks.data)
while True:
try:
print_page(next(tasks))
except StopIteration:
break
import { TwelveLabs, Task } from 'twelvelabs-js';
const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>'});
const tasks = await client.task.listPagination({ filename: '<YOUR_FILE_NAME>' }); // Example: filename="01.mp4"
tasks.data.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status} metadata=${task.metadata}`);
});
while (true) {
const nextPageData = await tasks.next();
if (!nextPageData) {
break;
}
nextPageData.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status} created_at=${task.createdAt} metadata=${task.metadata}`);
});
}
The following output was truncated for brevity:
id=65e5ae52bb29f13bdd6f37c8 status=ready created_at=2024-03-04T11:19:46.901Z metadata={'filename': '01.mp4', 'duration': 579.12, 'width': 640, 'height': 360}
id=65d46ef879384c4778ab30fa status=ready created_at=2024-02-20T09:20:56.321Z metadata={'filename': '01.mp4', 'duration': 579.12, 'width': 640, 'height': 360}
Filter based on duration
To filter based on the duration of a video, use the duration
parameter. The example below displays all the videos of a specific duration (810
seconds):
from twelvelabs import TwelveLabs
client = TwelveLabs(api_key="<YOUR_API_KEY>")
tasks = client.task.list_pagination(
duration=810
)
# Utility function to print a specific page
def print_page(page):
for task in page:
print(f"id={task.id} status={task.status} created_at={task.created_at} metadata={task.metadata}")
print_page(tasks.data)
while True:
try:
print_page(next(tasks))
except StopIteration:
break
import { TwelveLabs, Task } from 'twelvelabs-js';
const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>'});
const tasks = await client.task.listPagination({ duration: 810 });
tasks.data.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status}`);
});
while (true) {
const nextPageData = await tasks.next();
if (!nextPageData) {
break;
}
nextPageData.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status} created_at=${task.createdAt} metadata=${task.metadata}`);
});
}
The following example output was truncated for brevity:
id=65e5ae52bb29f13bdd6f37c8 status=ready created_at=2024-03-04T11:19:46.901Z metadata={'filename': '02.mp4', 'duration': 810, 'width': 640, 'height': 360}
id=65d46ef879384c4778ab30fa status=ready created_at=2024-02-20T09:20:56.321Z metadata={'filename': '02.mp4', 'duration': 810, 'width': 640, 'height': 360}
Updated 5 days ago