Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Dynamic Zones via REST API no longer works #2327

Open
spyderdsn opened this issue Dec 15, 2024 · 3 comments
Open

Updating Dynamic Zones via REST API no longer works #2327

spyderdsn opened this issue Dec 15, 2024 · 3 comments

Comments

@spyderdsn
Copy link

spyderdsn commented Dec 15, 2024

  • Strapi version: v5
  • Database: MySQL

Describe the bug

Updating dynamic zones via REST API does not work. Tried multiple approaches:

  • sending id & documentId
  • not sending id & documentId
  • using connect, disconnect or set
  • sending the entire array back
  • sending partial array back
{
	"data": {
		"id": 5,
		"documentId": "bui11070zyexg20k1xg9fdxx",
		"name": "Test Document",
		"createdAt": "2024-12-13T05:52:18.359Z",
		"updatedAt": "2024-12-13T21:15:20.414Z",
		"publishedAt": "2024-12-13T21:15:20.966Z",
		"locale": "en",
		"assets": [
			{
				"name": "142bdf157191583.63749e49bcb3a.jpg",
				"alternativeText": null,
				"caption": null,
				"width": 2048,
				"height": 2048,
				... rest of object here ...
			},
			{
				"name": "27a5197bdaf301a49d1fa23eb2391256.png",
				"alternativeText": null,
				"caption": null,
				"width": 900,
				"height": 900,
				... rest of object here ...
			}
		]
	},
	"meta": {}
}
{
   "data":{
      "name":"Document Updated 1",
      "assets":{
         "connect":[
            {
                  "id": 8,
                  "documentId": "pku4d0m6e5x43ehr0f6o6ar7",
                  "alternativeText": "Test 1",
                   "caption": "Test 1"
            },
            {
                  "id": 7,
                  "documentId": "noz98h30ln5qatv7gc5nqhhp",
                  "alternativeText": "Test 2",
                   "caption": "Test 2"
            }
         ]
      }
   }
}

more examples here: https://forum.strapi.io/t/put-for-repeatable-items-or-media-via-rest-api/49520/2

Steps to reproduce the behavior

use Postman or Insomnia to send the payload.

@Boegie19
Copy link
Contributor

Boegie19 commented Dec 16, 2024

@spyderdsn You have to add __component: 'compo.type' to the assets so that the dynamic zone knows what component you want to create or update this seems to be a documentation issue so will ask somone to move this issue to the docs repo since this is not documented for API or DocumentService.

@spyderdsn
Copy link
Author

{
	"data": {
		"id": 5,
		"documentId": "bui11070zyexg20k1xg9fdxx",
		"name": "Test Document",
		"createdAt": "2024-12-13T05:52:18.359Z",
		"updatedAt": "2024-12-13T21:15:20.414Z",
		"publishedAt": "2024-12-13T21:15:20.966Z",
		"locale": "en",
		"assets": [
			{
                                "__component": "media",
                                "id": 8,
				"name": "142bdf157191583.63749e49bcb3a.jpg",
				"alternativeText": null,
				"caption": "Test 1",
				"width": 2048,
				"height": 2048,
				... rest of object here ...
			},
			{
                                "__component": "media",
                                "id": 7,
				"name": "27a5197bdaf301a49d1fa23eb2391256.png",
				"alternativeText": null,
				"caption": "Test 2",
				"width": 900,
				"height": 900,
				... rest of object here ...
			}
		]
	},
	"meta": {}
}

Thanks @Boegie19 I tried this, got 200 OK and responded with no changes. If I remove id I get a validation error.

@spyderdsn
Copy link
Author

Please provide a better example here for the time being. Thanks

@derrickmehaffy derrickmehaffy transferred this issue from strapi/strapi Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants