Hi Dato community,
We are “again” working on a plugin and I wanted to know if there is a way to retrieve the Presentation fields available in a Model:
Today we are using find
method with the API client : await client.items.find(recordId);
Is there a way to retrieve these fields from the model we are searching for?
Thanks for your help.
Best
roger
October 31, 2024, 6:57pm
3
A little more explanation: That metadata is associated with a field (so it’s fields.find()
), rather than getting the actual content data associated with a record (which is what items.find()
does).
The field ID is that GHOCe8r...
string in the upper right of the dialog. It’s also in the URL when you edit a specific field. You can also use the CMA to list all fields of a model .
roger:
A little more explanation: That metadata is associated with a field (so it’s fields.find()
), rather than getting the actual content data associated with a record (which is what items.find()
does).
The field ID is that GHOCe8r...
string in the upper right of the dialog. It’s also in the URL when you edit a specific field. You can also use the CMA to list all fields of a model .
Thank you guys for your explanation …
I’ve just made a quick test with hardcoded value:
const field = await client.fields.find('ZgLZT16CQ_OCR0Dxxxxx'); // xxx is just not to share it :)
console.log(field);
I’m getting the following error:
linkField.tsx:108 Uncaught (in promise) Error: GET https://site-api.datocms.com/fields/ZgLZT16CQ_OCR0Dxxxxx: 404
[
{
"id": "302048",
"type": "api_error",
"attributes": {
"code": "NOT_FOUND",
"details": {}
}
}
]
Do I miss something?
Thanks for your precious help guys!
roger
November 1, 2024, 1:20pm
5
@ghislain.flandin , I am SO sorry. I hastily added to Marcelo’s answer without having looked at your screenshot in sufficient detail.
It should be itemTypes.find()
for what you want, not fields.find()
.
https://www.datocms.com/docs/content-management-api/resources/item-type/self
And its props title_field
, image_preview_field
, and excerpt_field
are in there: https://www.datocms.com/docs/content-management-api/resources/item-type
Sorry about that! The dialogs for editing a field and editing a model look very similar, and we both made a mistake before answering you!
Thank you so much, works fine.
1 Like