Home > Blockchain >  Shopware 6 Admin Api - Updating existing record through patch method. Not working
Shopware 6 Admin Api - Updating existing record through patch method. Not working

Time:11-11

shopware 6 admin api patch - why it's failing? I get error "Only single write operations are supported"

Following is api for rule-condition entity in the database, I update it with Id. For same api get method is working!

url: api/rule-condition/dbb0d904c7c14860a9a94cf26b94eca6

method: patch

json body

[
    {
        "op": "replace",
        "path": "/data/attributes/value/email",
        "value": "[email protected]"
    }
]

response:

{ "errors": [ { "code": "0", "status": "400", "title": "Bad Request", "detail": "Only single write operations are supported. Please send the entities one by one or use the /sync api endpoint.", .......

I also tried changing json body to following

{
    "data": {
        "attributes": {
            "value": {
                "email": "[email protected]"
            }
        }
    } }

Still it's not updating. Can somebody check and let me know what am i missing?

Documentation I followed: https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyMzA4NTQ5-writing-entities

This website has all apis and example methods. https://swagger.docs.fos.gg/, rule-condition entity can also be found there.

Btw : I used postman for testing api

CodePudding user response:

You're passing an array of objects in the request body, suggesting you want to update multiple records, but the endpoint only supports updating a single record. The correct payload in your case should look like this:

{
    "value": { 
        "operator": "=", 
        "email": "[email protected]" 
    }
}

Notice that value is a json field and not only includes a single value. The exact content and the names of the properties of value depend on the type of condition used and usually it also includes the operator used in the condition.

  • Related