Developers LinkApi

Other Commands

Parallel

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

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

await linkapi.parallel(collection, {
    parallelExecutions: 1, // AMOUNT RUNS IN PARALLEL
    transaction: {
        uniqueKey: 'id', // 'uniqueKey' is a 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 duplicates objects based on uniqueKey and already successfully transacted
        create: true // 'create' controls whether or not to create 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:

linkapi.core.sftp.readDirectory({
    credentials: {
                host: '',
                port: 22,
                user: 'USER',
                password: 'PASS',
            },
            params: {
                directory: '/directory'
            }
        });
linkapi.core.sftp.readFile({
    credentials: {
                host: '',
                port: 22,
                user: 'USER',
                password: 'PASS',
            },
            params: {
                path: '/directory/my-file.csv'
            }
        });
linkapi.core.sftp.moveFile({
    credentials: {
                host: '',
                port: 22,
                user: 'USER',
                password: 'PASS',
            },
            params: {
                    oldPath: '',
                    newPath: ''
            }
        });

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.

linkapi.reject("Message that will be shown in logs")

Causes a reject in your integration.

object = linkapi.removeNullFields(object)

This function removes all null fields of a specific object.

Other Commands


Suggested Edits are limited on API Reference Pages

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