Frequently used assets may be uploaded via this API to the Weixin server permanently. New permanent assets can be managed in Media Asset Management module on Official Accounts Platform.

Notes:

  1. Last update: Once added, new permanent images are returned with URLs for developers to use on all Tencent domain names (images will be hidden if used on external domain names).

  2. An Official Account's media asset library is subject to a maximum storage limit: 5,000 for articles and images and 1,000 for other types of assets.

  3. The format and size restrictions for assets are the same as shown on the Official Accounts Platform:

Image: 10 MB. BMP, PNG, JPEG, JPG, and GIF formats are supported.

Voice: 2 MB. The maximum length is 60s. MP3, WMA, WAV, and AMR formats are supported.

Video: 10 MB. The MP4 format supported.

Thumbnail: 64 KB. The JPG format supported.

  1. The Weixin backend will filter out any external image links in articles. Image URLs must be obtained by uploading images via the "Upload Image in Article to Obtain URL" API.

  2. Images uploaded via the "Upload Image in Article to Obtain URL" API are excluded from the maximum storage limit of 5,000 images for an Official Account's media asset library. Only JPG/PGN images smaller than 1 MB are supported.

  3. Links to articles broadcasted from your account and other Official Accounts can be added in the main body of the article.

# Adding New Permanent Articles

API Request Format

HTTP request method: POST. HTTPS protocol is used.
https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=ACCESS_TOKEN

Calling Example

{
    "articles": [{
     "title": TITLE,
    "thumb_media_id": THUMB_MEDIA_ID,
    "author": AUTHOR,
    "digest": DIGEST,
    "show_cover_pic": SHOW_COVER_PIC(0 / 1),
    "content": CONTENT,
    "content_source_url": CONTENT_SOURCE_URL,
    "need_open_comment":1,
    "only_fans_can_comment":1
},
    //If multiple articles are added, there should also be more segments of structure information here for these articles.
]
}

Parameters

Parameter Required Description
title Yes The Title
thumb_media_id Yes The ID for the cover image asset of articles (it must be a permanent mediaID)
author No The author
digest No The summary of an article. Only the single article has a summary. For multiple articles, it is empty. If this field is not specified, the first 64 characters in the main body will be fetched by default.
show_cover_pic Yes Indicates whether to display the cover. 0 is false, indicating not to display; 1 is true, indicating to display.
content Yes Detailed contents of articles, which supports HTML tags. It must be less than 20,000 characters and 1 MB in size. JS-related content will be removed. Image URLs must be obtained by uploading images via the "Upload Image in Article to Obtain URL" API. External image URLs will be filtered out.
content_source_url Yes The URL to the original page of an article. This is the URL to be redirected to after Read More is tapped.
need_open_comment No Uint32 Indicates whether to enable comment. 0: Disabled; 1: Enabled.
only_fans_can_comment No Uint32 Indicates whether to allow followers to comment only. 0: All users; 1: Followers.

Response Description

{
   "media_id":MEDIA_ID
}

The media_ID of the added article asset is returned.

# Uploading Image in Article to Obtain URL

Images uploaded via this API are excluded from the maximum storage limit of 5,000 images for an Official Account's media asset library. Only JPG/PGN images smaller than 1 MB are supported.

API Request Format

HTTP request method: POST. HTTPS protocol is used.
https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN
Calling Example (using the curl command to upload an image via FORM):
curl -F media=@test.jpg "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN"

Parameters

Parameter Required Description
access_token Yes The credential for API call
media Yes The identifier of the media file in form-data, including information such as filename, filelength, and content-type.

Response Description The result returned for a successful request:

{
    "url":  "http://mmbiz.qpic.cn/mmbiz/gLO17UPS6FS2xsypf378iaNhWacZ1G1UplZYWEYfwvuU6Ont96b1roYs CNFwaRrSaKTPCUdBK9DgEHicsKwWCBRQ/0"

}

The above URL is the URL of the uploaded image and can be used in articles.

# Adding Other Types of Permanent Assets

API Request Format

This API is called via a POST form. The form ID is "media" and includes the asset content to be uploaded, as well as information such as filename, filelength, and content-type. Note: Images will be put into the default group of Media Asset Management module on Official Accounts Platform.

HTTP request method: POST. HTTPS protocol is used.
https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN&type=TYPE
Calling Example (using the curl command to add another type of permanent asset via FORM. See more information for the use of curl.)

Parameters

Parameter Required Description
access_token Yes The credential for API call
type Yes Media file types, including images (parameter = "image"), voice (parameter = "voice"), videos (parameter = "video"), and thumbnails (parameter = "thumb").
media Yes The identifier of the media file in form-data, including information such as filename, filelength, and content-type.

Note the following when adding permanent videos:

Another form is required via POST to upload videos. The ID is "description" and includes a description of the asset. The content is in JSON format as below:

{
    "title":VIDEO_TITLE,
    "introduction":INTRODUCTION
}

Calling example for adding permanent videos:

curl "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN&type=TYPE" -F media=@media.file -F  description='{"title":VIDEO_TITLE, "introduction":INTRODUCTION}'

Parameters

Parameter Required Description
title Yes The title of the video
introduction Yes The description of the video

Response Description

{
  "media_id":MEDIA_ID,
  "url":URL
}

Response Parameters

Parameter Description
media_id The media_id for added permanent asset
url Image URL of the added image (this field will be returned only for adding images)

The returned JSON packet for a failed request (this is an example of invalid media type):

{"errcode":40007,"errmsg":"invalid media_id"}