ibij
ibij

Reputation: 51

ContentFul: Unable to retrieve images in RichText

When I embed an image in rich text, I think I get two responses, sys and fields, but why can't I get them? The plan is using the free plan.

--ps-- I use a DeepL

{
  nodeType: "embedded-asset-block",
  content: [],
  data: {
    target: {
      sys: {
        id: "roh929XgOJMh1YF23UYW2",
        type: "Link",
        linkType: "Asset",
      },
    },
  },
};

Upvotes: 0

Views: 496

Answers (1)

stefan judis
stefan judis

Reputation: 3879

Contentful DevRel here. 👋 To get the linked asset data you have to adjust the query to include it.

For the following RichText Content

Richtext including Contentful logo

you can retrieve the image information as follows.

query {
  quoteCollection(limit: 10) {
    items {
      richText {
        links {
          assets {
            block {
              title
              url
            }
          }
        }
        json
      }
    }
  }
}

In the example query I'm using the links field to access references and assets included in the richText field.

You can read more about RichText queries in the docs.

Upvotes: 1

Related Questions