Problem/Motivation
My user accounts have an image file field (image, not media). I want to update the alt text of the image via JSON:API.
How can I do that?
Steps to reproduce
I tried
const myJsonData : InterfaceJsonUserDataOnlyAltText = {
data: {
id: userObject.id,
type: 'user--user',
relationships: {
field_ref_image: {
data: {
id: fileUuid,
type: 'file--file',
meta: {
alt: userData.my_alt_text,
},
},
},
},
},
};
However, when I post with axios, I get this error:
Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException: No route found that matches "Content-Type: application/vnd.api+json" in Drupal\Core\Routing\ContentTypeHeaderMatcher->filter() (line 49 of /app/web/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php).
Comments
Comment #3
bbralaIf you want to update data on a related object you should post to the endpoint of that specific object. This would probably be:
When updating relations in an endpoint you can only update the relationsship properties, not the data of the related resource.
Does this fix your issue?
Comment #4
bbralaComment #5
bbralaAs we have no activity on this support request im going to assume the issue fixed.
Comment #6
wim leersCrediting you, @bbrala :) ;)
Comment #7
wim leers(Based on the error, I'd say they were indeed sending the request to the wrong route/URL.)
Comment #8
ptmkenny commentedThanks @bbrala, I didn't realize I needed to post to the object's endpoint.
I'm sorry to be late getting back to the issue, but this can definitely be closed.
Comment #9
wim leersLovely, thank you!
Comment #10
bbralaComment #12
hlopes commentedCan I get some aditional clarification here?
Tried post, put, patch with the following data
to
/jsonapi/[entity_type]/[bundle]/[entity_uuid]/relationships/[field_name]But the best I got was a 409 "You can only POST to to-many relationships"
Using PATCH seems to work but the fields (alt + title) aren't updated.
Comment #13
vincenzocacciatore commentedI am sorry but it looks like the meta field of an image is property of the node and not of the file.
Could you please help me to solve how to update alt field of an image?