Save legal document
curl --request PUT \
--url https://api.example.com/api/v1/admin/legal/{slug}import requests
url = "https://api.example.com/api/v1/admin/legal/{slug}"
response = requests.put(url)
print(response.text)const options = {method: 'PUT'};
fetch('https://api.example.com/api/v1/admin/legal/{slug}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/admin/legal/{slug}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/admin/legal/{slug}"
req, _ := http.NewRequest("PUT", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.example.com/api/v1/admin/legal/{slug}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/admin/legal/{slug}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
response = http.request(request)
puts response.read_bodyLegal
Save legal document
Create or replace the Terms & Conditions or Privacy Policy.
PUT
/
api
/
v1
/
admin
/
legal
/
{slug}
Save legal document
curl --request PUT \
--url https://api.example.com/api/v1/admin/legal/{slug}import requests
url = "https://api.example.com/api/v1/admin/legal/{slug}"
response = requests.put(url)
print(response.text)const options = {method: 'PUT'};
fetch('https://api.example.com/api/v1/admin/legal/{slug}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/admin/legal/{slug}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/admin/legal/{slug}"
req, _ := http.NewRequest("PUT", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.example.com/api/v1/admin/legal/{slug}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/admin/legal/{slug}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
response = http.request(request)
puts response.read_bodyOverview
Writes a legal document in place. There is no create/delete pair here — the slug set is fixed, so this either writes the first revision of a document or replaces the existing one.Authentication
Bearer admin token. SUPER or MODERATOR only; FINANCE is read-only on this surface.Request body
{
"title": "Terms & Conditions",
"bodyHtml": "<h2>1. Acceptance of Terms</h2><p>By creating a Swappr account…</p>",
"effectiveAt": "2026-08-03T00:00:00.000Z",
"isPublished": true
}
| Field | Type | Notes |
|---|---|---|
title | string | 1–200 chars |
bodyHtml | string | 1–200,000 chars. Sanitized before storage — see below. |
effectiveAt | string | ISO-8601. Shown to users as “Last updated”. |
isPublished | boolean | false keeps it out of the public endpoints |
Sanitizing
bodyHtml is run through a fixed allowlist before it is written, so the stored value is always safe and readers never have to sanitize:
- Kept:
h1–h4,p,ul/ol/li,strong/b,em/i,u,a,br,hr,blockquote, and table tags. - Stripped:
<script>(and its contents),<style>,<iframe>,<img>, event handlers such asonclick,style/class/idattributes, and anyjavascript:ordata:URL. - Forced: every
<a>getsrel="noopener noreferrer". - Link schemes are limited to
http,https,mailto,tel.
400 VALIDATION_FAILED rather than saving an empty page.
Because sanitizing happens on write, the response body may differ from what you
sent. Always re-render the editor from the response rather than from your local
draft, or the admin will see markup that is not actually stored.
Versioning
version auto-increments only when the title or bodyHtml actually changed. Toggling isPublished or correcting effectiveAt deliberately does not bump it, so the number stays meaningful as a “has the wording changed?” signal.
Response — 200 OK
The saved document, in the same shape as the get endpoint.
Errors
| Status | Code | When |
|---|---|---|
400 | VALIDATION_FAILED | Bad slug, missing/over-length field, or a body left empty by sanitizing |
403 | FORBIDDEN | Caller is not SUPER or MODERATOR |
Audit
Alegal.saved audit row is written on success, recording the title, resulting version and publish state. The body itself is not stored in the audit log — it is far too large.
Seeding
A fresh environment is seeded with placeholder copy viapnpm seed:legal, which runs on every deploy. That seed is insert-only: once a document exists it is never touched again, so a deploy can never overwrite copy published through this endpoint.