Asset

View as Markdown

Asset

Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use. These files can be attached and used in multiple entries.

create_folder

The create_folder method creates a new asset folder and/or adds a parent folder to it in a particular stack.

NameTypeDescription
data (required)Dict

The data you want to send to the server when creating a folder.

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

data = {
    >>>     "asset": {
        >>>         "name": "Demo"
    >>>     }
}
asset = client().stack(api_key='api_key').assets()
response = asset.create_folder(data)

delete_folder

The delete_folder method removes an existing asset folder along with all the assets within that folder.

NameTypeDescription
folder_uid (required)str

The UID of the folder you want to delete

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

asset = client().stack(api_key='api_key').assets()
response = asset.delete(folder_uid='folder_uid')

delete

The delete method removes an existing asset from the stack.

NameTypeDescription
asset_uid (required)str

UID of the asset

client = contentstack_management.Client(authtoken="authtoken")

asset = client().stack(api_key='api_key').assets()
response = asset.delete("asset_uid")

download

The download method lets you save the specific asset in your local storage.

NameTypeDescription
asset_uid (required)str

UID of the asset

client = contentstack_management.Client(authtoken="authtoken")

asset = client().stack(api_key='api_key').assets(asset_uid='asset_uid')
response = asset.download()

fetch

The fetch method retrieves the details of a specific version of a particular asset

NameTypeDescription
asset_uid (required)str

UID of the asset

include_asset_scan_statusBoolean

When true, includes the _asset_scan_status field in the asset response (pending, clean, quarantined, or not_scanned). Opt-in; omitted from the request by default.

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

asset = client().stack(api_key='api_key').assets()
response = asset.fetch("asset_uid")

find

The find method retrieves the details of all assets in a stack.

NameTypeDescription
include_asset_scan_statusBoolean

When true, includes the _asset_scan_status field in the asset response (pending, clean, quarantined, or not_scanned). Opt-in; omitted from the request by default.

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

asset = client().stack(api_key='api_key').assets()
response = asset.find()

folder

The folder method retrieves the details of a specific asset folder in the stack using the folder UID.

NameTypeDescription
folder_uid (required)str

UID of the folder

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

asset = client().stack(api_key='api_key').assets()
response = asset.folder_collection(folder_uid='folder_uid')

folder_by_name

The folder_by_name method retrieves the details of a specific asset folder in the stack using the folder name.

NameTypeDescription
query (required)str

The search query for the folder

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

query = {"is_dir": True, "name": "folder_name"}
asset = client().stack(api_key='api_key').assets()
response = asset.folder_collection(query)

generate

The generate method allows you to generate a permanent asset URL for the specific asset.

NameTypeDescription
data (required)Dict

The data to be sent in the request body

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

data = {
   "asset": {
       "permanent_url": "https://images.contentstack.io/v3/assets/stack_api_key/asset_UID/sample-slug.jpeg"
       }
   } 
asset = client().stack(api_key='api_key').assets(asset_uid='asset_uid')
response = asset.generate(data)

get_subfolders

The get_subfolders method retrieves the details of only the subfolder within a specific asset folder in the stack.

NameTypeDescription
folder_uid (required)str

The UID of the folder

query (required)str

The search query for the folder

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

query = {"is_dir": True}
asset = client().stack(api_key='api_key').assets()
response = asset.folder_collection(folder_uid='folder_uid', query)

publish

The publish method allows you to publish a specific version of the asset on the required environment either immediately or at a later time/date.

NameTypeDescription
data (required)Dict

The data that you want to publish.

import contentstack_management

client = contentstack_management.Client(authtoken="authtoken")


data = {

         "asset": {

                 "locales": [

                         "en-us"

                 ],

                 "environments": [

                         "development"

                 ]

         },

         "version": 1,

         "scheduled_at": "2019-02-08T18:30:00.000Z"

}

asset = client().stack(api_key='api_key').assets(asset_uid='asset_uid')

response = asset.publish(data)

references

The references method retrieves the details of the entries and content types in which a specific asset is referenced.

NameTypeDescription
asset_uid (required)str

UID of the asset

client = contentstack_management.Client(authtoken="authtoken")

asset = client().stack(api_key='api_key').assets(asset_uid='asset_uid')
response = asset.references()

replace

The replace method allows you to replace an existing asset with another file in the stack.

NameTypeDescription
file_path (required)str

The path to the file that you want to replace the existing asset with.

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

file_path = ""
asset = client().stack(api_key='api_key').assets(asset_uid='asset_uid')
response = asset.replace(file_path)

rte

The rte method retrieves the details of all the assets uploaded through the Rich Text Editor field.

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

asset = client().stack(api_key='api_key').assets()
response = asset.rte()

specific_asset_type

The specific_asset_type method retrieves the assets based on the query request.

NameTypeDescription
asset_typestr

The type of asset you want to retrieve

client = contentstack_management.Client(authtoken="authtoken")

asset_type = "images"
asset = client().stack(api_key='api_key').assets()
response = asset.specific_asset_type(asset_type)

specific_folder

The specific_folder method retrieves the details of assets of a specific asset folder without the subfolders in the requested parent folder.

NameTypeDescription
folder_uid (required)str

UID of the folder

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

asset = client().stack(api_key='api_key').assets()
response = asset.specific_folder("folder_uid")

subfolder

The subfolder method retrieves the details of assets and subfolders of a specific parent folder.

NameTypeDescription
folder_uid (required)str

UID of the folder

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

asset = client().stack(api_key='api_key').assets()
response = asset.subfolders("folder_uid")

unpublish

The unpublish method allows you to unpublish a specific version of an asset from a desired environment.

NameTypeDescription
data (required)Dict

The data you want to send to server for the unpublish operation

import contentstack_management

client = contentstack_management.Client(authtoken="authtoken")


data = {

         "asset": {

                 "locales": [

                         "en-us"

                 ],

                 "environments": [

                         "development"

                ]

         },

         "version": 1,

         "scheduled_at": "2019-02-08T18:30:00.000Z"

}

asset = client().stack(api_key='api_key').assets(asset_uid='asset_uid')

response = asset.unpublish(data)

update

The update method allows you to make changes in the title and description of an existing asset in the stack.

NameTypeDescription
data (required)Dict

The updated information for the asset

import contentstack_management

client = contentstack_management.Client(authtoken="authtoken")


data = {

         "asset": {

                 "title": "Title"

         }

}

asset = client().stack(api_key='api_key').assets(asset_uid='asset_uid')

response = asset.update(data)

update_asset_revision

The update_asset_revision method upgrades the specified version of the asset to the latest version.

NameTypeDescription
data (required)Dict

The updated information for the asset

import contentstack_management

client = contentstack_management.Client(authtoken="authtoken")


data = {

         "asset": {

                 "title": "Title",

                 "description": "Description"

         },

         "version": 2

}

asset = client().stack(api_key='api_key').assets(asset_uid='asset_uid')

response = asset.update_asset_revision(data)

update_or_move

The update_or_move method allows you to either update the details of a folder or set the folder as a parent folder if you want to move a folder under another folder.

NameTypeDescription
folder_uid (required)str

UID of the folder

data (required)Dict

The request body

import contentstack_management

client = contentstack_management.Client(authtoken="authtoken")


data = {

         "asset": {

                 "name": "Demo"

         }

}

asset = client().stack(api_key='api_key').assets()

response = asset.update_or_move(folder_uid='folder_uid', data)

upload

The upload method allows you to upload an asset file in the stack.

NameTypeDescription
file_path (required)str

The path to the file you want to upload

import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")

file_path = ""
asset = client().stack(api_key='api_key').assets()
response = asset.upload(file_path)

version

The version method retrieves the details of all versions of an asset.

NameTypeDescription
asset_uid (required)str

UID of the asset

client = contentstack_management.Client(authtoken="authtoken")

asset = client().stack(api_key='api_key').assets(asset_uid='asset_uid')
response = asset.version()

version_delete

The version_delete method allows you to remove the name of a specific version of an asset and resets it to the version number.

NameTypeDescription
version_number (required)str

The version of the asset you want to delete

client = contentstack_management.Client(authtoken="authtoken")

version_number = 1
asset = client().stack(api_key='api_key').assets(asset_uid='asset_uid')
response = asset.version_delete(version_number)

version_naming

The version_naming method allows you to assign a name to a specific version of an asset.

NameTypeDescription
data (required)Dict

The information you want to update for the specified version

version_number (required)str

The version of the asset you want to delete

import contentstack_management

client = contentstack_management.Client(authtoken="authtoken")


version_number = 1

data = {

         "upload": {

             "_version_name": "Version name"

         }

}

asset = client().stack(api_key='api_key').assets(asset_uid='asset_uid')

response = asset.version_naming(version_number, data)