Skip to content

Is valid data for table api

  • This API is used to check the given data fields are as per the database schema, and it has valid values or not.

Request Method: POST

URL

/api/system-api/user-path/is-valid-data-for-table

Request payload

{
    "first_name": 86,
    "last_name": "Martin",
    "phone": 7894561265,
    "contact_email": "example@example.com"

}

Validate table data

Test data valid or not using global object 'g'.

1
2
3
4
5
6
7
8
9
await g.sys.system.isValidDataForTable({
    instance: "INSTANCE_NAME",
    database: "DATABASE_NAME",
    collection: "COLLECTION_NAME",
    data: {
        "field": "fieldValue",
        "field": "fieldValue"
    }
});
await g.sys.system.isValidDataForTable({
    instance: "mongoDB",
    database: "db_inventory",
    collection: "tbl_customers",
    data: {
        "customer_id": 1,
        "first_name": "Bob",
        "last_name": "Lin",
        "last_update": "2006-02-14T23:04:33.000Z",
        "pincode": 382330,
        "isActive": 1
    }
});

API Response

{
    "success": true,
    "statusCode": 200,
    "data": [
        {
            "type": "schemaKeyNotFound",
            "field": "contact_email",
            "message": "Property not found in schema for key 'contact_email'.",
            "code": 400
        },
        {
            "type": "required",
            "field": "first_name",
            "message": "Please provide valid 'first_name' field with type 'string'.",
            "code": 400
        }
    ]
}