0.1.8 • Published 3 years ago

@alpuks/ml-api-unofficial v0.1.8

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Unofficial API wrapper for Multilogin

Shield

This is a basic wrapper for accessing the API of Multilogin v5. A promise is returned for each call.

Endpoints supported:

  • createProfile
  • updateProfile
  • listProfiles
  • deleteProfile
  • updateProfileCore
  • migrateProfile
  • startProfile
  • stopProfile

Installing

The application is available via NPM.

npm install @alpuks/ml-api-unofficial

Usage

Setting up

let MlaApi = require("@alpuks/ml-api-unofficial");

// Enter the port on which Multilogin gets launched on
const api = new MlaApi({ port: 35000 });

Getting a list of profiles

api.listProfiles().then((profileList) => console.log(profileList));

Creating a new profile

let profileBody = {
  name: "testProfile",
  browser: "mimic",
  os: "win",
};

api
  .createProfile(profileBody)
  .then((profile_id) => console.log(profile_id))
  .catch((error) => console.log(error));

Updating a profile

let profileId = "10e56b91-6e6c-4ee5-8555-1a886665e6e7";
let profileBody = {
  name: "Renamed profile",
};

api
  .updateProfile(profileId, profileBody)
  .then((response) => console.log(response))
  .catch((error) => console.log(error));

Starting a profile

let profileId = "10e56b91-6e6c-4ee5-8555-1a886665e6e7";

// Possible options {profileId=..., loadTabs=True, automation=True, puppeteer=true}
let startOptions = { profileId, automation: true };

api
  .startProfile(startOptions)
  .then((websocket) => {
    // Connect selenium/puppeteer with the websocket for automation
  })
  .catch((error) => {
    console.log(error);
  });

Stopping a profile

let profileId = "10e56b91-6e6c-4ee5-8555-1a886665e6e7";

api.stopProfile(profileId).then(console.log("Sent stop request"));

Deleting a profile

let profileId = "10e56b91-6e6c-4ee5-8555-1a886665e6e7";

api.removeProfile(profileId).then((response) => console.log(response));

Migrating a profile from MLA v4 to MLA v5

let profileId = "10e56b91-6e6c-4ee5-8555-1a886665e6e7";

api.migrateProfile(profileId).then(console.log("Profile migrated"));

Updating the browser profile core to the latest version

let profileId = "10e56b91-6e6c-4ee5-8555-1a886665e6e7";

api.updateProfileCore(profileId).then(console.log("Profile updated"));

Examples

Here's a quick example on how to get a list of browsers that need their cores updated and update them while implementing a sleep function to not get rate limited.

let MlaApi = require("@alpuks/ml-api-unofficial");

const api = new MlaApi({ port: 35000 });

async function sleep(millis) {
  return new Promise((resolve) => setTimeout(resolve, millis));
}

api.listProfiles().then((listOfProfiles) => {
  listOfProfiles.forEach(async (profile) => {
    if (profile.browserNeedsUpdate) {
      api
        .updateProfileCore(profile.uuid)
        .then(() => console.log(`Update profile core of ${profile.name}`))
        .catch(() =>
          console.log(`Failed to update profile core of ${profile.name}`)
        );
    }
    // Timeout so that we would not spam the API
    await sleep(500);
  });
});

Dependencies

The wrapper is built using isomorphic-unfetch for compatibility with node and also most browsers.

0.1.8

3 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago