Trax Platform APIv1

Building an nFocus site from a template

An nFocus site's pages come from a template that nFocus owns. The public portal has the template's code (its pages, layout and components); the API has the template's schema and each site's content for it. This guide covers what the public portal reads to render a site, and what the organization site edits.

Templates and versions

A template has a stable key (community-hub, youth-center) and numbered versions.

The schema

GET /v1/manage/sites/{siteId}/website returns the draft's schema; GET /v1/manage/sites/{siteId}/templates lists the templates a site can use, with each version's pages and sections, and the template's thumbnail (thumbnailUrl and thumbnailAltText) once nFocus uploaded one. nFocus adds templates and versions, and previews a version's sample content, in the admin app (see nFocus admin, "Templates").

The templates an nFocus site can use

GET https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/templates → 200 OK, JSON

curl
curl -s 'https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/templates' \
  -H 'Authorization: Bearer your_keycloak_access_token'
JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/templates', {
  headers: {
    'Authorization': 'Bearer your_keycloak_access_token',
  },
});
const data = await response.json();
C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/templates");
request.Headers.Authorization = new("Bearer", "your_keycloak_access_token");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();

Field types

Type Value Limits
text One line of plain text max characters
paragraphs Plain text; paragraphs separated by a blank line (\n\n) max characters
url https://…, or a path on the site starting with / (/#outcomes) 500 characters
email, phone Plain text
image A media id from the site's library (alt text is required there) aspect (w:h), tolerance, minWidth
boolean true or false
choice One of the field's options values
number A whole number min, max
list An array of objects with the list's fields minItems, maxItems
ref { "kind": …, "id": "…" }: a location, staff, post, service, organization content, sponsorship, video, contact, catalog activity or program kinds
cta A button: { "kind", "label", "url" (link), "target" (register) } kinds

No field holds HTML: text is shown as text. A button's kind is one of register (the catalog, or one activity or program as its target), donate (the donation flow), call, email, directions (the organization's own phone, email and address) and link (its url, with its own label).

Section types

The section type says which component renders it. Its fields are the words and settings the organization writes for it (headings, introductions, buttons). Sections that show the organization's items read them from the website's public endpoints, as the organization keeps them:

Section type Shows
header, footer The logo (branding), the organization's name, address, phone and social links (GET P/site), and the fields' buttons
hero, textBlock, ctaBand Their own fields. On a location page, the hero is the location (GET P/locations/{slug}), and a ctaBand its buttons
locationCards, locationDirectory, map The locations (GET P/locations), with the services each offers (GET P/services, for the directory's filter)
posts, announcements GET P/posts, GET P/announcements
serviceGrid, programCards Service categories and services (GET P/services); on a location page, the location's services
weeklySchedule GET P/schedules (the site's own, or ?location= on a location page)
outcomes, impactNumbers, values, pathways, quote, sponsorships GET P/content (the site's own, or ?location= on a location page)
videos The videos its videos list names (up to six), or, left empty, the site's published videos (GET P/videos)
contacts The contacts its contacts list names (up to twelve), or, left empty, the site's public contacts (GET P/contacts)

A section whose items come from a capability the organization turned off is left out of GET P/website, and a reference to an item of one resolves to nothing.

The published website

GET P/website is public (a site key is optional) and answers for an nFocus site that has published its website.

An nFocus site's published website

GET https://api.nfocus.solutions/v1/portals/riverbend/central/website → 200 OK, JSON

curl
curl -s 'https://api.nfocus.solutions/v1/portals/riverbend/central/website'
JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/portals/riverbend/central/website');
const data = await response.json();
C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.nfocus.solutions/v1/portals/riverbend/central/website");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();

Caching

The answer carries Cache-Control: public, max-age=60, stale-while-revalidate=300 and a strong ETag. Send the ETag back in If-None-Match and an unchanged website answers 304 Not Modified with no body. A publish shows within about a minute.

Previews

The organization site makes a preview link (POST …/website/preview-link), which points at GET P/website?preview={token} and works for one hour on that site only. A preview answers the draft, with "preview": true, Cache-Control: no-store and X-Robots-Tag: noindex, nofollow: render it the same way and never cache it. A wrong or expired token serves the published website.

Editing a website

The organization site edits a site's website in two stages, a draft and the published version (see Organization site, "An nFocus site's website"):

The website draft, its schema and what blocks publishing

GET https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website → 200 OK, JSON

curl
curl -s 'https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website' \
  -H 'Authorization: Bearer your_keycloak_access_token'
JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website', {
  headers: {
    'Authorization': 'Bearer your_keycloak_access_token',
  },
});
const data = await response.json();
C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website");
request.Headers.Authorization = new("Bearer", "your_keycloak_access_token");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();

Saving a draft someone else changed

PUT https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website/draft → 412, problem details

curl
curl -s -X PUT 'https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website/draft' \
  -H 'Authorization: Bearer your_keycloak_access_token' \
  -H 'If-Match: "stale"' \
  -H 'Content-Type: application/json' \
  -d '{"branding": {"colors": {"primary": "#c62828"}}}'
JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website/draft', {
  method: 'PUT',
  headers: {
    'Authorization': 'Bearer your_keycloak_access_token',
    'If-Match': '"stale"',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"branding": {"colors": {"primary": "#c62828"}}}),
});
const data = await response.json();
C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Put, "https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website/draft");
request.Headers.Authorization = new("Bearer", "your_keycloak_access_token");
request.Headers.Add("If-Match", ""stale"");
request.Content = new StringContent("""
    {"branding": {"colors": {"primary": "#c62828"}}}
    """, System.Text.Encoding.UTF8, "application/json");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();

Colours and contrast

Each colour slot names the pairs it is used in: against a fixed colour (#ffffff) or another slot, at level text (4.5:1) or large (3:1, large text and controls), WCAG 2.2's ratios. A colour that fails is refused when it is saved, with an error that names the pair and the ratio it reached:

{
  "code": "invalid-request",
  "errors": { "branding.colors.primary": ["White text on primary buttons: the contrast is 2.38:1; it needs at least 4.5:1."] }
}

When a site changes a colour that another slot is checked against (a light band behind text), the error names the colour the site changed.