Hi! I’m requesting this URL https://site-api.datocms.com/items/${query?.itemId}
and it doesn’t return the _seoMetaTags field. Is it a limitation or should I configure something to work?
Hi @maysa.bonfante,
There’s a slight difference between how this is handled by the GraphQL CDA and the REST CMA.
_seoMetaTags
is something our GraphQL resolver handles for you, combining the record-level overrides (if any are specified) with the site-level SEO data as a fallback.
But if you’re using site-api.datocms.com
, that is our separate Content Management API and it doesn’t handle that fallback quite as automatically.
You can still get the info, but it takes two separate calls:
-
GET https://site-api.datocms.com/items/${itemId}
to fetch the record first. If it has an SEO field, the overrides will be in there, like:"seo": { "image": null, "title": "record level title", "no_index": false, "description": null, "twitter_card": null }
-
BUT you also have to separately fetch the site-level SEO using
GET https://site-api.datocms.com/site
, which will get you aglobal_seo
property like:"global_seo": { "site_name": "Site-level website name", "fallback_seo": { "title": "Site-level fallback title", "description": "Site-level fallback description", "image": null, "twitter_card": "summary_large_image", "no_index": null }, "title_suffix": "", "twitter_account": null, "facebook_page_url": "" },
Then you can combine the two, like:
const pageTitle = seo.title ?? global_seo.fallback_seo.title ?? global_seo.site_name;
const pageDescription = seo.description ?? global_seo.fallback_seo.description;
// etc., basically testing for the any overrides in the record-level `seo` field
// and then falling back to `global_seo.fallback_seo` if it doesn't have any
Does that help?
Yes! I believe that’s what I was looking for.