Monday, 13 March 2017

How to retrieve linked fields in Contentful query

I'm using Contentful and have a content model which uses a series of related fields. I am querying my content in NodeJS using the JS api. If I call get entries, like so

contentfulClient.getEntries({
    content_type: 'homePage'
})

it fetches all the content of type homePage, and includes the actual field data for each related field, like so

"subField": {
        "sys": {
            "space": {
                "sys": {
                    "type": "Link",
                    "linkType": "Space",
                    "id": "#######"
                }
            },
            "id": "#######",
            "type": "Entry",
            "createdAt": "2017-03-10T15:58:25.697Z",
            "updatedAt": "2017-03-10T15:58:25.697Z",
            "revision": 1,
            "contentType": {
                "sys": {
                    "type": "Link",
                    "linkType": "ContentType",
                    "id": "homeSubField"
                }
            },
            "locale": "en-GB"
        },
        "fields": {
            "category": {
                "sys": {
                    "type": "Link",
                    "linkType": "Entry",
                    "id": "#######"
                }
            },
            "subFieldContent": "Some field content"
        }
    },

However, if I call a specific entry with an ID, like

contentfulClient.getEntry('1234567890').then(function(entries) {

Then each linked field is just returned as a reference with an ID, like

"subField": {
            "sys": {
                "type": "Link",
                "linkType": "Entry",
                "id": "#######"
            }
        },

How can I get the full text when calling getEntry, like I do with getEntries?



via Math

No comments:

Post a Comment