CodamAIDocs
Topicdone

Field selection with response

The response list decides what comes back, and it is mandatory. This page lists the possible entries and what happens when the list is missing or a field is unknown.

Variants
Field nameWildcardObject {field, response}excluderesponse missing → 400empty list → system fields onlyunknown field → silently ignoredobject on a simple field → ignoredpermissions apply per model, not per field

What this is about

Every request that returns data carries a response list. It tells CDMS which fields should be in the response. This applies to read, query, create, update, patch and rollback.

{
  "response": ["id", "firstname", "+", { "field": "company", "response": ["companyname"] }],
  "exclude": ["internalNote"]
}

The three kinds of entries

An entry in response is either a text or an object:

flowchart TB
    E["Entry in response"] --> T{"Text or object?"}
    T -->|"Text without + and *"| F["Field name<br/>exactly this simple field"]
    T -->|"Text with + or *"| W["Wildcard<br/>many fields at once"]
    T -->|"Object { field, response }"| O["Expand a reference<br/>with its own field selection"]
EntryExamplereturns
Field name"firstname"exactly this simple field
Wildcard"+", "*", "+name", "depart*"all matching fields, see Wildcards
Object{ "field": "company", "response": ["companyname"] }the reference company with its own field selection

Next to response there is also the exclude list. It removes fields again that a wildcard added.

The object in detail

An object expands a reference. It has up to four keys:

KeyRequiredMeaning
fieldyesname of the reference in the model, e.g. company or employees
responseyesfield selection for the referenced object, with the same three kinds of entries
excludenoas above, but only for this level
parameternolists only: filter, sorting, page size for the entries of the list

Because response inside the object may contain objects again, you can nest as deep as you like. How that works is described under Expanding references and lists.

Example on the employee model

The same model as on the other pages of this chapter: employee with firstname, lastname and the references company and department.

Field name, wildcard and object mixed
Request
POST /api/rest/hr/employee/read/7f3…
{
  "response": [
    "firstname",
    "+name",
    { "field": "company", "response": ["companyname"] }
  ]
}
Response
{
  "data": {
    "id": "7f3…",
    "firstname": "Daniel",
    "lastname": "Mertins",
    "company": { "id": "a1…", "companyname": "Codamic AG" },
    "department": null
  },
  "meta": { "error": false }
}

firstname appears twice, once as a name and once through +name. That does no harm, CDMS reads every field only once.

What CDMS does with unusual entries

Special cases in response

When: The body is {} or contains only exclude.

  1. 1
    Client→CDMS
    sends POST /read/{id} without response
  2. 2
    CDMS→Client
    400 InvalidQueryDefinitionException with messageKey response

Result: 400. The same applies to an object { "field": … } without its own response.

When: { "response": [] }

An empty list is allowed. CDMS then reads only what it always reads: id, _createdOn and _updatedOn.

Result: 200 with the system fields, everything else null. Handy when you only want to know whether the object exists and you may see it.

When: You write "fristname" instead of "firstname", or the field does not exist in this model.

  1. 1
    CDMS
    finds no column for the name
  2. 2
    CDMS
    leaves the entry out, without an error
  3. 3
    CDMS→Client
    returns all other fields

Result: 200. The misspelled field is simply missing, the correct one is null.

When: { "field": "firma", "response": ["+"] }, but the reference is called company.

CDMS does not find firma in the model and skips the whole object.

Result: 200 without this reference.

When: { "field": "firstname", "response": ["+"] }

firstname is not a reference and cannot be expanded. CDMS skips the object.

Result: 200, and firstname is not returned. Name it as text.

When: The response reaches into company, the user lacks company-read.

  1. 1
    CDMS
    checks the read role of company while expanding
  2. 2
    CDMS→Client
    403 missing-permission|company-read

Result: 403 for the whole request, not just for the reference.

Decision table

What happens to an entry?
Entryexists in the modelread role of the target modelResult
response missing––400 response
Field nameyes–field is returned
Field nameno–silently left out, 200
Wildcard––all matching fields, no match is 200 too
Object on a referenceyesyesreference with its own field selection
Object on a referenceyesno403 missing-permission|<role>
Object on a referenceno–silently skipped, 200
Object on a simple fieldyes–silently skipped, 200

Permissions: per model and per relation

CDMS decides whether you may read something per model and per relation. Whoever may read employee may read the simple fields of employee, unless a field carries a read role of its own: then + leaves it out without this role, and requesting it by name results in 403. See Protected values. A role only comes into play when the response reaches into another model: then you need its read role or a role on the relation itself. See Model roles and Permissions on relations.

The tables above describe the default, strict mode. Without it, a single reference without the role is silently null; the other cases still fail, only with a different status or key. See Strict mode.

Pitfalls

Sources in the code and the knowledge base
  • CDMS/cdms-rest-api – Expander, ReadPayload, ModelResponse, ResponseDeserializer
  • CDMS/cdms-persistence-database – SelectionBuilder.getBaseField
  • documentation/20-api/03-response-requests.md
Search