You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用WIX Blog REST API创建含richContent的草稿失败求助

WIX博客API创建草稿时richContent字段500错误解决办法

问题情况

调用WIX REST API创建博客草稿,只要携带richContent字段就会返回500错误:str.substring is not a function,但将该字段设为空对象(params.draftPost.richContent = {};)就能正常创建草稿。且相同的请求体在WIX官方API测试工具中可以正常运行。

原代码示例

//
// Create a new blog draft
//
const axios = require('axios')
const mySecret =      "obfuscated"
const account_id =    "3ce23514-62b3-4167-a04a-ad0b131b09e9"; 
const my_site_id =    "ab60bafa-00c1-409e-9225-4b1e53bc831e"; 
const headers = {
    "Content-Type":   "application/json",
    "Authorization":  mySecret,
    'wix-account-id': account_id,
    'wix-site-id':    my_site_id
}

const params = { "draftPost": {
    "title": "abc1",
    "memberId":"3ce23514-62b3-4167-a04a-ad0b131b09e9",   
    "richContent": {
        "nodes": [ 
        { 
            "type": "PARAGRAPH",
            "id": "foo",
            "nodes": [            {
              "type": "TEXT",
              "id": "foo2",
              "nodes": [],
              "textData":               {
                "text": "This is a paragraph of text.",
                "decorations": []
              }
            }],
            "paragraphData": {
              "textStyle": {"textAlignment": "AUTO"},
              "indentation": 0
            }
          } 
         ]
      }
    }
  ,"publish":false
  ,"fieldSets":["RICH_CONTENT"]
}

const options = {
  url: '/draft-posts',
  method: 'post', 
  baseURL: 'https://www.wixapis.com/blog/v3',
  headers: headers,
  params: params, // 错误所在
  timeout: 2000
}

axios(options)
  .then(function (response) {
     console.log(response);
  })
  .catch(function (error) {
    console.log(error.response.data);
  });

问题原因

Axios中params属性用于设置URL查询参数,而POST请求的请求体必须放在data属性中。你的代码把请求内容当成URL参数发送,导致WIX API无法正确解析richContent的嵌套结构,触发了字符串处理类错误。

解决方法

将options中的params: params替换为data: params即可:

const options = {
  url: '/draft-posts',
  method: 'post', 
  baseURL: 'https://www.wixapis.com/blog/v3',
  headers: headers,
  data: params, // 修改为data属性
  timeout: 2000
}

修改后重新调用API,richContent字段会被正确解析,草稿可正常创建。

内容的提问来源于stack exchange,提问作者DThompson55

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 05:10:12