Trax Platform APIv1

Duda websites

An organization's website is a Duda website or an nFocus site (see Building an nFocus site); this guide is about Duda. Each organization website built in Duda is registered as a site: bound to one portal, with its own origins and keys (see Authentication and keys). nFocus support creates the site from a curated template (in the admin app, or the organization site's POST /v1/manage/sites), and the API writes these values into the site's Content Library.

Values a site keeps in its Content Library

Custom text Value
trax_api The API base URL (no trailing slash)
trax_client The client token
trax_org The org token
trax_site_key The site's publishable key (pk_…)

Widgets

A custom widget reads those values and calls the API with the publishable key. In the Duda editor (data.inEditor), show placeholder content instead of calling the API.

const lib = await dmAPI.loadContentLibrary();
const text = (label) => (lib.site_texts.custom.find((t) => t.label === label) || {}).text;
const base = `${text('trax_api')}/v1/portals/${text('trax_client')}/${text('trax_org')}`;

const response = await fetch(`${base}/activities?age=8&pageSize=12`, {
  headers: { 'X-Trax-Site-Key': text('trax_site_key') },
});
const page = await response.json();
for (const listing of page.items) {
  console.log(listing.name, listing.fee.text, listing.availabilityLabel);
}

External collections

Collections give Duda a flat list it renders into dynamic pages, which search engines can index. Each row has a slug to use as the page URL field.

Collection Name in Duda URL
Activities trax_activities /v1/portals/{clientToken}/{orgToken}/collections/activities
Memberships trax_memberships /v1/portals/{clientToken}/{orgToken}/collections/memberships
Posts (blog and news) trax_posts /v1/portals/{clientToken}/{orgToken}/collections/posts
Staff trax_staff /v1/portals/{clientToken}/{orgToken}/collections/staff
Locations trax_locations /v1/portals/{clientToken}/{orgToken}/collections/locations (each location's stored slug; also roleLine, description, photoUrl, photoAlt, latitude, longitude, layout)

Template collections

A Duda external collection is a list of rows that Duda reads from a URL and turns into pages: a page template designed once, and one page per row (one page per post, per staff member, per activity). In a Trax template, the designer builds those pages and binds their elements to the row fields above (title, summary, imageUrl, publishedDate, and so on).

Every site made from the template gets a copy of its collections, including the URL and key the template used. That URL would be wrong for every site: each site must read its own portal's feed with its own secret key. When nFocus support creates a site, the API therefore reconnects each collection on the new site:

That is why the names must match exactly. A collection named, say, posts or Trax Posts is never found, so the site keeps the template's URL and never shows its own posts. The same lookup by name drives the refreshes described below.

When a site switches template, the new template brings its own collections and Content Library, so the API repeats these steps with fresh keys and revokes the keys they replace. If a designer adds a collection to a template later, a Site Admin reconnects the site's collections with POST /v1/manage/sites/{siteId}/duda/collections.

To build a template's collections:

  1. Create each external collection with a name from the table. For its URL, use the matching feed of any test portal, with that portal's secret key; the API replaces both for every real site.
  2. Set the page URL field to slug.
  3. Design the item page and the list sections, binding to the fields of each row.

Collections need the site's secret key. Through Duda's Partner API, send it as the authorization header value Bearer sk_…. In the Duda editor, where only a URL can be entered, add ?key=sk_….

Activities as a Duda collection

GET https://api.nfocus.solutions/v1/portals/riverbend/north/collections/activities → 200 OK, JSON

curl
curl -s 'https://api.nfocus.solutions/v1/portals/riverbend/north/collections/activities' \
  -H 'Authorization: Bearer sk_your_secret_key'
JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/portals/riverbend/north/collections/activities', {
  headers: {
    'Authorization': 'Bearer sk_your_secret_key',
  },
});
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/north/collections/activities");
request.Headers.Authorization = new("Bearer", "sk_your_secret_key");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();

Activity rows carry ready-to-bind text: dates, days, times, ages, fee, availabilityLabel. Numbers are there too: feeCents, and spotsLeft, which is -1 when the activity has no capacity limit. detailsUrl points to the full activity in this API.

Duda caches external collections for up to about two hours. When staff change posts, staff profiles or locations in the organization site, the API asks Duda to refresh that collection within seconds. For a scheduled post, it asks again when the post goes up and when it comes down.

Posts as a Duda collection

GET https://api.nfocus.solutions/v1/portals/riverbend/north/collections/posts → 200 OK, JSON

curl
curl -s 'https://api.nfocus.solutions/v1/portals/riverbend/north/collections/posts' \
  -H 'Authorization: Bearer sk_your_secret_key'
JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/portals/riverbend/north/collections/posts', {
  headers: {
    'Authorization': 'Bearer sk_your_secret_key',
  },
});
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/north/collections/posts");
request.Headers.Authorization = new("Bearer", "sk_your_secret_key");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();