Shopee V2 API虾皮开发者平台推送商品到已授权店铺

2024-12-12  本文已影响0人  i娟儿

--a) 授权(略)
--b) 其他前置接口,例如分类、属性等(略)
--c) 授权对象店铺配置说明(沙箱测试指引)
1、入参JSON串

{"attributes":[],"original_price":10.3,"description":"Kid's toys 7-12 years old","item_name":"Kid's toys 7-12 years old","weight":0.5,"category_id":102080,"dimension":{"package_height":11,"package_length":11,"package_width":11},"image":{"image_id_list":["sg-11134201-7r98o-m3py5bn77mrj29","sg-11134201-7r98o-m3q7rmnb9gcfa8","sg-11134201-7r98o-m3hhtbe7mr5rb9"]},"brand":{"brand_id":0},"description_type":"normal","logistic_info":[{"size_id":1,"is_free":true,"logistic_id":20011,"enabled":true,"estimated_shipping_fee":5}],"pre_order":{"is_pre_order":false,"days_to_ship":3},"condition":"NEW","item_status":"NORMAL","seller_stock":[{"stock":5}]}

2、PHP-demo

    /**
     * 上传商品demo
        多仓库未开启时:如果无法启用多仓库功能,可以按照以下步骤处理:
        1、修改代码逻辑,跳过仓库相关的 API 调用,直接使用单仓模式。
        2、在商品上传接口中,将仓库字段配置为默认值(参考入参)
     * @return array|object
     */
    public function addProductItem($shopId = 0) {
        // 验参
        if(!$shopId){
            return $this->error('参数错误');
        }
        // 入参
        $params = [
            "attributes"  =>[],
            "original_price" => 10.3,
            "description" => "Kid's toys 7-12 years old",
            "item_name" => "Kid's toys 7-12 years old",
            "weight" => 0.5,
            "category_id" => 102080,
            "dimension" => [
                "package_height" => 11,
                "package_length" => 11,
                "package_width" => 11
            ],
            "image" => [
                "image_id_list" => [
                    "sg-11134201-7r98o-m3py5bn77mrj29",
                    "sg-11134201-7r98o-m3q7rmnb9gcfa8",
                    "sg-11134201-7r98o-m3hhtbe7mr5rb9"
                ]
            ],
            "brand" => [
                "brand_id" => 0, // 0为无品牌
//                "original_brand_name" => "NoBrand" // 替换为品牌名称
            ],
            "description_type"=> "normal",
            "logistic_info" => [ // 添加有效的物流信息,即使不发货也需要提供
                [
                    "size_id" => 1,
                    "is_free" => true,
                    "logistic_id" => 20011,
                    "enabled" => true,
                    "estimated_shipping_fee" => 5,
                ]
            ],
            "pre_order" => [
                "is_pre_order" => false,
                "days_to_ship" => 3
            ],
            "condition" => "NEW",     // 商品状况,确保为有效值
            "item_status" => "NORMAL", // 商品状态,确保为有效值(NORMAL表示上架)
            "seller_stock" => [  // 确保库存数量有效
                [
                    //"location_id" => "more", // 如果不支持多仓库,通常可以使用一个默认值
                    "stock" => 5     // 提供有效的库存数量,不能为null或0
                ]
            ]
        ];
        echo json_encode($params);die;
        // 获取AccessToken
        $token = $this->getAccessTokenMerchantLevel($shopId);
        $shopApi = new Shoapi();
        $response = $shopApi->call('product')
            ->access('add_item', $token['access_token']) // 需要替换为实际的access_token
            ->shop($shopId) // 替换为实际店铺ID
            ->request($params)
            ->response();

        return $response;
    }

3、推送成功返回示例:


image.png
上一篇 下一篇

猜你喜欢

热点阅读