Developers LinkApi

Parallel

Execute a function for each item from the array and choose the number of executions in parallel. Create transactions for each item from the array and remove duplicated items based on an uniquekey.

const collection = [{ id: '1', name: 'LinkApi' }]

await linkapi.parallel(collection, {
    parallelExecutions: 1, // NUMBER OF RUNS IN PARALLEL
    transaction: {
        uniqueKey: 'id', // 'uniqueKey' is an identifier which allows you to use an object's property if you specify it
        data: '{{item}}', // 'data' is the data stored on log
        removeDuplicates: true, // 'removeDuplicates' can remove duplicate objects based on uniqueKey and already successfully transacted
        create: true // 'create' controls whether or not to create the transaction. While developing, we recommend setting this flag to false
       }
    }, async (item) => {
    // DO YOUR LOGIC HERE
 });

SFTP Commands

The SFTP commands allow you to see and make changes on SFTP files. Follow these examples:

const credentials = {
            host: 'example.sftp.com',
            port: 22,
            username: 'user',
            password: 'pass'
        }

        const sftp = new linkapi.sftp(credentials);
const privateKeyCredentials = {
            host: 'example.sftp.com',
            port: 22,
            username: 'user',
            passphrase: 'pass',
            privateKey: 'base64'
        }

     const sftp = new linkapi.sftp(privateKeyCredentials);
const fromPath = '/folder/file1';
        const toPath = '/folder/file2';
        await sftp.copyFile(fromPath, toPath);
const filePath = '/folder/file1';
    const fileContent = await sftp.readFile(filePath);
const filePath = '/folder/file1';
        const fileContent = 'hello world!';
        await sftp.uploadStream(fileContent, filePath);
const filePath = '/folder/file1';
        await sftp.deleteFile(filePath);
const folderPath = '/folder';
        const files = await sftp.readDirectory(folderPath);
        const fileExample = {
            filename: 'vale_tst',
            longname: 'drwxr--r--   1        -        -        0 Feb  6 19:00 vale_tst',
            attrs:
                {
                    mode: 16868,
                    permissions: 16868,
                    uid: undefined,
                    gid: undefined,
                    size: 0,
                    atime: 1581015616,
                    mtime: 1581015616
                }
        }

XML and JSON

Use these commands to transform a payload from XML to Json and vice versa.

const xml = `
      <note>
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
      </note>
`;

const parsed = await linkapi.parser.json(xml);
// output 
// {
//     note:
//     {
//         to: 'Tove',
//         from: 'Jani',
//         heading: 'Reminder',
//         body: 'Don\'t forget me this weekend!'
//     }
// }
const json = {
    to: 'Tove',
    from: 'Jani',
    heading: 'Reminder',
    body: 'Don\'t forget me this weekend!'
}

const parsed = await linkapi.parser.xml(json);
// output 
// <to>Tove</to>
// <from>Jani</from>
// <heading>Reminder</heading>
// <body>Don't forget me this weekend!</body>

Other Comands

Command (parameters)

Description

linkapi.log(...messages)

Outputs a message in the response editor after the test runs.

Example: linkapi.log('param1', '...', 'paramN');

linkapi.errorParser(err)

Verifies if the sent error is already a node error instance or not. If yes, it will be sent for the next layer without changes; otherwise, a new error will be returned with the information provided.

linkapi.compose(array, composeFunction, chunkSize)

Execute the inputted function within the contents of a selected array. You can change the execution speed changing the chunkSize value, 1 by default. |
| utils.Function() | All lodash functions are available. Check all lodash commands.

linkapi.dateTime("Date to be manipulated").Function("desired format")

This function manipulates the informed date to the desired format. Check all moment.js commands.

object = linkapi.removeNullFields(object)

This function removes all null fields of a specific object.

Updated about a year ago

Utils


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.