Converts a long URL to a short URL.

Use cases: A long URL for generating a product or payment QR code may slow down the scanning speed and affect its success rate. This API is used to convert the long URL to a short URL to increase the scanning speed and success rate.

API Request Format

Developers can use OpenID to get basic user information. Be sure to use the HTTPS protocol.

HTTP request method: POST


Parameter Required Description
access_token Yes The credential for API call
action Yes Enter long2short, which indicates converting a long URL to a short URL
long_url Yes The long URL to be converted. URLs starting with http://, https://, and weixin://wxpay are supported.

Call example

curl -d "{\"action\":\"long2short\",\"long_url\":\"\"}" ""

Response Description

For a successful request, Weixin returns the following JSON packet to the Official Account:



Parameter Description
errcode Error code
errmsg Error message
short_url Short URL

When an error occurs, Weixin will return an error code and related information. An example of the JSON packet (for an invalid AppID error) is shown below:

{"errcode":40013,"errmsg":"invalid appid"}