Skip to content

System APIs

Encrypt data

Encrypt System API

Get encrypted data using global object 'g'.

let encryptedData = await g.sys.system.encrypt({
    "data": {
        "name": "Bob"
    }
});

Decrypt data

Decrypt System API

Get decrypted data using global object 'g'.

let decryptedData = await g.sys.system.decrypt("U2FsdGVkX191c+lmyM80ctf4QV18dZ/x17yDh/fRxs4=");

Hash data

Hash System API

Get hash of the given data using the global object 'g'.

let hashData = await g.sys.system.hash({ "Name": "Alice" });

Get token

Get token using global object 'g'.

  • Get Token of API Maker's API_user.
1
2
3
4
5
6
7
await g.sys.system.getToken({
    "authTokenType": "AM",
    "authTokenAM": {
        "u": "USER_NAME",
        "p": "USER_PASSWORD"
    }
});
  • Get Token of database_user (application user).
await g.sys.system.getToken({
    "authTokenType": "AM_DB",
    "authTokenAMDB": {
        "instance": "INSTANCE_NAME",
        "database": "DATABASE_NAME",
        "collection": "COLLECTION_NAME",
        "usernameColumn": "USER_NAME_COLUMN",
        "passwordColumn": "USER_PASSWORD_COLUMN",
        "u": "USER_NAME",
        "p": "PASSWORD"
    }
});

Execute query

Execute query System API

Execute database query using global object 'g'.

1
2
3
4
5
6
await g.sys.system.executeQuery({
    instance: 'INSTANCE_NAME',
    database: 'DATABASE_NAME',
    collection: 'COLLECTION_NAME',
    query: "select * from DATABASE_NAME.COLLECTION_NAME"
});
  • If the database is Mongodb API Maker supports other query fields like, 'find', 'sort', 'skip', 'limit', and 'select'.
await g.sys.system.executeQuery({
    instance: 'INSTANCE_NAME',
    database: 'DATABASE_NAME',
    collection: 'COLLECTION_NAME',
    query: {
        find: {
            "column_name": "value"
        },
        sort: "column_name",
        skip: 3,
        limit: 5,
        select: "column_name with comma sparator",
    }
});

How we use Native Query in API Maker.

Native query using secret management

  • Set Database constrain in Secret management.

    import * as T from 'types';
    
    let Secret: T.ISecretType | any = {
    // Place your keys here in json format.
        common: <T.ISecretTypeCommon>{
            dbConstrain: {
                instance: 'mysql',
                database: 'inventory',
                collection: ''
            }
        }
    };
    module.exports = Secret;
    

  • Get Database constrain from Secret management.

    1
    2
    3
    4
    let dbConstrain = await g.sys.system.getSecret('common.dbConstrain');
    let instance = dbConstrain.instance || 'mysql';
    let database = dbConstrain.database || 'inventory';
    let collection = dbConstrain.collection || 'employees';
    

  • Create table

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: `${instance}`,
        query: `CREATE TABLE ${database}.${collection}(emp_id int AUTO_INCREMENT PRIMARY KEY);`
    });
    

Various types of Database & It`s Native Query In API Maker

  • MySQL | TiDB | Percona XtraDB

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "SELECT * FROM inventory.employees;"
    });
    

  • MariaDB

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mariadb",
        query: "SELECT * FROM inventory.employees;"
    });
    

  • Microsoft SQL Server

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "sqlserver",
        query: "SELECT * FROM inventory.dbo.employees;"
    });
    

  • MongoDB

    await g.sys.system.executeQuery({
        instance: "mongodb",
        database: 'am_cloud',
        collection: 'orders',
        query: {
            find: {
                "pro_name": "Oil"
            },
            sort: "created_at",
            skip: 3,
            limit: 5,
            select: "order_id,order_price,pro_name,created_at",
        }
    })
    

  • Oracle

Please follow these rules when writing a query or statement:

  • Use backticks (`) to enclose your query or statement.
  • Do not add a semicolon (;) at the end of your query.
1
2
3
4
await g.sys.system.executeQuery({
    instance: "oracle",
    query: `SELECT * FROM "INVENTORY"."employees"`
});

DDL Operation in API Maker

  • CREATE TABLE

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "CREATE TABLE inventory.employees(id int AUTO_INCREMENT PRIMARY KEY);"
    })
    

  • ALTER TABLE

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "ALTER TABLE inventory.employees ADD COLUMN emp_name VARCHAR(30) NOT NULL;"
    })
    

  • RENAME TABLE

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "ALTER TABLE inventory.employees RENAME COLUMN id TO emp_id;"
    })
    

  • TRUNCATE TABLE

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "TRUNCATE TABLE inventory.employees;"
    })
    

  • DROP TABLE

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "DROP TABLE IF EXISTS inventory.employees;"
    })
    

DML Operation in API Maker

API Maker allows us to perform various DML operations, such as the following examples.

  • INSERT

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "INSERT into inventory.employees Values(101, 'Bob', 'M');"
    })
    

  • DELETE

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "DELETE FROM inventory.employees WHERE emp_Id = '101';"
    })
    

  • UPDATE

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "UPDATE inventory.employees SET emp_Name = 'Alice' WHERE emp_Id = '101';"
    })
    

DQL Operation in API Maker

API Maker allows us to perform various DQL operations, such as the following examples.

  • SELECT

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "SELECT * FROM inventory.employees;"
    })
    

  • DISTINCT

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "SELECT DISTINCT emp_Name FROM inventory.employees;"
    })
    

  • ORDER BY

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "SELECT * FROM inventory.employees order by emp_Gen,emp_Name;"
    })
    

Aggregated Function in API Maker

API Maker allows us to perform various Aggregated Function, such as the following examples.

  • SUM

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "SELECT SUM(emp_Sal) as Total_Salary FROM inventory.employees;"
    })
    

  • AVG

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "SELECT AVG(emp_Sal) as Average_Salary FROM inventory.employees;"
    })
    

Joins in API Maker

API Maker allows us to perform Joins, such as the following examples.

  • INNER JOIN

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "SELECT * FROM inventory.employees INNER JOIN inventory.attandance ON inventory.employees.emp_Id = inventory.attandance.emp_id;"
    })
    

  • LEFT JOIN

    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "mysql",
        query: "SELECT * FROM inventory.employees LEFT JOIN inventory.attandance ON inventory.employees.emp_Id = inventory.attandance.emp_id;"
    })
    

How to call SQL Server Store Procedure

  • Just replace your procedure name with below "procedureName".
    1
    2
    3
    4
    await g.sys.system.executeQuery({
        instance: "sql_server",
        query: "USE inventory; exec dbo.procedureName;"
    });
    

Call external API

Call external API using global object 'g'.

Simple call external apis

1
2
3
4
5
6
7
8
9
await g.sys.system.callExternalApi([
    {
        "url": `your_url`,
        "method": "GET",
        "timeout": 5000,
        "queryParams": { "select": "first_name" },
        "headers": { "x-am-authorization": "TOKEN" },
    }
]);

Parallel type

  • If the type is 'parallel' the external APIs are executed in parallel.
await g.sys.system.callExternalApi([
    {
        url: "FULL_URL",
        method: "POST",
        body: [
            {
                first_name: "James",
                last_name: "Bond"
            }
        ],
        id: "saveApi",
        postProcess: [
            {
                from: "saveApi.output.data.first_name",
                to: "setApi.body.first_name"
            }
        ],
        queryParams: {
            deep: JSON.stringify([{
                s_key: "SOURCE_COLLECTION_COLUMN_NAME",
                t_key: "TARGET_COLLECTION_COLUMN_NAME",
                t_col: "TARGET_COLLECTION_NAME",
                select: "COLUMN_NAMES"
            }]),
            select: "COLUMN_NAMES",
            limit: 2,
            sort: "COLUMN_NAMES"
        },
        timeout: 1000,
        headers: { "x-am-authorization": "TOKEN" },
    },
    {
        type: 'parallel',
        data: [
            {
                url: "FULL_URL",
                method: 'PUT',
                body: {},
                id: "setApi",
                headers: { "x-am-authorization": "TOKEN" }
            },
            {
                url: "FULL_URL",
                method: 'GET',
                headers: { "x-am-authorization": "TOKEN" }
            }
        ]
    }
]);

Sequential type

  • If the type is 'sequential' the API calls execute one by one.
await g.sys.system.callExternalApi([
    {
        url: "your_url",
        method: "GET",
        timeout: 5000,
        queryParams: { "select": "first_name" },
        headers: { "x-am-meta": true },
        id: "getData",
        output: "any"
    },
    {
        type: "sequential",
        data: [
            {
                url: "your_url",
                method: "POST",
                body: {},
                id: "addData",
                preProcess: [
                    {
                        from: "getData.output.data",
                        to: "addData.body"
                    }
                ],
                headers: { "x-am-authorization": "TOKEN", "x-am-response-case": "capitalCase" }
            },
            {
                url: "your_url",
                method: "GET",
                headers: { "x-am-response-case": "capitalCase" }
            }
        ]
    }
]);

Get secret key/keys

Get secret System API

Get secret using global object 'g'.

  • Get only one secret key value.
await g.sys.system.getSecret("common.secret");
  • Get multiple secret keys values.
await g.sys.system.getSecret(["common.secret","common.secret"]);

Get table metadata

Get table metadata System API

Get table metadata using global object 'g'.

1
2
3
4
5
await g.sys.system.getTableMeta({
    instance: 'INSTANCE_NAME',
    database: 'DATABASE_NAME',
    collection: 'COLLECTION_NAME'
});

Emit event

Emit event System API

Emit event using global object 'g'.

await g.sys.system.emitEvent("EVENT_NAME", "EVENT_DATA", ["LISTENERS_NAME"]);

Emit event websocket

Emit event web-socket System API

Emit event of websocket using global object 'g'.

await g.sys.system.emitEventWS("EVENT_NAME", "EVENT_DATA");
1
2
3
4
await g.sys.system.emitEventWS(
    "myEvent", 
    { "name": "Bob" }
);

Is valid data for table/collection

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
    }
});

Is valid data for custom API

Validate custom API body object

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

1
2
3
4
5
6
7
8
await g.sys.system.isValidDataForCustomAPI({
    name: "custom_api_name",
    data: {
        "some": "data",
        "some": "data"
    },
    type: "BODY" // BODY | QUERY_PARAMS
});

Is valid data for third party API

Validate third party request body

Test the data is valid for Third party API, using global object 'g'.

await g.sys.system.isValidDataForThirdPartyAPI({
    apiBundleName: "bundle_name",
    apiVersionName: "api_version",
    name: "api_name",
    type: "BODY", // BODY | QUERY_PARAMS
    data: {
        name: 'hello'
    },
    isArray: false
});