【问题标题】:Shopware 6 Admin Api - Updating existing record through patch method. Not workingShopware 6 Admin Api - 通过补丁方法更新现有记录。不工作
【发布时间】:2022-11-10 17:51:16
【问题描述】:

shopware 6 admin api 补丁 - 为什么会失败?我收到错误"Only single write operations are supported"

以下是数据库中rule-condition 实体的api,我用Id 更新它。 对于相同的 api get method 正在工作!

url: api/rule-condition/dbb0d904c7c14860a9a94cf26b94eca6

method:补丁

json 正文

[
    {
        "op": "replace",
        "path": "/data/attributes/value/email",
        "value": "test@gmail.com"
    }
]

回复:

{ “错误”:[ { “代码”:“0”, “状态”:“400”, "title": "错误请求", "detail": "仅支持单次写入操作,请一一发送实体或使用 /sync api 端点。", …………

我也尝试将 json body 更改为以下

{
    "data": {
        "attributes": {
            "value": {
                "email": "test@gmail.com"
            }
        }
    } }

仍然没有更新。有人可以检查并让我知道我错过了什么吗?

我遵循的文档: https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyMzA4NTQ5-writing-entities

这个网站有所有的api和示例方法。 https://swagger.docs.fos.gg/, rule-condition 实体也可以在那里找到。

顺便说一句:我使用邮递员来测试 api

【问题讨论】:

    标签: api patch shopware6 shopware6-api


    【解决方案1】:

    您在请求正文中传递了一组对象,建议您要更新多条记录,但端点仅支持更新一条记录。在您的情况下,正确的有效负载应如下所示:

    {
        "value": { 
            "operator": "=", 
            "email": "test@gmail.com" 
        }
    }
    

    请注意,value 是一个 json 字段,不仅包含单个值。 value 属性的确切内容和名称取决于使用的条件类型,通常还包括条件中使用的运算符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-16
      相关资源
      最近更新 更多