Skip to main content

Custom Fields

Read a tenant's custom fields and the records users hold against them — for example, to sync licence expiry dates or compliance documents into your own systems. The model has three parts:

  • Custom field (user_field in the API) — the field definition: its name, kind (text, date, file, licence, …) and which tab it appears on
  • Assignment — whether a given user has the field, and whether it's editable, read-only or hidden for them
  • Record — a value a user holds for a field. A field can accumulate many records over time; the current record is the active one, and it carries the compliance status (valid / expired / expiring soon)

API endpoints:

note

This example assumes you already have an access_token — see Authentication — and the user_id of the user you're reading. You can find user IDs with List Users or Get Users by Email.

Read custom fields​

Page through every custom field defined in your account. Each field has an id (used everywhere below as user_field_id), a name and a kind.

import httpx

BASE = "https://your-account.wyzed.com/v3_compliance/tenants"

# UserField schema: https://compliance-dot-wyzed-app.appspot.com/docs#/schemas/UserFieldDTO
user_fields = []
cursor = None
while True:
params = {"limit": 100}
if cursor:
params["cursor"] = cursor

response = httpx.get(
f"{BASE}/{tenant_id}/user_fields/",
headers={
"Authorization": f"Bearer {access_token}",
},
params=params,
)
response.raise_for_status()

# Response shape: {"user_fields": [...], "more": true, "next_cursor": "..."}
data = response.json()
user_fields.extend(data["user_fields"])

if not data["more"]:
break
cursor = data["next_cursor"]

print(f"found {len(user_fields)} custom fields")
for field in user_fields:
print(f"- [{field['id']}] {field['name']} ({field['kind']})")

Read assignments​

Custom fields are organised into tabs, and fields are assigned per user — one user might have a "Driver's Licence" field while another doesn't. The assigned-fields endpoint returns, for one user and one tab, each assigned field together with the user's current record for it.

user_id = 123

# 1. Read the tabs. Response shape: {"tabs": [{"id": ..., "name": ..., ...}]}
response = httpx.get(
f"{BASE}/{tenant_id}/tabs/",
headers={
"Authorization": f"Bearer {access_token}",
},
)
response.raise_for_status()
tabs = response.json()["tabs"]

# 2. Read the user's assigned fields on each tab
# AssignedField schema: https://compliance-dot-wyzed-app.appspot.com/docs#/schemas/AssignedFieldDTO
for tab in tabs:
response = httpx.get(
f"{BASE}/{tenant_id}/users/{user_id}/assigned_fields/",
headers={
"Authorization": f"Bearer {access_token}",
},
params={"tab_id": tab["id"]},
)
response.raise_for_status()
assigned_fields = response.json()["assigned_fields"]

print(f"tab '{tab['name']}':")
for assigned in assigned_fields:
field = assigned["user_field"] # the field definition
record = assigned["current_record"] # the user's current record
status = record["status"]

# assignment_type: EDITABLE | READ_ONLY | HIDDEN | NOT_APPLICABLE
print(
f"- {field['name']}: {assigned['assignment_type']}, "
f"valid={status['is_valid']}, expired={status['is_expired']}, "
f"expiring_soon={status['is_upcoming']}"
)

A record with "is_valid": false is what shows as a compliance alert in Wyzed — for example a required field with no value, or an expired licence.

Read a user's current record for a custom field​

If you already know the field you care about, read the user's current record for it directly:

user_field_id = 456 # the custom field's "id" (see "Read custom fields" above)

# Record schema: https://compliance-dot-wyzed-app.appspot.com/docs#/schemas/RecordDTO
response = httpx.get(
f"{BASE}/{tenant_id}/records/current/{user_id}/{user_field_id}",
headers={
"Authorization": f"Bearer {access_token}",
},
)
response.raise_for_status()
record = response.json()
note

If the user has never held a record for the field, this endpoint doesn't 404 — it returns an initial record with "id": null and the field's default value (or a null value).

The record's value object varies by field kind — switch on value["kind"]:

def record_body(record: dict) -> dict:
"""Extract the content of a record, depending on its value kind."""
value = record["value"]
if value is None:
return {} # no value recorded yet
kind = value["kind"]

if kind == "TEXT":
return {"content": value["content"]}
elif kind == "DATE":
return {"date": value["value"]}
elif kind in ("SINGLE_CHOICE", "MULTIPLE_CHOICE"):
# Choice IDs — resolve them to names with the Read Choice List
# endpoint: GET /v3_compliance/tenants/{tenant_id}/user_fields/{user_field_id}/choices/
ids = [value["choice_id"]] if kind == "SINGLE_CHOICE" else value["choice_ids"]
return {"choice_ids": ids}
elif kind == "LICENCE":
# Expiry date, an optional reference number, and an optional
# attached file (see "Download a custom field file" below).
return {
"expires_at": value["expires_at"],
"reference": value["reference"],
"file": value["file"],
}
elif kind == "FILE":
# An uploaded file: {"id": ..., "filename": ..., "content_type": ..., "size": ...}
return {"file": value["file"]}
elif kind == "FILE_GROUP":
# A list of file IDs — each downloads the same way as a FILE.
return {"file_ids": value["file_ids"]}
elif kind == "DOC":
return {"url": value["url"]}

# Other kinds (EMBED_CODE, USER_ID, TRAINING_EVENT) — see the RecordDTO
# schema for their fields.
return {}

Download a custom field file​

FILE and LICENCE record values carry a file object whose id is a File ID. Custom field record files are stored in the folder users/{user_id}/user_fields/{user_field_id}. Downloading is two steps: create a download URL using the file ID and folder, then issue a GET request to that URL.

# A file from a FILE or LICENCE record value (see "record_body" above)
file = record["value"]["file"]

# 1. Create a download URL for the file
response = httpx.get(
f"https://your-account.wyzed.com/v3_file/tenants/{tenant_id}/files/{file['id']}/download_url",
headers={
"Authorization": f"Bearer {access_token}",
},
params={
"folder": f"users/{user_id}/user_fields/{user_field_id}",
},
)
response.raise_for_status()
download_url = response.json()["url"]

# 2. Download the file from that URL
response = httpx.get(download_url, follow_redirects=True, timeout=300)
response.raise_for_status()
with open(file["filename"], "wb") as f:
f.write(response.content)

For FILE_GROUP records, value["file_ids"] is a list of File IDs — download each one the same way (fetch the filename first with the Read File ↗ endpoint if you need it).

note

Download URLs are only valid for a short time (the response's expires_in_seconds tells you how long) — create them when you're ready to download, and don't store them.