/v2/miniprogram/qrcode/create

POST /v2/miniprogram/qrcode/create

With this API call, a merchant or an ISV can create a promotion QR code to redirect users to a specific mini program. For example, users can scan the QR code to order meals in the mini program.

Structure

A message consists of a header and body. The following sections are focused on the body structure. For the header structure, see:

Request parameters

Field

Data type

Required

Description

Example

appId

String 

Yes

Indicates the unique ID assigned by Mini Program Platform to identify a mini program that users are redirected to when they scan the QR code.

  • Maximum length: 32 characters
  • Characters not allowed: special characters such as @ # ?

Note: Obtain this field via the my.getAppIdSync JSAPI or Mini Program Platform.

"P000000000000001xxxx"

appQrCodeType

String

No

Indicates the type of the created QR code. The valid value is:

  • PROMO: indicates to create a promotion QR code.

Note: When the value of appQrCodeType is Null, the created QR code is a promotion QR code by default.

"PROMO"

appQrCodePage

String 

No

Indicates the page path that redirects users to a specific page in the mini program, for example: page/component/component-pages/view.

  • Maximum length: 512 characters
  • Can be Null.

Note: When the value of appQrCodePage is Null, the QR code will redirect users to the home page of the mini program.

"page/component/component-pages/view"

appQrCodeParams

String 

No

When a user uses the super app or other apps to scan the QR code, this field will be passed to the mini program via onLaunch method.

  • Maximum length: 512 characters
  • Can be Null.

"x=1&y=2"

appQrCodeDesc

String 

No

Indicates the description of the QR code.

  • Maximum length: 64 characters
  • Can be Null.

"My shop QR code"

Response parameters

Field

Data type

Required

Description

Example

result

Result

Yes

Indicates the request result such as status and error codes.

copy
{
    "resultCode": "SUCCESS",
    "resultStatus": "S",
    "resultMessage": "success" 
}

appQrCode

String

Yes

Indicates the QR code value, which is the final URL to redirect users to a mini program when they scan the QR code.

  • Maximum length: 1024 characters.

"https://miniprogram.alipay.com/mini-qr/28166612109YMP7RLw7zT2HU1k6AXzSOFfv4qu3xxxx"

appQrCodePicValue

String

Yes

Indicates the QR code image in the appQrCodeResultPicType format.

  • Maximum length: 4096 characters.

See Response Sample Code for an example.

appQrCodeResultPicType

String

Yes

Indicates the format of the QR code image. Currently, only Base64 is supported.

  • Maximum length: 1024 characters.

BASE64

Result process logic

In the response, the result.resultStatus field indicates the result of processing a request. The following table describes each result status:

Result status

Description 

S

The request to create a QR code is successful, which means the QR code value and image are generated and returned to the merchant.

Note: For the QR code generated with the same appId, appQrCodePage, appQrCodePage, and appQrCodeParams and reach an S status, the same QR code value and image are returned. For more information, see Idempotency.

The corresponding result.resultCode is SUCCESS and the result.resultMessage is Success.

U

The status of the request to create a QR code is unknown.  

The corresponding result.resultCode is UNKNOWN_EXCEPTION and result.resultMessage is "An API calling is failed, which is caused by unknown reasons.". For details, see the Common error codes section.

F

The request to create a QR code is failed.

The corresponding result.resultCode and result.resultMessage are various based on different situations. For details, see the following Error codes section.

Error codes

Error codes are usually classified into the following categories:

  • Common error codes are common for all mini program OpenAPIs in V2.  
  • API-specific error codes: The current OpenAPI does not have its dedicated error codes.

Samples

The data flow of creating a QR code is illustrated as below:

image

  1. The merchant server or the ISV server calls this API to request Mini Program Platform to create a QR code.
  2. Mini Program Platform processes the request and returns the generated QR code value and image to the merchant server or the ISV server.

Request

copy
{
    "appId":"P000000000000001xxxx",
    "appQrCodeType":"PROMO",
    "appQrCodePage":"page/component/component-pages/view",
    "appQrCodeParams":"x=1&y=2",
    "appQrCodeDesc":"My Shop QR code"
}
  • The merchant requests to create a QR code (with description My Shop QR code) for the mini program ( P000000000000001xxxx).
  • The QR code links to the mini program page( page/component/component-pages/view) with parameters (x=1&y=2).

Response

copy
{
    "appQrCode": "https://miniprogram.alipay.com/mini-qr/28166612109YMP7RLw7zT2HU1k6AXzSOFfv4qu3xxxx",
    "appQrCodePicValue": "iVBORw0KGgoAAAANSUhEUgAAAawAAAGsCAIAAAAOqgT7AAAM6UlEQVR42u3aS3IDIRBEQd3/0vIVHGHT1QX51mNpxCfxgs9Xkh7uYwgkQVCSIChJEJQkCEoSBCUJgpIEQUmCoCRBUJIgKEkQlCQIShIEJQmCkgRBSYKgJEFQkiAoSRCUJAhKEgQlCYKSBEFJgqAkQVCSIChJEJQkCEoSBCUJgpIEQUmCoCRBUJIgKEkQlCQIShIEJQ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appQrCodeResultPicType": "BASE64",
  
    "result": {
        "resultCode": "SUCCESS",
        "resultMessage": "success",
        "resultStatus": "S"
    }
}

Related links

my.getAppIdSync