Automatically update document metadata

There are two methods you can use to automatically update document metadata:

Using tokens

You can use tokens to automatically fill in your document metadata, just like you do it in your template.

Let’s say we have the following JSON structure:

{
    "title": "Invoice",
    "subject": "Water pumps",
    "creator": "David Navarro"
}

We’ll add the tokens {{title}}, {{subject}} and {{creator}} in the document metadata. Once you run the generation process, these tokens will be replaced with the values “Invoice,” “Water pumps,” and “David Navarro,” respectively.

metadata

Using the @metadata object

Alternatively, you can set the metadata values using the @metadata object directly in the JSON at the top level. You will need to pass @metadata JSON object along with other data.

{
    "@metadata": {
         "title": "Some title",
         "description": "Some description",
         "subject": "",
         "creator": "David Navarro",
         "keywords": "",
         "lastModifiedBy": "Plumsail Inc"
    },
  "prop1": "val1",
  "prop2": "val2",
  "propN": "valN"
}

In this structure, all metadata fields are defined within the JSON. If you don’t specify the lastModifiedBy and creator fields, the system will automatically use default values, which are “Plumsail Inc” and “Plumsail,” respectively.

It’s important to note that if a token appears both in the @metadata object and as a separate token within the JSON, the separate token will take precedence.

{
     "@metadata": {
         "creator": "admin"
    },
  "creator": "David Navarro"
}

In this case, the creator token will be replaced with “David Navarro,” overriding the value in the @metadata object.