How can I get the content type of an entry?

Pretty simple question. I thought it would be in the sys node but that only tells me if it’s an entry or link. Any ideas?

This should be included in sys.contentType.sys.id; however, if this is a reference field and you are using REST calls without leveraging one of the client libraries you will have to dig a little deeper. By default, full data for referenced entries are not included in the parent entry’s field data. Instead, you need to pass an include parameter, which will then add an includes array to the response. In this includes array you will find the full data for the referenced entry, which you can map to the field data on the parent via entry id. Hopefully this helps!

Are you trying to look for a specific type based on what’s in a rich text field?

If so, you need to catch two things, the BLOCKS or INLINES subtype (e.g. “BLOCKS.EMBEDDED_ASSET” and then the node inside of that. That node that it sounds like you found is correct, but it’s a few layers deeper than you might imagine (e.g. “sys?.contentType?.sys?.id”).

Here’s some sample code (React):

[BLOCKS.EMBEDDED_ASSET]: (node) => {
                switch (node?.data?.target?.fields?.file?.contentType){
                    case "application/pdf":
                        return <Button label={"Download PDF"} variant="secondary" url={`https:${node?.data?.target?.fields?.file?.url}`} />
                    default:
                        return (
                            <Image
                                src={`https:${node?.data?.target?.fields?.file?.url}`}
                                alt={node.data?.target?.fields?.description}
                                height={node?.data?.target?.fields?.file?.details?.image?.height}
                                width={node?.data?.target?.fields?.file?.details?.image?.width}
                                objectFit="contain"
                            />
                        )
                }
            },
[INLINES.EMBEDDED_ENTRY]: (node) => {
                switch(node?.data?.target?.sys?.contentType?.sys?.id) {
                    case "reference":
                        return <InlineReference {...node.data.target.fields} />
                    case "button":
                        return <Button {...node.data.target.fields} />
                }
            }