# Quick Start

This quick start assumes you have already installed `ml-cli` (see [Download & Installation](/cli#download--installation)) and that the MoreLogin client is running locally.

## 1. Check The Service

Confirm that the local `httpServer` is reachable:


```bash
ml-cli status
```

If MoreLogin is not running, the CLI will fail during port resolution.

## 2. Authenticate

If the endpoint requires authentication, log in first:


```bash
ml-cli login --api-id your-api-id --api-key your-api-key
```

You can also provide the token through an environment variable:


```bash
export ML_API_KEY=your-token
ml-cli env list
```

## 3. List Browser Profiles

List browser environments:


```bash
ml-cli env list
ml-cli env list --page-no 1 --page-size 20
ml-cli env list --env-name test
```

## 4. Start A Browser Profile

You can start an environment by `id`, `envId`, or `uniqueId/sn`:


```bash
ml-cli env start --id 1001
ml-cli env start --env-id 1868548141708648448
ml-cli env start --unique-id SN001
```

## 5. Create And Assign A Proxy

Create a proxy first:


```bash
ml-cli proxy create \
  --proxy-name local-http \
  --proxy-ip 127.0.0.1 \
  --proxy-port 7890 \
  --proxy-type 0 \
  --proxy-provider 0
```

Then assign it to an environment:


```bash
ml-cli env set-proxy \
  --env-ids 1001 \
  --proxy-ip 127.0.0.1 \
  --proxy-port 7890 \
  --proxy-type 0 \
  --proxy-provider 0 \
  --proxy-name local-http
```

## 6. Work With Cloud Phones

List cloud phones:


```bash
ml-cli cloudphone list
```

Create a cloud phone:


```bash
ml-cli cloudphone create --sku-id 10004 --quantity 1
```

Fetch details:


```bash
ml-cli cloudphone info --id 123456
```

## 7. Query Schedules

List schedule templates and tasks:


```bash
ml-cli schedule template-market --page-no 1 --page-size 20
ml-cli schedule list --page-no 1 --page-size 20
```

Create a one-time task:


```bash
ml-cli schedule create-once-task \
  --cloud-phone-id 123456 \
  --schedule-name once-task-demo \
  --template-id 888 \
  --template-parameter '{}'
```

## 8. Use `--json-data`

For endpoints with many fields, passing raw JSON is often faster:


```bash
ml-cli env create-advanced \
  --json-data '{"browserTypeId":1,"operatorSystemId":1,"envName":"cli-adv-test"}'
```

CLI flags and `--json-data` can be combined. Explicit flags override matching keys from the JSON payload:


```bash
ml-cli env set-proxy \
  --env-ids 1001 \
  --json-data '{"proxy":{"proxyProvider":"0","proxyIp":"1.1.1.1"}}' \
  --proxy-ip 127.0.0.1
```

## 9. Pipe To `jq`

The CLI prints raw JSON, which works well with shell pipelines:


```bash
ml-cli status | jq '.status'
ml-cli env processes | jq '.data[].pid'
```

## 10. Common Failure Cases

- `Could not detect MoreLogin port`: MoreLogin is not running, IPC is unavailable, or no `--port` was provided
- business failure with exit code `0`: the HTTP request succeeded, but the JSON response contains an application-level error
- `ml-cli env arrange` on Linux: the current implementation does not support it and exits immediately