Returns all fields in the project that reference a specific model (works both for Models and Block Models)
Returns an array of resource objects of type field
1import { buildClient } from "@datocms/cma-client-node";2 3async function run() {4 const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });5 6 const modelIdOrApiKey = "blog_post";7 8 const fields = await client.fields.referencing(modelIdOrApiKey);9 10 for (const field of fields) {11 // Check the 'Returned output' tab for the result ☝️12 console.log(field);13 }14}15 16run();
1{2 id: "Pkg-oztERp6o-Rj76nYKJg",3 label: "Title",4 field_type: "string",5 api_key: "title",6 localized: true,7 validators: { required: {} },8 position: 1,9 hint: "This field will be used as post title",10 default_value: { en: "A default value", it: "Un valore di default" },11 appearance: {12 editor: "single_line",13 parameters: { heading: false },14 addons: [{ id: "1234", field_extension: "lorem_ipsum", parameters: {} }],15 },16 deep_filtering_enabled: true,17 item_type: { type: "item_type", id: "DxMaW10UQiCmZcuuA-IkkA" },18 fieldset: null,19}