Skip to main content
Platform
Language

Metadata

In this example, we will show you how to use the CreativeEditor SDK's CreativeEngine block API to modify a block's metadata. Metadata are a flat map of strings, that you can freely modify. They're serialized with the scene and may be used for various applications.

Setup#

This example uses the headless CreativeEngine. See the Setup article for a detailed guide. To get started right away, you can also access the block API within a running CE.SDK instance via cesdk.engine.block. Check out the APIs Overview to see that illustrated in more detail.

Functions#

setMetadata(id: DesignBlockId, key: string, value: string): void

Set a metadata value of a block identified by a key. If the key does not exist, yet, it will be added.

  • id: The block whose metadata will be accessed.
  • key: The key used to identify the desired piece of metadata.
  • value: The value to set.
hasMetadata(id: DesignBlockId, key: string): boolean

Check if the block has metadata associated with the key.

  • id: The block whose metadata will be accessed.
  • key: The key used to identify the desired piece of metadata.
  • Returns whether the key exists.
getMetadata(id: DesignBlockId, key: string): string

Get a metadata value of a block identified by a key. If the key does not exist, yet, this method will fail.

  • id: The block whose metadata will be accessed.
  • key: The key used to identify the desired piece of metadata.
  • Returns the value associated with the key.
findAllMetadata(id: DesignBlockId): string[]

Query all metadata keys that exist on this block.

  • id: The block whose metadata will be accessed.
  • Returns A list of all metadata keys on this block or an error, if the block is invalid.
removeMetadata(id: DesignBlockId, key: string): void

Remove metadata associated with the key from the given block. If the key does not exist, this method will fail.

  • id: The block whose metadata will be accessed.
  • key: The key used to identify the desired piece of metadata.
const payment = {
id: 5,
method: 'credit_card',
received: true
};
engine.block.setMetadata(image, 'payment', JSON.stringify(payment));
/* This will return 'img.ly' */
engine.block.getMetadata(scene, 'author');
/* This will return '1000000' */
engine.block.getMetadata(image, 'customer_id');
/* This will return ['customer_id'] */
engine.block.findAllMetadata(image);
engine.block.removeMetadata(image, 'payment');
/* This will return false */
engine.block.hasMetadata(image, 'payment');