Skip to main content

Summary

Apply detected DOCX template/substrate (styles, numbering, settings, theme, font table, web settings, headers/footers, section defaults) from a source package onto the current document, preserving body content. Scopes are auto-detected from source package evidence.
  • Operation ID: templates.apply
  • API member path: await editor.doc.templates.apply(...)
  • Mutates document: yes
  • Idempotency: conditional
  • Supports tracked mode: no
  • Supports dry run: yes
  • Returns a promise (must be awaited): yes
  • Deterministic target resolution: yes

Expected result

Returns a TemplatesApplyReceipt with detected/applied/skipped scopes, unsupported items, changed parts, id mappings, and warnings.

Input fields

FieldTypeRequiredDescription
bodyPolicy"preserve"noConstant: "preserve"
sourceobject(kind=“path”) | object(kind=“base64”)yesOne of: object(kind=“path”), object(kind=“base64”)

Example request

{
  "bodyPolicy": "preserve",
  "source": {
    "kind": "path",
    "path": "example"
  }
}

Output fields

Variant 1 (success=true)

FieldTypeRequiredDescription
appliedScopesobject[]yes
bodyPolicy"preserve"yesConstant: "preserve"
changedbooleanyes
changedPartsobject[]yes
detectedScopesobject[]yes
dryRunbooleanyes
idMappingsobjectyes
idMappings.numberingobject[]no
idMappings.relationshipsobject[]no
idMappings.stylesobject[]no
skippedScopesobject[]yes
sourceobjectyes
source.fingerprintstringyes
source.kindenumyes"path", "base64"
source.partCountintegeryes
successtrueyesConstant: true
unsupportedItemsobject[]yes
warningsobject[]yes

Variant 2 (success=false)

FieldTypeRequiredDescription
failureobjectyes
failure.codeenumyes"UNSUPPORTED_SOURCE", "INVALID_PACKAGE", "CAPABILITY_UNAVAILABLE", "UNSUPPORTED_TEMPLATE_CONTENT"
failure.messagestringyes
successfalseyesConstant: false

Example response

{
  "appliedScopes": [
    {
      "detail": "example",
      "part": "example",
      "scope": "styles"
    }
  ],
  "bodyPolicy": "preserve",
  "changed": true,
  "changedParts": [
    {
      "change": "created",
      "part": "example",
      "scope": "styles"
    }
  ],
  "detectedScopes": [
    {
      "detail": "example",
      "part": "example",
      "scope": "styles"
    }
  ],
  "dryRun": true,
  "idMappings": {
    "numbering": [
      {
        "from": "example",
        "kind": "style",
        "to": "example"
      }
    ],
    "styles": [
      {
        "from": "example",
        "kind": "style",
        "to": "example"
      }
    ]
  },
  "skippedScopes": [
    {
      "message": "Operation failed.",
      "part": "example",
      "reason": "NOT_PRESENT_IN_SOURCE",
      "scope": "all"
    }
  ],
  "source": {
    "fingerprint": "example",
    "kind": "path",
    "partCount": 1
  },
  "success": true,
  "unsupportedItems": [
    {
      "category": "example",
      "part": "example",
      "reason": "example"
    }
  ],
  "warnings": [
    {
      "code": "INVALID_TARGET",
      "message": "Operation failed."
    }
  ]
}

Pre-apply throws

  • INVALID_INPUT
  • CAPABILITY_UNAVAILABLE
  • REVISION_MISMATCH

Non-applied failure codes

  • UNSUPPORTED_SOURCE
  • INVALID_PACKAGE
  • CAPABILITY_UNAVAILABLE
  • UNSUPPORTED_TEMPLATE_CONTENT

Raw schemas

{
  "additionalProperties": false,
  "properties": {
    "bodyPolicy": {
      "const": "preserve"
    },
    "source": {
      "oneOf": [
        {
          "additionalProperties": false,
          "properties": {
            "kind": {
              "const": "path"
            },
            "path": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "path"
          ],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "data": {
              "type": "string"
            },
            "filename": {
              "type": "string"
            },
            "kind": {
              "const": "base64"
            }
          },
          "required": [
            "kind",
            "data"
          ],
          "type": "object"
        }
      ]
    }
  },
  "required": [
    "source"
  ],
  "type": "object"
}
{
  "oneOf": [
    {
      "additionalProperties": false,
      "properties": {
        "appliedScopes": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "detail": {
                "type": "string"
              },
              "part": {
                "type": "string"
              },
              "scope": {
                "enum": [
                  "styles",
                  "numbering",
                  "settings",
                  "theme",
                  "fontTable",
                  "webSettings",
                  "headersFooters",
                  "sectionDefaults"
                ]
              }
            },
            "required": [
              "scope",
              "part"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "bodyPolicy": {
          "const": "preserve"
        },
        "changed": {
          "type": "boolean"
        },
        "changedParts": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "change": {
                "enum": [
                  "created",
                  "replaced",
                  "merged",
                  "imported"
                ]
              },
              "part": {
                "type": "string"
              },
              "scope": {
                "enum": [
                  "styles",
                  "numbering",
                  "settings",
                  "theme",
                  "fontTable",
                  "webSettings",
                  "headersFooters",
                  "sectionDefaults",
                  "package"
                ]
              }
            },
            "required": [
              "part",
              "scope",
              "change"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "detectedScopes": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "detail": {
                "type": "string"
              },
              "part": {
                "type": "string"
              },
              "scope": {
                "enum": [
                  "styles",
                  "numbering",
                  "settings",
                  "theme",
                  "fontTable",
                  "webSettings",
                  "headersFooters",
                  "sectionDefaults"
                ]
              }
            },
            "required": [
              "scope",
              "part"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "dryRun": {
          "type": "boolean"
        },
        "idMappings": {
          "additionalProperties": false,
          "properties": {
            "numbering": {
              "items": {
                "additionalProperties": false,
                "properties": {
                  "from": {
                    "type": "string"
                  },
                  "kind": {
                    "enum": [
                      "style",
                      "numbering",
                      "relationship"
                    ]
                  },
                  "to": {
                    "type": "string"
                  }
                },
                "required": [
                  "kind",
                  "from",
                  "to"
                ],
                "type": "object"
              },
              "type": "array"
            },
            "relationships": {
              "items": {
                "additionalProperties": false,
                "properties": {
                  "from": {
                    "type": "string"
                  },
                  "kind": {
                    "enum": [
                      "style",
                      "numbering",
                      "relationship"
                    ]
                  },
                  "to": {
                    "type": "string"
                  }
                },
                "required": [
                  "kind",
                  "from",
                  "to"
                ],
                "type": "object"
              },
              "type": "array"
            },
            "styles": {
              "items": {
                "additionalProperties": false,
                "properties": {
                  "from": {
                    "type": "string"
                  },
                  "kind": {
                    "enum": [
                      "style",
                      "numbering",
                      "relationship"
                    ]
                  },
                  "to": {
                    "type": "string"
                  }
                },
                "required": [
                  "kind",
                  "from",
                  "to"
                ],
                "type": "object"
              },
              "type": "array"
            }
          },
          "type": "object"
        },
        "skippedScopes": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "message": {
                "type": "string"
              },
              "part": {
                "type": "string"
              },
              "reason": {
                "enum": [
                  "NOT_PRESENT_IN_SOURCE",
                  "OUT_OF_SCOPE",
                  "NO_CHANGE",
                  "CAPABILITY_UNAVAILABLE"
                ]
              },
              "scope": {
                "type": "string"
              }
            },
            "required": [
              "scope",
              "reason",
              "message"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "source": {
          "additionalProperties": false,
          "properties": {
            "fingerprint": {
              "type": "string"
            },
            "kind": {
              "enum": [
                "path",
                "base64"
              ]
            },
            "partCount": {
              "type": "integer"
            }
          },
          "required": [
            "kind",
            "fingerprint",
            "partCount"
          ],
          "type": "object"
        },
        "success": {
          "const": true
        },
        "unsupportedItems": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "category": {
                "type": "string"
              },
              "part": {
                "type": "string"
              },
              "reason": {
                "type": "string"
              }
            },
            "required": [
              "part",
              "category",
              "reason"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "warnings": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ],
            "type": "object"
          },
          "type": "array"
        }
      },
      "required": [
        "success",
        "changed",
        "dryRun",
        "bodyPolicy",
        "source",
        "detectedScopes",
        "appliedScopes",
        "skippedScopes",
        "unsupportedItems",
        "changedParts",
        "idMappings",
        "warnings"
      ],
      "type": "object"
    },
    {
      "additionalProperties": false,
      "properties": {
        "failure": {
          "additionalProperties": false,
          "properties": {
            "code": {
              "enum": [
                "UNSUPPORTED_SOURCE",
                "INVALID_PACKAGE",
                "CAPABILITY_UNAVAILABLE",
                "UNSUPPORTED_TEMPLATE_CONTENT"
              ]
            },
            "message": {
              "type": "string"
            }
          },
          "required": [
            "code",
            "message"
          ],
          "type": "object"
        },
        "success": {
          "const": false
        }
      },
      "required": [
        "success",
        "failure"
      ],
      "type": "object"
    }
  ]
}
{
  "additionalProperties": false,
  "properties": {
    "appliedScopes": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "detail": {
            "type": "string"
          },
          "part": {
            "type": "string"
          },
          "scope": {
            "enum": [
              "styles",
              "numbering",
              "settings",
              "theme",
              "fontTable",
              "webSettings",
              "headersFooters",
              "sectionDefaults"
            ]
          }
        },
        "required": [
          "scope",
          "part"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "bodyPolicy": {
      "const": "preserve"
    },
    "changed": {
      "type": "boolean"
    },
    "changedParts": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "change": {
            "enum": [
              "created",
              "replaced",
              "merged",
              "imported"
            ]
          },
          "part": {
            "type": "string"
          },
          "scope": {
            "enum": [
              "styles",
              "numbering",
              "settings",
              "theme",
              "fontTable",
              "webSettings",
              "headersFooters",
              "sectionDefaults",
              "package"
            ]
          }
        },
        "required": [
          "part",
          "scope",
          "change"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "detectedScopes": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "detail": {
            "type": "string"
          },
          "part": {
            "type": "string"
          },
          "scope": {
            "enum": [
              "styles",
              "numbering",
              "settings",
              "theme",
              "fontTable",
              "webSettings",
              "headersFooters",
              "sectionDefaults"
            ]
          }
        },
        "required": [
          "scope",
          "part"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "dryRun": {
      "type": "boolean"
    },
    "idMappings": {
      "additionalProperties": false,
      "properties": {
        "numbering": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "from": {
                "type": "string"
              },
              "kind": {
                "enum": [
                  "style",
                  "numbering",
                  "relationship"
                ]
              },
              "to": {
                "type": "string"
              }
            },
            "required": [
              "kind",
              "from",
              "to"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "relationships": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "from": {
                "type": "string"
              },
              "kind": {
                "enum": [
                  "style",
                  "numbering",
                  "relationship"
                ]
              },
              "to": {
                "type": "string"
              }
            },
            "required": [
              "kind",
              "from",
              "to"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "styles": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "from": {
                "type": "string"
              },
              "kind": {
                "enum": [
                  "style",
                  "numbering",
                  "relationship"
                ]
              },
              "to": {
                "type": "string"
              }
            },
            "required": [
              "kind",
              "from",
              "to"
            ],
            "type": "object"
          },
          "type": "array"
        }
      },
      "type": "object"
    },
    "skippedScopes": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "message": {
            "type": "string"
          },
          "part": {
            "type": "string"
          },
          "reason": {
            "enum": [
              "NOT_PRESENT_IN_SOURCE",
              "OUT_OF_SCOPE",
              "NO_CHANGE",
              "CAPABILITY_UNAVAILABLE"
            ]
          },
          "scope": {
            "type": "string"
          }
        },
        "required": [
          "scope",
          "reason",
          "message"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "source": {
      "additionalProperties": false,
      "properties": {
        "fingerprint": {
          "type": "string"
        },
        "kind": {
          "enum": [
            "path",
            "base64"
          ]
        },
        "partCount": {
          "type": "integer"
        }
      },
      "required": [
        "kind",
        "fingerprint",
        "partCount"
      ],
      "type": "object"
    },
    "success": {
      "const": true
    },
    "unsupportedItems": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "category": {
            "type": "string"
          },
          "part": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          }
        },
        "required": [
          "part",
          "category",
          "reason"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "warnings": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "message"
        ],
        "type": "object"
      },
      "type": "array"
    }
  },
  "required": [
    "success",
    "changed",
    "dryRun",
    "bodyPolicy",
    "source",
    "detectedScopes",
    "appliedScopes",
    "skippedScopes",
    "unsupportedItems",
    "changedParts",
    "idMappings",
    "warnings"
  ],
  "type": "object"
}
{
  "additionalProperties": false,
  "properties": {
    "failure": {
      "additionalProperties": false,
      "properties": {
        "code": {
          "enum": [
            "UNSUPPORTED_SOURCE",
            "INVALID_PACKAGE",
            "CAPABILITY_UNAVAILABLE",
            "UNSUPPORTED_TEMPLATE_CONTENT"
          ]
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "type": "object"
    },
    "success": {
      "const": false
    }
  },
  "required": [
    "success",
    "failure"
  ],
  "type": "object"
}