Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3667

Strapi CMS PUT for repeatable items or media via REST API

$
0
0

How do I update each asset or all assets via PUT rest API? If this is my document:

{"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": [            {"id": 8,"documentId": "pku4d0m6e5x43ehr0f6o6ar7","name": "142bdf157191583.63749e49bcb3a.jpg","alternativeText": null,"caption": null,"width": 2048,"height": 2048,                ...            },            {"id": 7,"documentId": "noz98h30ln5qatv7gc5nqhhp","name": "27a5197bdaf301a49d1fa23eb2391256.png","alternativeText": null,"caption": null,"width": 900,"height": 900,                ...            }        ]    },"meta": {}}

How do I update each asset or all assets via PUT rest API?

I tried eg. this:

https://localhost/api/documents/bui11070zyexg20k1xg9fdxx

body(JSON)

{"data":         {"name": "Test Document Updated","assets": [                {"caption": "Test 1"                },                {"caption": "Test 2"                }            ]        }}

but get 400 Bad Request:

{"data": null,"error": {"status": 400,"name": "ValidationError","message": "Invalid relations","details": {"errors": [                {"path": [],"message": "Invalid relations","name": "ValidationError"                }            ]        }    }}

this works no problem:

{"data":         {"name": "Test Document Updated"        }}

if I PUT the entire assets array back with changed caption field, I get:

{"data": null,"error": {"status": 400,"name": "ValidationError","message": "Invalid key documentId","details": {"key": "documentId","source": "body"        }    }}

Viewing all articles
Browse latest Browse all 3667

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>