小程序直播 /商品管理 /更新商品

# 更新商品

> 接口应在服务器端调用,详细说明参见[服务端API](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/backend-api.html)。

> 本接口支持[云调用](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html)。需开发者工具版本 >= `1.02.1904090`(最新[稳定版下载](https://developers.weixin.qq.com/miniprogram/dev/devtools/stable.html)),`wx-server-sdk` >= `0.4.0`

## 接口说明

### 接口英文名

updateGoodsinfo

### 功能描述

调用此接口可以更新商品信息,审核通过的商品仅允许更新价格类型与价格,审核中的商品不允许更新,未审核的商品允许更新所有字段, 只传入需要更新的字段。

## 调用方式

### HTTPS 调用

```text
POST https://api.weixin.qq.com/wxaapi/broadcast/goods/update?access_token=ACCESS_TOKEN 
```

### 云调用

- 出入参和 HTTPS 调用相同,调用方式可查看[云调用说明文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html)
- 接口方法为: openapi.liveBroadcast.goodsUpdate

### 第三方调用

- 调用方式以及出入参和 HTTPS 相同,仅是调用的 token 不同
- 该接口所属的权限集 id 为:52
- 服务商获得其中之一权限集授权后,可通过使用[authorizer_access_token](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/api_authorizer_token.html)代商家进行调用

### 请求参数含义

| **参数**        | **类型** | **必填** | **说明**                                                     |
| :-------------- | :------- | :------- | :----------------------------------------------------------- |
| coverImgUrl     | String   | 是       | 填入mediaID(mediaID获取后,三天内有效);图片 mediaID 的获取,请参考以下文档: [New_temporary_materials](https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html);图片规则:图片尺寸最大300像素*300像素; |
| name            | String   | 是       | 商品名称,最长14个汉字,1个汉字相当于2个字符                 |
| priceType       | Number   | 是       | 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传) |
| price           | Number   | 是       | 数字,最多保留两位小数,单位元                               |
| price2          | Number   | 否       | 数字,最多保留两位小数,单位元                               |
| url             | String   | 是       | 商品详情页的小程序路径,路径参数存在 url 的,该参数的值需要进行 encode 处理再填入 |
| goodsId         | Number   | 是       | 商品ID                                                       |
| thirdPartyAppid | String   | 否       | 当商品为第三方小程序的商品则填写为对应第三方小程序的appid,自身小程序商品则为'' |

### 返回参数

| **参数** | **类型** | **说明** |
| :------- | :------- | :------- |
| errcode  | number   | 返回码   |

## 调用示例

> 示例说明: HTTPS请求

### 请求数据示例

```json
{    

    "goodsInfo": {        
        // 需要更新哪个字段就传入哪个字段,goodsId 必传        
        "coverImgUrl": "ZuYVNKk9sMP1X4m7FXdcDCKra251KDZTjS502UTV7gwalgLZXcrOhG6oNYX6c7AR",        
        "name":"TIT茶杯",        
        "priceType":1,
        "price":99.5,
        // "price2": 150.5, priceType为2或3时必填
        "url": "pages/index/index",       
        "goodsId": 9     
    }
} 
```

### 返回数据示例

```json
{
    "errcode": 0,
    "errmsg": "ok"
} 
```

### 错误码

| 错误码 | 错误码取值                                              | 解决方案                                                     |
| :----- | :------------------------------------------------------ | :----------------------------------------------------------- |
| 40001  | invalid credential access_token isinvalid or not latest | 获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口 |
| 200002 | 参数错误                                                |                                                              |
| 300002 | 名称长度不符合规则                                      |                                                              |
| 300003 | 价格输入不合规(如现价比原价大、传入价格非数字等)      |                                                              |
| 300006 | 图片上传失败(如:mediaID过期)                         |                                                              |
| 300007 | 线上小程序版本不存在该链接                              |                                                              |
| 300010 | 商品审核状态不对(如商品审核中)                        |                                                              |
| 300011 | 操作非法(API不允许操作非 API 创建的商品)              |                                                              |
| 300015 |                                                         |                                                              |