You need to enable JavaScript to run this app. VBA调用WooCommerce API新增分类报rest_missing_callback_param错误求解
优惠活动
大模型
产品
解决方案
定价
更多

VBA调用WooCommerce API新增分类报rest_missing_callback_param错误求解

问题根因

你当前调用的WooCommerce单个产品分类创建接口,要求请求体为单个JSON对象。你将分类参数封装在了数组中,接口解析参数时无法从外层获取到name字段,因此触发参数缺失报错。


修复方案

移除Collection封装逻辑,直接将存储分类属性的Dictionary转为JSON发送即可,修改后的代码如下:

Public Sub woo_Post_category()

Dim xmlhttp As New MSXML2.XMLHTTP60
Dim myurl As String
Dim Json As Object

myurl = "https://example.com/wp-json/wc/v3/products/categories"

xmlhttp.Open "POST", myurl, False

xmlhttp.setRequestHeader "authorization", "Basic " & <SECRET_HERE>
xmlhttp.setRequestHeader "content-type", "application/json"

Dim inner As Dictionary
Set inner = New Dictionary

inner("name") = "Automotive parts and accessories"
inner("slug") = "Automotive parts and accessories"
inner("parent") = 0
inner("display") = "default"
            
Debug.Print ConvertToJson(inner, Whitespace:=3)
xmlhttp.send (ConvertToJson(inner, Whitespace:=3))
Debug.Print xmlhttp.responseText

End Sub

补充说明

如果你需要批量创建分类,需要调用专门的批量操作接口,同时在请求参数外层加create字段包裹分类数组,当前使用的单个分类创建接口不支持数组格式的请求体。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.14 02:21:03