Produce a series of multi-platform works
One story goes to several platforms. Each platform looks different, but the pictures are the same. This recipe runs a full round with the media library’s works: create a Xiaohongshu gallery and a WeChat article in one series that share pictures by id, read them out for a publish script, and write the link and numbers back after publishing. The example is “AI startup diary 01”. How you see these works in the Console is in Works in the help center.
Prerequisites
- A media library with at least 3 pictures. Step 1 gets their ids with
praxis.media.libraries.assets.list. - Works are open for your organization. While they are not, every works call returns
OPERATION_NOT_SUPPORTED. - Run the code in codemode, where
praxisis signed in and ready. You can also hand this recipe to your secretary or an agent and let it do the steps in codemode.
1. Get the picture ids
A work can only reference assets that are still in the same library, by asset id. List the library’s pictures and take the first 3:
const libraryId = "<library id>";
const images = await praxis.media.libraries.assets.list({ path: { library_id: libraryId }, query: { material_type: "image", limit: 3 },});const [coverId, deskId, noteId] = images.data.map(asset => asset.asset_id);Expected: images.data holds 3 assets, and coverId, deskId and noteId are strings. With fewer than 3, put more pictures in the library first.
2. Create the Xiaohongshu gallery
The Xiaohongshu version is a gallery: title, text, topics, cover and items in order. An item is a picture { asset_id, caption? } or a text segment { text }. series groups the versions of one story; it takes lower-case letters, digits, _ and -.
const gallery = await praxis.media.libraries.works.create({ path: { library_id: libraryId }, body: { kind: "gallery", series: "ai-diary-01", body: { title: "AI 创业第一天就踩坑", text: "第一天的三件事,第二件最离谱。", topics: ["AI创业", "创业日记"], cover: coverId, items: [ { asset_id: coverId }, { asset_id: deskId, caption: "桌上的笔记" }, { text: "下午换了个角度" }, { asset_id: noteId }, ], }, custom: { platform: "xiaohongshu" }, },});Expected: the returned gallery.kind is "gallery", gallery.revision is 1, and gallery.series is "ai-diary-01".
3. Create the WeChat article with the same pictures
The WeChat version is an article: title, summary, author, cover and a Markdown body. A picture in the body is written  and appears where it is written. These are the same ids as in the gallery: nothing is copied or uploaded again.
const article = await praxis.media.libraries.works.create({ path: { library_id: libraryId }, body: { kind: "article", series: "ai-diary-01", body: { title: "AI 创业日记 01:第一天,我把三件事都做错了", summary: "第一天的三个坑,和我后来怎么补的。", author: "小周", cover: coverId, body: [ "第一天的计划写得很满。", ``, "下午换了个角度,事情才有了头绪。", ``, ].join("\n\n"), }, custom: { platform: "wechat_mp" }, },});Expected: article.kind is "article" and article.series equals the gallery’s. If an id is not in this library, or has the wrong type (a cover or inline picture must be an image or sticker), the whole request is refused with every bad reference listed and nothing is saved; fix them and send again.
4. List the series
const series = await praxis.media.libraries.works.list({ path: { library_id: libraryId }, query: { series: "ai-diary-01" },});// series.data: [{ id, kind, title, series, cover_url, item_count, missing_count, updated_at }]Expected: series.data has 2 rows, with kind gallery and article. The list also filters by kind and matches titles with q. Rows carry no body; read a work (next step) for that.
5. Read it out for the publish script
Add expand: "assets" when reading to get each referenced asset’s address, thumbnail and size in the same request. Addresses expire, so read again just before publishing and do not store them.
const work = await praxis.media.libraries.works.retrieve({ path: { library_id: libraryId, work_id: gallery.id }, query: { expand: "assets" },});
const pictures = work.body.items .filter(item => "asset_id" in item) .map(item => ({ url: work.assets[item.asset_id].url, caption: item.caption ?? "" }));// work.missing 列出已被删除的素材编号;正文里仍保留它们原来的位置。Expected: pictures gives each picture’s url in item order. work.assets is keyed by asset id, each with url and thumbnail_url, and pictures also have width and height. work.missing is an empty array; if it is not, an asset it referenced was deleted, so replace it before publishing.
6. Write the link and numbers back after publishing
Write the platform’s link and numbers back to the work. custom merges as a JSON Merge Patch (RFC 7396): send only your own keys and you will not overwrite keys others wrote; a key set to null is removed; nested objects merge level by level. With if_revision, the change applies only if the work is still at the revision you read.
const read = await praxis.media.libraries.works.retrieve({ path: { library_id: libraryId, work_id: gallery.id },});
const written = await praxis.media.libraries.works.update({ path: { library_id: libraryId, work_id: gallery.id }, body: { custom: { published_url: "https://www.xiaohongshu.com/explore/<note id>", stats: { views: 12840, likes: 936 }, }, if_revision: read.revision, },});A few days later, update only the numbers: send just stats, and the existing published_url and platform stay as they are.
await praxis.media.libraries.works.update({ path: { library_id: libraryId, work_id: gallery.id }, body: { custom: { stats: { views: 20310, likes: 1502 } } },});Expected: written.custom.published_url is the link you wrote, and written.revision is one more than read.revision. If someone changed the work after you read it, the update returns 409 REVISION_CONFLICT: read again and resend with the new revision.
7. Verify
const check = await praxis.media.libraries.works.retrieve({ path: { library_id: libraryId, work_id: gallery.id },});console.log(check.custom);// { platform: "xiaohongshu", published_url: "https://…", stats: { views: 12840, likes: 936 } }In the Console, open this library’s 作品 tab and pick the series ai-diary-01: you see the gallery and the article as two cards. Open the gallery and the 自定义字段 (Custom fields) on the right show published_url, stats.views and stats.likes.
Troubleshooting
| Symptom | Cause | What to do |
|---|---|---|
Every works call returns OPERATION_NOT_SUPPORTED | Works are not open for your organization | Do not retry; ask the platform to open them |
| Creating a work reports a reference error | An id is not in this library, was deleted, or has the wrong type | The error lists every bad id; fix them and resend the whole request |
| Creating a work reports an unknown field | A field the work does not store, such as price | Price and stock stay in your own business system; put business fields in custom |
An update returns 409 REVISION_CONFLICT | The work changed after you read it | Read again and update with the new revision |
work.missing is not empty | A referenced asset was deleted later | Replace the asset, update the work with a whole new body, then publish |
Clean up
Deleting a work deletes only the work; the assets it referenced are kept:
await praxis.media.libraries.works.delete({ path: { library_id: libraryId, work_id: gallery.id } });await praxis.media.libraries.works.delete({ path: { library_id: libraryId, work_id: article.id } });Next steps
- Works API and limits: fields of the four kinds, count limits and the limits on
custom. - Help center: Works: preview in each platform’s look in the Console and see what breaks a limit.
- For other categories such as recipes or property listings, use the
blockskind and put business fields incustom; see the developer page.