Purchase orders
Save the legacy Word template markup
/a/PurchaseOrders_templateWordSet
Rewrite selected legacy HTML constructs and save po-template-word.
When to use this endpoint
Use the CRM1 Purchase Order Word settings editor’s Save behavior. This stores account markup; it does not upload a Word binary, generate a PDF or change an order’s selected form.
Authentication and permissions
Authenticate with signed API-key fields or a logged-in CRM session. Session requests use dispatcher CSRF protection when configured. API keys use their owner’s identity.
Client-administrator access is required; the saved markup is account-wide. A signed key must belong to an administrator.
The dispatcher also requires Purchase Order View and Edit. The setting write is checked and audited in the tenant transaction.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
template | Markup string | Yes | The complete replacement markup. Missing/null fails. After the rewrites, PHP-falsy content (including empty string and "0") fails; whitespace-only content is not trimmed away. |
Example request
$result = FM_api('PurchaseOrders_templateWordSet', [
'template'=>'<p>Purchase order {{Order No}}</p>',
]);
Example response
{
"ok": 1
}
Errors and unusual responses
| Response | Condition |
|---|---|
{"error":"not logged in"} | No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs. |
{"error": "missing or invalid parameter: template"} | template is absent/null. |
{"error": "you are not an admin"} | Client-admin check fails. |
{"error": "Could not save template as it is empty or not fully uploaded"} | The rewritten value is PHP-falsy. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Requires client administrator plus Purchase Order View/Edit. Writes are checked under the tenant-owner transaction, with audit history, Unix cdate and cache invalidation after commit. A failed write returns an error; an unchanged value returns ok without a new audit.
- Requires authenticated tenant context and client-administrator access. No order ID or partial template patch exists; the supplied string replaces the account value.
- Repeatedly renames script tags to noscriptsallowed, iframe tags to noiframesallowed, meta tags to nometasallowed and matching inline on…= attributes by prefixing notallowed. Other markup, links and merge-code text remain. Only these targeted rewrites are implemented.
Side effects
- Replaces the tenant template setting atomically with audit history and cache invalidation. Does not modify orders, render a document or send email.
See it in Fieldmotion
CRM1
In CRM1 Purchase Order Word settings, edit the preview/CKEditor content. The page strips tabs/newlines from preview HTML before calling PurchaseOrders_templateWordSet.
CRM2
No direct CRM2 literal caller was found in the searched client source.
Related endpoints
PurchaseOrder_getPdf— Render the current order document from its selected form.PurchaseOrder_setForm— Select the modern type-5 order form.