# wxacode.createQRCode

Call this API at the server side. For more information, see Server API.

This API supports Cloud Calls. The WeChat DevTools version must be 1.02.1904090 or later (download the latest stable version here), and the wx-server-sdk version must be 0.4.0 or later.

Obtains Mini Program QR code in scenarios where a small number of codes are required. Note that Mini Program codes generated via this API never expire, but the quantity is limited. For details, see Obtaining the QR Code.

Calling methods:

# HTTPS Call

# Request Address

POST https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN

# Request Parameters

Attribute Type Default Required Description
access_token string Yes Credentials to call API
path string Yes The path to the Mini Program page to be entered after QR code is scanned. Its value cannot be empty and contains a maximum of 128 bytes. For a Mini Game, you may pass in only the query part. For example, after ?foo=bar is passed in, you can obtain {foo:"bar"} from the query parameter via the wx.getLaunchOptionsSync API.
width number 430 No The width of the QR code (in px). The minimum value is 280 px and the maximum value is 1280 px.

# Return Value

# Buffer

An image buffer is returned.

# Exception Response

# Object

JSON

Property Type Description
errcode number Error code
errmsg string Error message

Valid values of errcode

Value Description Minimum Version
45029 The total number of generated codes has reached the upper limit.

# Return Values

If the call is successful, binary content of the image is directly returned; if the call failed, data in the JSON format is returned.

# Notes

  • POST parameters need to be converted into JSON strings, and cannot be submitted in forms.
  • This API can only be used to generate the QR codes for published Mini Programs. The QR code containing parameters for a Mini Program in the developer version can be generated via WeChat DevTools during preview.
  • The maximum number of codes generated via wxacode.get and this API is 100,000, so be cautious when using this API.

# Example

Request

{
 "path":"page/index/index",
 "width":430
}

Response

{
 "errcode": 0,
 "errmsg": "ok",
 "contentType": "image/jpeg",
 "buffer": Buffer
}

# Cloud Call

Cloud call is a capability provided by Mini Program·Cloud Base that allows you to call WeChat APIs in a cloud function. It must be used via wx-server-sdk in the cloud function.

# API Calling Method

openapi.wxacode.createQRCode

You need to configure the permissions for the wxacode.createQRCode API via config.json. Details

# Request Parameters

Attribute Type Default Required Description
path string Yes The path to the Mini Program page to be entered after QR code is scanned. Its value cannot be empty and contains a maximum of 128 bytes. For a Mini Game, you may pass in only the query part. For example, after ?foo=bar is passed in, you can obtain {foo:"bar"} from the query parameter via the wx.getLaunchOptionsSync API.
width number 430 No The width of the QR code (in px). The minimum value is 280 px and the maximum value is 1280 px.

# Return Value

# Object

Returns an object containing binary data and its data type.

Property Type Description
contentType String Data type (MIME Type)
buffer Buffer Data buffer

# Exceptions

# Object

JSON

Property Type Description
errCode number Error code
errMsg string Error message

Valid values of errCode

Value Description Minimum Version

# Example

Request

const cloud = require('wx-server-sdk')
  cloud.init()
  exports.main = async (event, context) => {
    try {
      const result = await cloud.openapi.wxacode.createQRCode({
        path: 'page/index/index',
        width: 430
      })
      console.log(result)
      return result
    } catch (err) {
      console.log(err)
      return err
    }
  }

Response

{
 "errcode": 0,
 "errmsg": "ok",
 "contentType": "image/jpeg",
 "buffer": Buffer
}