代码之家  ›  专栏  ›  技术社区  ›  Matt

如何在BigCommerce中更新小部件的模板

  •  0
  • Matt  · 技术社区  · 5 年前

    我已经使用content/widget templates api端点构建了一个小部件,将此数据用作请求中的主体

    {
      "name": "Test Widget One",
      "template": "<h1>Test Widget One</h1>",
      "schema": [
           {
          "type": "tab",
          "label": "Content",
          "sections": []
           }
        ]
    }
    

    如果我想编辑该模板,该怎么办?如果我用一个新模板重新发布这个请求,它将创建一个同名的新小部件。我已经获取了提供的模板uuid,并形成了这样一个请求

    {
      "name": "Test Widget One",
      "widget_configuration": {
        "images": [
          {
            "image_url": "{{where-the-image-should-link-to}}",
            "image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/1280x1280/products/91/309/thekinfolktablecover_1024x1024__80715.1456436719.jpg?c=2&imbypass=on"
          },
          {
            "image_url": "{{where-the-image-should-link-to}}",
            "image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/1280x1280/products/109/361/kinfolkessentialissue_1024x1024__22507.1456436715.jpg?c=2&imbypass=on"
          },
          {
            "image_url": "{{where-the-image-should-link-to}}",
            "image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/500x659/products/85/282/livingwithplants_grande__26452.1456436666.jpg?c=2&imbypass=on"
          }
        ]
      },
       "widget_template": {
        "uuid": "my-uuid",
        "template": "<h1>This is an update to test widget One</h1>"
      },
      "widget_template_uuid": "my-uuid"
    }
    

    响应不会报告任何错误,但不会更新小部件的实际模板。

    这是我得到的回应: (为了示例,我将uuid替换为“uuid”)

    {
        "data": {
            "uuid": "uuid",
            "name": "Test Widget One",
            "widget_configuration": {
                "images": [
                    {
                        "image_url": "{{where-the-image-should-link-to}}",
                        "image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/1280x1280/products/91/309/thekinfolktablecover_1024x1024__80715.1456436719.jpg?c=2&imbypass=on"
                    },
                    {
                        "image_url": "{{where-the-image-should-link-to}}",
                        "image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/1280x1280/products/109/361/kinfolkessentialissue_1024x1024__22507.1456436715.jpg?c=2&imbypass=on"
                    },
                    {
                        "image_url": "{{where-the-image-should-link-to}}",
                        "image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/500x659/products/85/282/livingwithplants_grande__26452.1456436666.jpg?c=2&imbypass=on"
                    }
                ],
                "_": {
                    "id": "id"
                }
            },
            "widget_template": {
                "uuid": "uuid",
                "name": "Test Widget One",
                "schema": [
                    {
                        "type": "tab",
                        "label": "Content",
                        "sections": []
                    }
                ],
                "template": "<h1>Test Widget One</h1>",
                "date_created": "2020-08-05T17:46:37.802Z",
                "date_modified": "2020-08-05T17:46:37.818Z",
                "kind": "custom",
                "storefront_api_query": "",
                "icon_name": "default",
                "template_engine": "handlebars_v3",
                "client_rerender": false,
                "site_id": 1000,
                "current_version_uuid": "uuid",
                "channel_id": 1
            },
            "date_created": "2020-08-05T18:04:24.512Z",
            "date_modified": "2020-08-05T18:04:24.512Z",
            "description": "",
            "storefront_api_query_params": {},
            "site_id": 1000,
            "version_uuid": "uuid",
            "channel_id": 1
        },
        "meta": {}
    }
    

    我需要做什么来更新已经上传的自定义小部件的模板?

    0 回复  |  直到 5 年前
        1
  •  0
  •   Dharman vijay    5 年前

    可以使用正确的API调用和HTTP“方法”删除或更新现有模板。

    例如,您可以执行HTTP删除或PUT(POST是您似乎正在执行的操作,即添加新模板)。确保在下面的路径中设置了正确的uuid以更新或删除它:

    https://api.bigcommerce.com/stores/{{$$.env.store_hash}}/v3/content/widget-templates/:uuid