Save Unit Assets

Unit Assets store JSON settings and files. Use State for a single numeric or string value and Assets for structured settings or files. Assets use different APIs from site-record attachments.

Reads require Read permission for units; saves require Write permission. API authentication and access to the target Unit apply.

Create JSON content

POST /api/1/units/account-<Account ID>/assets
Authorization: Bearer <Account API Token>
Content-Type: application/json

{
  "filename": "site-a-dashboard.json",
  "content": { "title": "Site A", "threshold": 30 },
  "expectedETag": null
}

Success returns HTTP 201 with id, url, and etag. Choose filenames that are unique within the Account. Different Unit IDs do not guarantee independent storage for the same filename.

Use the read ETag to prevent overwrites

GET /api/1/units/{unit_id}/assets/{asset_id}?contentType=json returns the JSON body. Keep its ETag response header and pass it unchanged as expectedETag when updating. Updates use the same POST /api/1/units/{unit_id}/assets endpoint and the same filename as creation.

{
  "filename": "site-a-dashboard.json",
  "content": { "title": "Site A", "threshold": 32 },
  "expectedETag": "\"abc123\""
}

Replace abc123 with the actual ETag. The double quotes are part of the ETag and must be escaped inside JSON.

expectedETag: null allows creation only. Omitting it permits an unconditional save for ordinary User/API-key requests. Include it to protect an update from conflicts. On 409 asset_revision_conflict, retrieve the latest content and reconcile changes before saving.

Do not store API tokens or passwords in Assets readable by browsers. Use Account Secrets for execution secrets.