Get table meta¶
Describes a table : the name and the type of every column (or of every field found in a MongoDB collection), in the same format for every database. Migration scripts use it to check whether a column exists before adding it.
| Method | POST |
| URL | /api/system-api/admin/get-table-meta : admin is the user path of your account |
| Body | { instance, database, collection } or an array of them |
| Answer | data : an array of fields, or an array of arrays |
| From code | g.sys.system.getTableMeta |
The call¶
Answer
{
"success": true,
"statusCode": 200,
"data": [
{ "name": "customer_id", "path": "customer_id", "count": 24, "total_count": 24, "type": "Number", "has_duplicates": false, "probability": 1 },
{ "name": "first_name", "path": "first_name", "count": 24, "total_count": 24, "type": [ "String", "Null" ], "has_duplicates": true, "probability": 1 }
]
}
| Key | Meaning |
|---|---|
name, path |
The column, with its path for nested MongoDB fields. |
type |
The type, or the list of types seen (MongoDB). |
count, total_count, probability |
For MongoDB, in how many of the sampled documents the field appears. |
has_duplicates |
Whether the same value appears twice in the sample. |
tableworks in place ofcollection. An array of tables answers an array of arrays, in the same order.- A table of a tenant :
"instance": "crm::acme", or the headerx-am-tenant-username.
From code¶
A migration which adds a column once
const meta = await g.sys.system.getTableMeta({ instance: 'mysql8', database: 'inventory', table: 'order_transactions' });
if (!meta.find(c => c.name === 'description')) {
await g.sys.system.executeQuery({ instance: 'mysql8', query: 'ALTER TABLE `inventory`.`order_transactions` ADD COLUMN `description` varchar(255) NULL' });
}
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, inx-am-authorization) orIS_PUBLIC. Without settings it isNO_ACCESS: your code calls it throughg.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. |
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. |