WeChat DevTools provides command line API and HTTP API for external calls. Developers can instruct the DevTools to perform operations, such as login, preview and upload, by using command lines or sending HTTP requests.

HTTP

The HTTP service is automatically enabled when the DevTools is launched, with its port number recorded in the user directory. You can check whether the DevTools is installed or launched by checking whether the port file exists in the user directory and connecting to the server.

Location of the port file:

macOS: ~/Library/Application Support/微信开发者工具/Default/.ide

Windows: ~/AppData/Local/微信开发者工具/User Data/Default/.ide

1. Open DevTools or Specified Project

API definition:

URL: /open

HTTP method: GET

URL Parameter Required Description
projectpath No Opens the project in the specified path. If the project is already opened, it will be refreshed automatically. If no project exists, an project is automatically created and opened. If this parameter is not specified, the DevTools window is displayed.

Example:

# Open the DevTools
http://127.0.0.1:port number/open
# Open/Refresh the project
http://127.0.0.1:port number/open?projectpath=full path of the project

Note:

  • The project path must contain "project.config.json" in the correct format, and "appid" and "projectname" fields are provided in the file.
  • The project path must be URL-encoded.

2. Login

API definition:

URL: /login

HTTP method: GET

URL Parameter Required Description
format No Specifies the return format of the login QR code. Available values include image (default), base64, and terminal. The image format is png.
qroutput No Specifies the file path to write the QR code data into the file. If specified, the QR code is written into the file under the specified path. Otherwise, the QR code is returned as the request response.
resultoutput No Specifies the file path to output the login result

Example:

# Log in and return the QR code in image format
http://127.0.0.1:port number/login
# Log in and get the QR code in  base64  format
http://127.0.0.1:port number/login?format=base64
# Log in, get the QR code in  base64  format, and write it into  /Users/username/logincode.txt
http://127.0.0.1:port number/login?format=base64&qroutput=%2FUsers%2Fusername%2Flogincode.txt
# Log in and write the login result into  /Users/username/loginresult.json
http://127.0.0.1:port number/login?resultoutput=%2FUsers%2Fusername%2Floginresult.json

3. Preview

API definition:

URL: /preview

HTTP method: GET

URL Parameter Required Description
projectpath Yes Previews the project in the specified path. If the project is already opened, it will be refreshed automatically. If no project exists, an project is automatically created and previewed.
format No Specifies the return format of the login QR code. Available values include image (default), base64, and terminal. The image format is png.
qroutput No Specifies the file path to write the QR code data into the file. If specified, the QR code is written into the file under the specified path. Otherwise, the QR code is returned as the request response.
infooutput No If specified, the additional information about this preview, such as code package size and subpackage size, is output to the specified path in json format.
compilecondition No Specifies custom compilation conditions in json string format. Two fields can be specified: pathName that indicates the opened page (homepage if left blank), and query that indicates the page parameter.

Example:

# Preview the project under the path  /Users/username/demo  and return the QR code in image format
http://127.0.0.1:port number/preview?projectpath=%2FUsers%2Fusername%2Fdemo
# Preview the project under the path  /Users/username/demo  and return the QR code in  base64  format
http://127.0.0.1:port number/preview?projectpath=%2FUsers%2Fusername%2Fdemo&format=base64
# Preview the project under the path  /Users/username/demo , return the QR code in  base64  format, and write it into  /Users/username/logincode.txt
http://127.0.0.1:port number/preview?projectpath=%2FUsers%2Fusername%2Fdemo&format=base64&qroutput=%2FUsers%2Fusername%2Flogincode.txt
# Preview the project under the path  /Users/username/demo , return the QR code in image format, and output the preview information to  /Users/username/info.json
http://127.0.0.1:port number/preview?projectpath=%2FUsers%2Fusername%2Fdemo&infooutput=%2Users%2username%2info.json
# Preview the project under the path  /Users/username/demo , and specify custom compilation conditions where the startup page is  pages/index/index and the parameter is  x=1&y=2
http://127.0.0.1:port number/preview?projectpath=%2FUsers%2Fusername%2Fdemo&compilecondition={"pathName":"pages/index/index","query":"a3=1"}

4. Upload

API definition:

URL: /upload

HTTP method: GET

URL Parameter Required Description
projectpath Yes Uploads the project in the specified path
version Yes Version number
desc No Release notes about this upload
infooutput No If specified, the additional information about this upload, such as code package size and subpackage size, is output to the specified path in json format.

Example:

# Upload the project under the path  /Users/username/demo , and specify the version number of  v1.0.0
http://127.0.0.1:port number/upload?projectpath=%2FUsers%2Fusername%2Fdemo&version=v1.0.0
# Upload the project under the path  /Users/username/demo , specify the version number of  v1.0.0, and provide release notes
http://127.0.0.1:port number/upload?projectpath=%2FUsers%2Fusername%2Fdemo&version=v1.0.0&desc=test
# Upload the project under the path  /Users/username/demo , specify the version number of  v1.0.0, and output the upload information to  /Users/username/info.json
http://127.0.0.1:port number/upload?projectpath=%2FUsers%2Fusername%2Fdemo&version=v1.0.0&infooutput=%2Users%2username%2info.json

5. Build npm

API definition:

URL: /buildnpm

HTTP method: GET

URL Parameter Required Description
projectpath Yes Uploads the project in the specified path
compiletype No Compilation type: miniprogram (default) or plugin

Example:

# Build the project under the path  /Users/username/demo 
http://127.0.0.1:port number/buildnpm?projectpath=%2FUsers%2Fusername%2Fdemo&compiletype=miniprogram

6. Auto Testing

API definition:

URL: /test

HTTP method: GET

URL Parameter Required Description
projectpath Yes Tests the project in the specified path

Example:

# Submit the project under the path  /Users/username/demo  for testing
http://127.0.0.1:port number/test?projectpath=%2FUsers%2Fusername%2Fdemo

Request Response

The HTTP status code is 200 under normal circumstances, and 400 when an error occurs, in which case a JSON string in the following format is returned:

{
  "code": 40000,
  "error": "Reason"
}

7. Auto Preview

API definition:

URL: /autopreview

HTTP method: GET

URL Parameter Required Description
projectpath Yes Specifies the project in the path. If the project is already opened, it will be refreshed automatically. If no project exists, an project is automatically created and previewed.
infooutput No If specified, the additional information about this auto preview, such as code package size and subpackage size, is output to the specified path in json format.

Example:

# Auto preview the project under the path  /Users/username/demo , return the QR code in image format, and output the preview information to  /Users/username/info.json
http://127.0.0.1:port number/autopreview?projectpath=%2FUsers%2Fusername%2Fdemo&infooutput=%2Users%2username%2info.json

8. Close the Window of the Current Project

API definition:

URL: /close

HTTP method: GET

URL Parameter Required Description
projectpath Yes Specifies the project in the path

Example

http://127.0.0.1:port number/close?projectpath=%2FUsers%2Fusername%2Fdemo

Note: When closing the project, a pop-up window will appear, prompting whether to block it. If not, the project will be closed in 3 seconds.

9. Quit the WeChat DevTools

API definition:

URL: /quit

HTTP method: GET

Example

http://127.0.0.1:port number/quit

Note: When quitting the WeChat DevTools, a pop-up window will appear, prompting whether to block it. If not, the DevTools will be closed in 3 seconds.