Hierarchy

Properties

fields: {
    description?: {
        [key: string]: string;
    };
    file: {
        [key: string]: {
            contentType: string;
            details?: Record<string, any>;
            fileName: string;
            upload?: string;
            uploadFrom?: Record<string, any>;
            url?: string;
        };
    };
    title: {
        [key: string]: string;
    };
}

Type declaration

  • Optional description?: {
        [key: string]: string;
    }

    Description for this asset

    • [key: string]: string
  • file: {
        [key: string]: {
            contentType: string;
            details?: Record<string, any>;
            fileName: string;
            upload?: string;
            uploadFrom?: Record<string, any>;
            url?: string;
        };
    }

    File object for this asset

    • [key: string]: {
          contentType: string;
          details?: Record<string, any>;
          fileName: string;
          upload?: string;
          uploadFrom?: Record<string, any>;
          url?: string;
      }
      • contentType: string
      • Optional details?: Record<string, any>

        Details for the file, depending on file type (example: image size in bytes, etc)

      • fileName: string
      • Optional upload?: string

        Url where the file is available to be downloaded from, into the Contentful asset system. After the asset is processed this field is gone.

      • Optional uploadFrom?: Record<string, any>
      • Optional url?: string

        Url where the file is available at the Contentful media asset system. This field won't be available until the asset is processed.

  • title: {
        [key: string]: string;
    }

    Title for this asset

    • [key: string]: string
metadata?: MetadataProps

Methods

  • Archives the object

    Returns

    Object returned from the server with updated metadata.

    Example

    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)

    Returns Promise<Asset>

  • Deletes this object on the server.

    Returns

    Promise for the deletion. It contains no data, but the Promise error case should be handled.

    Example

    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)

    Returns Promise<void>

  • Checks if asset is archived. This means it's not exposed to the Delivery/Preview APIs.

    Returns boolean

  • Checks if the asset is in draft mode. This means it is not published.

    Returns boolean

  • Checks if the asset is published. A published asset might have unpublished changes

    Returns boolean

  • Checks if the asset is updated. This means the asset was previously published but has unpublished changes.

    Returns boolean

  • Triggers asset processing after an upload, for the files uploaded to all locales of an asset.

    Prop

    Time in milliseconds to wait before checking again if the asset has been processed (default: 500ms)

    Prop

    Maximum amount of times to check if the asset has been processed (default: 5)

    Returns

    Object returned from the server with updated metadata.

    Throws

    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.

    Example

    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)

    Parameters

    • Optional options: AssetProcessingForLocale

      Additional options for processing

    Returns Promise<Asset>

  • Triggers asset processing after an upload, for the file uploaded to a specific locale.

    Prop

    Time in milliseconds to wait before checking again if the asset has been processed (default: 500ms)

    Prop

    Maximum amount of times to check if the asset has been processed (default: 5)

    Returns

    Object returned from the server with updated metadata.

    Throws

    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.

    Example

    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)

    Parameters

    • locale: string

      Locale which processing should be triggered for

    • Optional Options: AssetProcessingForLocale

    Returns Promise<Asset>

  • Publishes the object

    Returns

    Object returned from the server with updated metadata.

    Example

    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)

    Returns Promise<Asset>

  • Unarchives the object

    Returns

    Object returned from the server with updated metadata.

    Example

    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)

    Returns Promise<Asset>

  • Unpublishes the object

    Returns

    Object returned from the server with updated metadata.

    Example

    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)

    Returns Promise<Asset>

  • Sends an update to the server with any changes made to the object's properties

    Returns

    Object returned from the server with updated changes.

    Example

    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)

    Returns Promise<Asset>