Optional
description?: { File object for this asset
Optional
details?: Record<string, any>Details for the file, depending on file type (example: image size in bytes, etc)
Optional
upload?: stringUrl where the file is available to be downloaded from, into the Contentful asset system. After the asset is processed this field is gone.
Optional
uploadOptional
url?: stringUrl where the file is available at the Contentful media asset system. This field won't be available until the asset is processed.
Title for this asset
Optional
metadataArchives the object
Object returned from the server with updated metadata.
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getEnvironment('<environment_id>'))
.then((environment) => environment.getAsset('<asset_id>'))
.then((asset) => asset.archive())
.then((asset) => console.log(`Asset ${asset.sys.id} archived.`)
.catch(console.error)
Deletes this object on the server.
Promise for the deletion. It contains no data, but the Promise error case should be handled.
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getEnvironment('<environment_id>'))
.then((environment) => environment.getAsset('<asset_id>'))
.then((asset) => asset.delete())
.then((asset) => console.log(`Asset deleted.`)
.catch(console.error)
Triggers asset processing after an upload, for the files uploaded to all locales of an asset.
Time in milliseconds to wait before checking again if the asset has been processed (default: 500ms)
Maximum amount of times to check if the asset has been processed (default: 5)
Object returned from the server with updated metadata.
If the asset takes too long to process. If this happens, retrieve the asset again, and if the url property is available, then processing has succeeded. If not, your file might be damaged.
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getEnvironment('<environment_id>'))
.then((environment) => environment.createAssetWithId('<asset_id>', {
title: {
'en-US': 'Playsam Streamliner',
'de-DE': 'Playsam Streamliner'
},
file: {
'en-US': {
contentType: 'image/jpeg',
fileName: 'example.jpeg',
upload: 'https://example.com/example.jpg'
},
'de-DE': {
contentType: 'image/jpeg',
fileName: 'example.jpeg',
upload: 'https://example.com/example-de.jpg'
}
}
}))
.then((asset) => asset.processForAllLocales())
.then((asset) => console.log(asset))
.catch(console.error)
Optional
options: AssetProcessingForLocaleAdditional options for processing
Triggers asset processing after an upload, for the file uploaded to a specific locale.
Time in milliseconds to wait before checking again if the asset has been processed (default: 500ms)
Maximum amount of times to check if the asset has been processed (default: 5)
Object returned from the server with updated metadata.
If the asset takes too long to process. If this happens, retrieve the asset again, and if the url property is available, then processing has succeeded. If not, your file might be damaged.
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getEnvironment('<environment_id>'))
.then((environment) => environment.createAssetWithId('<asset_id>', {
title: {
'en-US': 'Playsam Streamliner',
},
file: {
'en-US': {
contentType: 'image/jpeg',
fileName: 'example.jpeg',
upload: 'https://example.com/example.jpg'
}
}
}))
.then((asset) => asset.processForLocale('en-US'))
.then((asset) => console.log(asset))
.catch(console.error)
Locale which processing should be triggered for
Optional
Options: AssetProcessingForLocalePublishes the object
Object returned from the server with updated metadata.
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getEnvironment('<environment_id>'))
.then((environment) => environment.getAsset('<asset_id>'))
.then((asset) => asset.publish())
.then((asset) => console.log(`Asset ${asset.sys.id} published.`)
.catch(console.error)
Unarchives the object
Object returned from the server with updated metadata.
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getEnvironment('<environment_id>'))
.then((environment) => environment.getAsset('<asset_id>'))
.then((asset) => asset.unarchive())
.then((asset) => console.log(`Asset ${asset.sys.id} unarchived.`)
.catch(console.error)
Unpublishes the object
Object returned from the server with updated metadata.
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getEnvironment('<environment_id>'))
.then((environment) => environment.getAsset('<asset_id>'))
.then((asset) => asset.unpublish())
.then((asset) => console.log(`Asset ${asset.sys.id} unpublished.`)
.catch(console.error)
Sends an update to the server with any changes made to the object's properties
Object returned from the server with updated changes.
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getEnvironment('<environment_id>'))
.then((environment) => environment.getAsset('<asset_id>'))
.then((asset) => {
asset.fields.title['en-US'] = 'New asset title'
return asset.update()
})
.then((asset) => console.log(`Asset ${asset.sys.id} updated.`)
.catch(console.error)
Description for this asset