Skip to content
This page View Markdown Open in ChatGPT Open in Claude

Is valid data for table

Runs the schema of a table on some data without writing anything, and answers the list of errors a save (or an update) would have refused it with. Empty list : the data is fine.

Method POST
URL /api/system-api/admin/is-valid-data-for-table : admin is the user path of your account
Body { instance, database, collection | table, data, sendingTo? } or an array of them
Answer data : an array of errors (empty when valid), or an array of arrays
From code g.sys.system.isValidDataForTable

The call

Body
{
    "instance": "mongodb", "database": "shop", "collection": "products",
    "data": { "name": "M", "currency": "EUR", "price_cents": -5, "contact_email": "[email protected]" }
}
Answer
{
    "success": true,
    "statusCode": 200,
    "data": [
        { "type": "schemaKeyNotFound", "field": "contact_email", "message": "Property not found in schema for key 'contact_email'.", "code": 400 },
        { "type": "minLength", "field": "name", "message": "Property 'name' should have minimum length of '2'.", "code": 400 },
        { "type": "enumValidation", "field": "currency", "message": "Property 'currency' should have any value from [IN, US, GB].", "code": 400 },
        { "type": "min", "field": "price_cents", "message": "Please provide minimum '0' for 'price_cents' field.", "code": 400 }
    ]
}
Key Meaning
instance, database, collection or table The table whose schema is used. A table without a schema is refused.
data One object, or an array of objects : then the answer is an array of error lists, one per object.
sendingTo SAVE (default) : required fields must be there. UPDATE : only the fields present are checked, the way update by id checks them.
  • The call is success: true even when the data is not : the errors are the answer, not a failure of the call.
  • An array of bodies checks several tables in one call.

From code

const errors = await g.sys.system.isValidDataForTable({ instance: 'mongodb', database: 'shop', collection: 'products', data: g.req.body, sendingTo: 'SAVE' });
if (errors.length) { g.res.statusCode = T.EStatusCode.BAD_REQUEST; return errors; }
  • Useful for a wizard which validates each step before the final save, or for an import which reports every bad row before writing any.

Access and settings

  • Over HTTP, a system API answers once its settings give it apiAccessType: TOKEN_ACCESS (the token of an API user whose group grants this system API, in x-am-authorization) or IS_PUBLIC. Without settings it is NO_ACCESS : your code calls it through g.sys, the admin panel tests it, and an HTTP call is refused.
  • The settings can also cache the answer or require person tokens (authProviders) ; pre and post hooks run around it like around any API.
  • The request headers apply : x-am-response-case, x-am-content-type-response, x-am-internationalization, x-am-tenant-username…

Errors

Code When
400 The body is wrong : the message names the missing or invalid key, Unable to find schema for … for a table without a schema.
401 No valid API user token, or the API is NO_ACCESS : You are not authorized to access this API.
403 No group grants this system API.