URL Shortening API
Back

From WeChat Official Account Admin Platform
Jump to: navigation, search

Convert a long URL into a short URL.

Use case: Original URL (e.g. a product or payment QR code) used to generate a QR code is too long, causing a problem in code-scanning speed or success rate. Use this API to convert the long URL into a short URL and then generate a QR code to help improve the code-scanning performance.

Request Description

By calling this API, developers can convert a long URL into a short URL. Please use the HTTPS protocol.

HTTP request method: POST
https://api.wechat.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN


Parameter Description

Parameter Required Description
access_token Yes Access token providing authorization to call this API
Action Yes Value should be “long2short”, indicating a conversion from a long URL to a short URL
long_url Yes Long URL requiring conversion, including URLs starting with http://, https://, or weixin://wxpay

Example

curl -d "{\"action\":\"long2short\",\"long_url\":\"http://wap.koudaitong.com/v2/showcase/goods?alias=128wi9shh&spm=h56083&redirect_count=1\"}" "https://api.wechat.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN"

Return Description

Parameter Description
errcode Error code
errmsg Error description
short_url Short URL

An example of a successful JSON response is as follows:

{"errcode":0,"errmsg":"ok","short_url":"http:\/\/w.url.cn\/s\/AvCo6Ih"}

Parameter Description

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

An example of an unsuccessful JSON response is as follows (Invalid AppID):

Return Codes

Developer Guide
Custom-defined Menu
WeChat JS-SDK