Add custom metadata to your resources to better track and organize your transcoding workflow
Metadata are defined as key-value pairs and can be added to the following resources: upload, sourceand job.
With these metadata you can add extra information to your resources and use it in your workflows.
For example, you can add your own IDs to your sources to avoid keeping Chunkify IDs in your database or you can add a custom description to your jobs to help you find them later.
Add Metadata to a resource
We will add some extra information to a job, we will need to do it at the job creation time.
Metadata per resource is limited to 2048 bytes total.
importChunkifyfrom'@chunkify/chunkify';constclient=newChunkify({projectAccessToken:'My Project Access Token',});// Add metadata to a job
constjob=awaitclient.jobs.create({source_id: source.id,format:{id:'mp4_h264',height: 1080,},metadata:{group:'test_jobs',},});
fromchunkifyimportChunkifyclient=Chunkify(project_access_token="My Project Access Token",)# Add metadata to a jobjob=client.jobs.create(source_id=source.id,format={"id":"mp4_h264","height":1080,},metadata={"group":"test_jobs"},)
useChunkify\Client;$client=newClient(projectAccessToken:'My Project Access Token',);// Add metadata to a job
$job=$client->jobs->create(format:['id'=>'mp4_h264','height'=>1080],sourceID:$source->id,metadata:['group'=>'test_jobs'],);
import("context""github.com/chunkifydev/chunkify-go""github.com/chunkifydev/chunkify-go/option")client:=chunkify.NewClient(option.WithProjectAccessToken("My Project Access Token"),)// Add metadata to a job
jobParams:=chunkify.JobNewParams{SourceID:source.ID,Format:chunkify.JobNewParamsFormatUnion{OfMP4H264:&chunkify.MP4H264Param{Height:chunkify.Int(1080),},},Metadata:map[string]string{"group":"test_jobs",},}job,err:=client.Jobs.New(context.TODO(),jobParams)iferr!=nil{log.Fatal(err)}
When adding metadata to an upload, it will also be added to the source
created from this upload. See the Metadata on uploads and sources section for more details
Key-Value Filtering
As seen above Metadata is a key-value store, and you can use these to filter your resources. Using the same values as the example above we could filter our jobs
to find the ones that have the group metadata set to test_jobs.
importChunkifyfrom'@chunkify/chunkify';constclient=newChunkify({projectAccessToken:'My Project Access Token',});// List all the jobs with the group metadata set to test_jobs
constjobs=awaitclient.jobs.list({metadata:[['group:test_jobs']]});// jobs are paginated results, we can access the results of the first page
console.log(jobs.data);
fromchunkifyimportChunkifyclient=Chunkify(project_access_token="My Project Access Token",)# List all the jobs with the group metadata set to test_jobsjobs=client.jobs.list(metadata=[["group:test_jobs"]])# jobs are paginated results, we can access the results of the first pageprint(jobs.data)
useChunkify\Client;$client=newClient(projectAccessToken:'My Project Access Token',);// List all the jobs with the group metadata set to test_jobs
$jobs=$client->jobs->list(metadata:[['group:test_jobs']],);// jobs are paginated results, we can access the results of the first page
print_r($jobs->getItems());
import("context""github.com/chunkifydev/chunkify-go""github.com/chunkifydev/chunkify-go/option")client:=chunkify.NewClient(option.WithProjectAccessToken("My Project Access Token"),)// List all the jobs with the group metadata set to test_jobs
jobs,err:=client.Jobs.List(context.TODO(),chunkify.JobListParams{Metadata:[][]string{{"group:test_jobs"},},})iferr!=nil{log.Fatal(err)}// jobs are paginated results, we can access the results of the first page
fmt.Println(jobs.Data)
Metadata on uploads and sources
Metadata added to an upload is automatically inherited by the source created from it.
This is useful for tracking resources using IDs from your internal database. For example,
if you want to keep track of which user uploaded a source, you can add their user ID from
your internal database as metadata:
importChunkifyfrom'@chunkify/chunkify';constclient=newChunkify({projectAccessToken:'My Project Access Token',});// Add metadata with your internal user ID when creating an upload
constupload=awaitclient.uploads.create({metadata:{uploaded_by:'user_demo',},});// Once the upload is processed and a source is created,
// the source will inherit this metadata
// You can then filter sources by this user ID
constsources=awaitclient.sources.list({metadata:[['uploaded_by:user_demo']],created:{sort:'desc',},});console.log(sources.data)
# Add metadata with your internal user ID when creating an uploadupload=client.uploads.create(metadata={"uploaded_by":"user_demo"})# Once the upload is processed and a source is created,# the source will inherit this metadata# You can then filter sources by this user IDsources=client.sources.list(metadata=[["uploaded_by:user_demo"]],created={"sort":"desc",})print("Sources list: ",sources.data)
// Add metadata with your internal user ID when creating an upload
$upload=$client->uploads->create(metadata:['uploaded_by'=>'user_demo'],);// Once the upload is processed and a source is created,
// the source will inherit this metadata
// You can then filter sources by this user ID
$sources=$client->sources->list(metadata:[['uploaded_by:user_demo']],created:['sort'=>'desc'],);print_r($sources->getItems());
import("context""github.com/chunkifydev/chunkify-go""github.com/chunkifydev/chunkify-go/option")// Add metadata with your internal user ID when creating an upload
upload,err:=client.Uploads.New(context.TODO(),chunkify.UploadNewParams{Metadata:map[string]string{"uploaded_by":"user_demo",},})iferr!=nil{log.Fatal(err)}// Once the upload is processed and a source is created,
// the source will inherit this metadata
// You can then filter sources by this user ID
sources,err:=client.Sources.List(context.TODO(),chunkify.SourceListParams{Metadata:[][]string{{"uploaded_by:user_demo"},},Created:chunkify.SourceListParamsCreated{Sort:"desc",},})iferr!=nil{log.Fatal(err)}
# Metadata
> Add custom metadata to your resources to better track and organize your transcoding workflow
Metadata are defined as key-value pairs and can be added to the following resources: `upload`, `source`and `job`.
With these metadata you can add extra information to your resources and use it in your workflows.
For example, you can add your own IDs to your sources to avoid keeping Chunkify IDs in your database or you can add a custom description to your jobs to help you find them later.
## Add Metadata to a resource
We will add some extra information to a job, we will need to do it at the job creation time.
<warning>Metadata per resource is limited to 2048 bytes total.</warning>
<codegroup>
<codeblock lang="Typescript">
```typescript
import Chunkify from '@chunkify/chunkify';
const client = new Chunkify({
projectAccessToken: 'My Project Access Token',
});
// Add metadata to a job
const job = await client.jobs.create({
source_id: source.id,
format: {
id: 'mp4_h264',
height: 1080,
},
metadata: {
group: 'test_jobs',
},
});
```
</codeblock>
<codeblock lang="Python">
```python
from chunkify import Chunkify
client = Chunkify(
project_access_token="My Project Access Token",
)
# Add metadata to a job
job = client.jobs.create(
source_id=source.id,
format={
"id": "mp4_h264",
"height": 1080,
},
metadata={"group": "test_jobs"},
)
```
</codeblock>
<codeblock lang="PHP">
```php
use Chunkify\Client;
$client = new Client(
projectAccessToken: 'My Project Access Token',
);
// Add metadata to a job
$job = $client->jobs->create(
format: ['id' => 'mp4_h264', 'height' => 1080],
sourceID: $source->id,
metadata: ['group' => 'test_jobs'],
);
```
</codeblock>
<codeblock lang="Go">
```go Go
import (
"context"
"github.com/chunkifydev/chunkify-go"
"github.com/chunkifydev/chunkify-go/option"
)
client := chunkify.NewClient(
option.WithProjectAccessToken("My Project Access Token"),
)
// Add metadata to a job
jobParams := chunkify.JobNewParams{
SourceID: source.ID,
Format: chunkify.JobNewParamsFormatUnion{
OfMP4H264: &chunkify.MP4H264Param{
Height: chunkify.Int(1080),
},
},
Metadata: map[string]string{
"group": "test_jobs",
},
}
job, err := client.Jobs.New(context.TODO(), jobParams)
if err != nil {
log.Fatal(err)
}
```
</codeblock>
</codegroup>
<note>
When adding metadata to an `upload`, it will also be added to the `source`
created from this upload. See the [Metadata on uploads and sources](#metadata-on-uploads-and-sources) section for more details
</note>
## Key-Value Filtering
As seen above Metadata is a key-value store, and you can use these to filter your resources. Using the same values as the example above we could filter our jobs
to find the ones that have the `group` metadata set to `test_jobs`.
<codegroup>
<codeblock lang="Typescript">
```typescript
import Chunkify from '@chunkify/chunkify';
const client = new Chunkify({
projectAccessToken: 'My Project Access Token',
});
// List all the jobs with the group metadata set to test_jobs
const jobs = await client.jobs.list({
metadata: [['group:test_jobs']]
});
// jobs are paginated results, we can access the results of the first page
console.log(jobs.data);
```
</codeblock>
<codeblock lang="Python">
```python
from chunkify import Chunkify
client = Chunkify(
project_access_token="My Project Access Token",
)
# List all the jobs with the group metadata set to test_jobs
jobs = client.jobs.list(
metadata=[["group:test_jobs"]]
)
# jobs are paginated results, we can access the results of the first page
print(jobs.data)
```
</codeblock>
<codeblock lang="PHP">
```php
use Chunkify\Client;
$client = new Client(
projectAccessToken: 'My Project Access Token',
);
// List all the jobs with the group metadata set to test_jobs
$jobs = $client->jobs->list(
metadata: [['group:test_jobs']],
);
// jobs are paginated results, we can access the results of the first page
print_r($jobs->getItems());
```
</codeblock>
<codeblock lang="Go">
```go
import (
"context"
"github.com/chunkifydev/chunkify-go"
"github.com/chunkifydev/chunkify-go/option"
)
client := chunkify.NewClient(
option.WithProjectAccessToken("My Project Access Token"),
)
// List all the jobs with the group metadata set to test_jobs
jobs, err := client.Jobs.List(context.TODO(), chunkify.JobListParams{
Metadata: [][]string{
{"group:test_jobs"},
},
})
if err != nil {
log.Fatal(err)
}
// jobs are paginated results, we can access the results of the first page
fmt.Println(jobs.Data)
```
</codeblock>
</codegroup>
## Metadata on uploads and sources
Metadata added to an upload is automatically inherited by the source created from it.
This is useful for tracking resources using IDs from your internal database. For example,
if you want to keep track of which user uploaded a source, you can add their user ID from
your internal database as metadata:
<codegroup>
<codeblock lang="Typescript">
```typescript
import Chunkify from '@chunkify/chunkify';
const client = new Chunkify({
projectAccessToken: 'My Project Access Token',
});
// Add metadata with your internal user ID when creating an upload
const upload = await client.uploads.create({
metadata: {
uploaded_by: 'user_demo',
},
});
// Once the upload is processed and a source is created,
// the source will inherit this metadata
// You can then filter sources by this user ID
const sources= await client.sources.list({
metadata: [['uploaded_by:user_demo']],
created: {
sort: 'desc',
},
});
console.log(sources.data)
```
</codeblock>
<codeblock lang="Python">
```Python
# Add metadata with your internal user ID when creating an upload
upload = client.uploads.create(
metadata={"uploaded_by": "user_demo"}
)
# Once the upload is processed and a source is created,
# the source will inherit this metadata
# You can then filter sources by this user ID
sources = client.sources.list(
metadata=[["uploaded_by:user_demo"]],
created={
"sort": "desc",
}
)
print("Sources list: ", sources.data)
```
</codeblock>
<codeblock lang="PHP">
```php
// Add metadata with your internal user ID when creating an upload
$upload = $client->uploads->create(
metadata: ['uploaded_by' => 'user_demo'],
);
// Once the upload is processed and a source is created,
// the source will inherit this metadata
// You can then filter sources by this user ID
$sources = $client->sources->list(
metadata: [['uploaded_by:user_demo']],
created: ['sort' => 'desc'],
);
print_r($sources->getItems());
```
</codeblock>
<codeblock lang="Go">
```Go
import (
"context"
"github.com/chunkifydev/chunkify-go"
"github.com/chunkifydev/chunkify-go/option"
)
// Add metadata with your internal user ID when creating an upload
upload, err := client.Uploads.New(context.TODO(), chunkify.UploadNewParams{
Metadata: map[string]string{
"uploaded_by": "user_demo",
},
})
if err != nil {
log.Fatal(err)
}
// Once the upload is processed and a source is created,
// the source will inherit this metadata
// You can then filter sources by this user ID
sources, err := client.Sources.List(context.TODO(), chunkify.SourceListParams{
Metadata: [][]string{
{"uploaded_by:user_demo"},
},
Created: chunkify.SourceListParamsCreated{
Sort: "desc",
},
})
if err != nil {
log.Fatal(err)
}
```
</codeblock>
</codegroup>