# Quickstart

Get up and running with the MoreLogin API in 5 minutes.

## Browser Automation (Local API)

**Scenario:** Create a browser profile, launch it, connect via Puppeteer to run a script, and then stop it.

### Prerequisites

- MoreLogin desktop app **v2.15.0+** installed and running locally.
- Puppeteer installed (`npm i puppeteer-core`).


### Step 1: Create a Browser Profile

```bash
curl -X POST "http://127.0.0.1:40000/api/env/create/quick" \
  -H "Content-Type: application/json" \
  -d '{
    "browserTypeId": 1,
    "operatorSystemId": 1,
    "quantity": 1
  }'
```

*This endpoint returns `data` as an array of the profile IDs it created. Take `data[0]` as the `envId` for the following steps (e.g., `1993244721490239488`). Resource IDs are decimal strings.*

### Step 2: Start the Profile & Get Debug Port

```bash
curl -X POST "http://127.0.0.1:40000/api/env/start" \
  -H "Content-Type: application/json" \
  -d '{"envId": "1993244721490239488"}'
```

*The response will include the `debugPort` (e.g., `12345`).*

### Step 3: Connect Puppeteer (Node.js)

```javascript
const puppeteer = require('puppeteer-core');

(async () => {
  const browser = await puppeteer.connect({
    browserURL: 'http://127.0.0.1:12345'
  });
  const page = await browser.newPage();
  await page.goto('https://www.morelogin.com');
  console.log(await page.title());
  await browser.disconnect();
})();
```

### Step 4: Stop the Profile

```bash
curl -X POST "http://127.0.0.1:40000/api/env/close" \
  -H "Content-Type: application/json" \
  -d '{"envId": "1993244721490239488"}'
```

## Cloud Phone Management (Open API)

**Scenario:** Quick-create a cloud phone, start it, install an application, and trigger an RPA schedule.

### Prerequisites

- API ID and API Key from the MoreLogin dashboard.
- Steps 1–3 work on a brand-new account. Step 4 needs at least one app in your team's app library, and step 5 needs at least one RPA template; neither can be created through the API, so seed them in the dashboard if the lookup calls come back empty.


### Step 1: Get Access Token

```bash
curl -X POST "https://api.morelogin.com/oauth2/token" \
  -H "Content-Type: application/json" \
  -d '{
    "client_id": "YOUR_API_ID",
    "client_secret": "YOUR_API_KEY",
    "grant_type": "client_credentials"
  }'
```

*Save the `access_token` from the response.*

### Step 2: Create a Cloud Phone

```bash
curl -X POST "https://api.morelogin.com/cloudphone/create" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -d '{
    "skuId": "10002",
    "quantity": 1
  }'
```

*Save `data[0]` from the response as the Cloud Phone ID. Resource IDs are decimal strings.*

### Step 3: Power On the Cloud Phone

```bash
curl -X POST "https://api.morelogin.com/cloudphone/powerOn" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -d '{"id": "1673823102599682"}'
```

*Power-on is asynchronous. A successful response accepts the operation; query the Cloud Phone list until the phone reports a runnable state before sending commands that require it to be online.*

### Step 4: Install an App

Apps are installed from your team's app library, so first look up what the library holds:

```bash
curl -X POST "https://api.morelogin.com/cloudphone/app/page" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -d '{"pageNum": 1, "pageSize": 10}'
```

*Take `data.dataList[0].appVersionList[0].id` as the `appVersionId` — versions come back newest first. The app-level `id` is not what `install` expects. If `data.dataList` is empty, upload an app in the MoreLogin dashboard first; there is no API to seed the library.*

Install by `appVersionId`, or by `packageName` plus `versionCode` when you only know the package:

```bash
curl -X POST "https://api.morelogin.com/cloudphone/app/install" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -d '{
    "id": "1673823102599682",
    "appVersionId": "1672940217990530"
  }'
```

### Step 5: Run an RPA Schedule

List your own templates and take the `id` you want to run:

```bash
curl -X POST "https://api.morelogin.com/cloudphone/rpa/template/personal/page" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -d '{"pageNo": 1}'
```

*Use `data.dataList[0].id` as the `templateId` below. Templates are authored in the dashboard or taken from the market; the API only lists and runs them.*

```bash
curl -X POST "https://api.morelogin.com/cloudphone/rpa/onceTask/save" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -d '{
    "cloudPhoneId": "1673823102599682",
    "scheduleName": "Daily Login Task",
    "templateId": "987654321"
  }'
```

## What's Next?

| Goal | Go to |
|  --- | --- |
| Full Browser Profile API reference | [Browser API](/api-reference/browser/local-api) |
| Full Cloud Phone API reference | [Cloud Phone API](/api-reference/cloud-phone/open-api) |
| Connect via ADB | [ADB Connection Guide](/api-reference/cloud-phone/adb) |