Skip to navigation

What do mid, idx and sn mean in a WeChat article link, and must I convert a short link?

In a long WeChat article URL, __biz identifies the account component, mid the publication batch, idx the article’s position within the batch and sn the link’s check value. To read an article’s text or engagement counts, pass the complete URL you received, without editing the parameters. Short article links work too. When you clean up a list of links, keep idx: __biz + mid + idx together identify one article.

When do __biz, mid, idx and sn matter?

ComponentRole in your article list
__bizAccount component in a long link; account-history requests still use username
midDistinguishes a message or publication batch; keep mid as received
idxDistinguishes articles within the batch, starting at 1
snKeep sn with the original link and pass the complete URL

The common mistake is dropping idx. Two links with the same __biz and mid but idx=1 and idx=2 identify two different articles in the same batch. Keep both links; do not deduplicate by account or by mid alone.

Do not rename mid into another API’s field. Use the complete url to read an article, and take user_name from the article detail when you need account history.

Organize a list supplied by a colleague

Keep the original list, then handle each link form as follows:

LinkAction
/s/… short URLUse the short URL directly for reading or statistics
Long URL containing __biz, mid and idxRetain all parameters and group by article identity
Same three identity components, different extra parametersGroup as candidates, check the differences and select an original URL
Different idxKeep as separate articles
Truncated link or copied HTML markupObtain the complete public share URL rather than inventing parameters

Keep a short URL and a long URL as separate records until checkable article information links the two. Matching titles are useful clues, not sufficient grounds to delete one record.

If you also receive a URL with extra source parameters, group the URL provisionally by __biz, mid and idx and keep every original link. After reading the article, verify the group with the returned title and source.

Organize larger lists locally first

The audit_links.py helper below checks 1–200 links without visiting the articles and writes two files:

  • input-urls.json: the original input for reference.
  • link-audit.json: URL forms, long-link identity components and candidate groups.

In same_long_identity_groups, input_indices are zero-based positions in the input JSON array. Every original URL is kept. Short links stay unresolved until you read the article. link-audit.json describes URL structure only; whether an article is accessible is shown by an actual read.

Once the list is ready, choose articles for body reading or engagement statistics. For account history, follow the article-to-account handoff. Call prices are on the pricing page.

Optional offline helper

Save your actual URLs as a JSON array in article-links.json, in the format below:

[
"https://mp.weixin.qq.com/s?__biz=EXAMPLE_ACCOUNT&mid=123456789&idx=2&sn=EXAMPLE_CHECK_VALUE",
"https://mp.weixin.qq.com/s/example-short-token"
]

Save the script further below as audit_links.py, then run:

python3 audit_links.py article-links.json link-review

audit_links.py checks the public-share URL structure and keeps the original URLs and input bytes. If copied text or identity parameters need attention, audit_links.py stops and reports the problem for correction. Use a new output-directory name for each run so earlier results are kept.

import hashlib,json,pathlib,re,sys
from urllib.parse import parse_qs,urlsplit
source,target=map(pathlib.Path,sys.argv[1:]);original=source.read_bytes();urls=json.loads(original)
if not isinstance(urls,list) or not 1<=len(urls)<=200:raise ValueError('Provide 1..200 public article URLs')
rows=[];groups={}
for url in urls:
if not isinstance(url,str) or not url or any(c.isspace() or ord(c)<32 or ord(c)==127 for c in url):raise ValueError('Use an intact public URL without whitespace/control characters')
parsed=urlsplit(url)
if parsed.scheme not in ('http','https') or parsed.hostname!='mp.weixin.qq.com' or parsed.username is not None or parsed.password is not None or parsed.port not in (None,80,443):raise ValueError('Expected a WeChat article host without embedded credentials')
query=parse_qs(parsed.query,keep_blank_values=True)
if any(k.startswith('amp;') for k in query):raise ValueError('Copy the actual URL, not HTML-escaped markup')
if any(k.lower() in ('pass_ticket','key','uin','ticket','access_token') for k in query):raise ValueError('Use a public share URL without browser-session parameters')
for key in ['__biz','mid','idx','sn']:
if key in query and (len(query[key])!=1 or not query[key][0] or any(c.isspace() or ord(c)<32 or ord(c)==127 for c in query[key][0])):raise ValueError('Ambiguous, blank or malformed article component: '+key)
if parsed.path=='/s':
if not all(k in query for k in ['__biz','mid','idx']):raise ValueError('Long-link identity needs __biz, mid and idx')
biz,mid,idx=(query[k][0] for k in ['__biz','mid','idx'])
if not re.fullmatch(r'[0-9]+',mid) or int(mid)<1 or not re.fullmatch(r'[0-9]+',idx) or int(idx)<1:raise ValueError('mid/idx must be original positive ASCII digit strings')
identity=[biz,mid,idx]
row={'url':url,'kind':'long','biz':biz,'mid':mid,'idx':idx,'sn_present':'sn' in query,'identity':identity,
'position':'headline' if int(idx)==1 else 'secondary'}
groups.setdefault(json.dumps(identity,ensure_ascii=False),[]).append(len(rows))
elif parsed.path.startswith('/s/') and parsed.path[3:] and '/' not in parsed.path[3:]:
row={'url':url,'kind':'short','biz':None,'mid':None,'idx':None,'sn_present':'sn' in query,'identity':None,'position':'not_derived_from_short_link'}
else:raise ValueError('Expected /s with long parameters or one /s/ article token')
rows.append(row)
target.mkdir()
(target/'input-urls.json').write_bytes(original)
(target/'link-audit.json').write_text(json.dumps({'links':rows,
'same_long_identity_groups':[{'identity':json.loads(k),'input_indices':v} for k,v in groups.items() if len(v)>1],
'input_sha256':hashlib.sha256(original).hexdigest(),'short_long_aliases_resolved':False,
'network_requests':0,'article_availability_verified':False},ensure_ascii=False,indent=2),encoding='utf-8')
print(json.dumps({'links':len(rows),'long_links':sum(r['kind']=='long' for r in rows),'short_links':sum(r['kind']=='short' for r in rows),'network_requests':0}))