{"record":{"id":"c6f7280b0e930f46","repo":"TryGhost/Ghost","slug":"failed-to-fetch-site-data-c6f728","errorCode":null,"errorMessage":"Failed to fetch site data","messagePattern":"Failed to fetch site data","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/comments-ui/src/utils/api.ts","lineNumber":52,"sourceCode":"    // To fix pagination when we create new comments (or people post comments\n    // after you loaded the page), we need to only load comments created AFTER the page load\n    let firstCommentCreatedAt: null | string = null;\n\n    const api = {\n        site: {\n            settings() {\n                const url = contentEndpointFor({resource: 'settings'});\n                return makeRequest({\n                    url,\n                    method: 'GET',\n                    headers: {\n                        'Content-Type': 'application/json'\n                    }\n                }).then(function (res) {\n                    if (res.ok) {\n                        return res.json();\n                    } else {\n                        throw new Error('Failed to fetch site data');\n                    }\n                });\n            }\n        },\n        member: {\n            identity() {\n                const url = endpointFor({type: 'members', resource: 'session'});\n                return makeRequest({\n                    url,\n                    credentials: 'same-origin'\n                }).then(function (res) {\n                    if (!res.ok || res.status === 204) {\n                        return null;\n                    }\n                    return res.text();\n                });\n            },\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/TryGhost/Ghost/blob/47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe/apps/comments-ui/src/utils/api.ts#L34-L70","documentation":"The comments-ui site.settings() method GETs the Ghost Content API settings endpoint (built via contentEndpointFor with the apiKey). If the response is not ok, it throws this generic message. This loads site-level config (title, labs flags, etc.) needed to render the comments widget.","triggerScenarios":"The Content API settings request returns 4xx/5xx. The apiKey is missing or invalid (401/403), the apiUrl is misconfigured (404), CORS blocks the request, or the Ghost server is down. contentEndpointFor returns '' if apiUrl or apiKey is absent, and fetching '' resolves to a relative URL that typically fails — but the fetch to a blank URL usually yields ok=false on a document response.","commonSituations":"The comments-ui script is embedded without the correct data-api-key or data-api-url attributes. The Content API key belongs to a different site. The Ghost instance is behind a CDN that blocks the request. The site URL in the script does not match the API URL origin, triggering CORS rejection.","solutions":["Verify the data-api-key and data-api-url attributes on the comments-ui script tag match the Ghost integration's Content API key and URL.","Check the Network tab for the settings GET status and response.","Ensure the Ghost site allows CORS from the page origin where comments-ui is embedded.","Confirm the Ghost instance is online and the Content API is enabled."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function isCommentsApiConfigured(apiUrl: string | undefined, apiKey: string | undefined): boolean {\n  return typeof apiUrl === 'string' && apiUrl.length > 0\n    && typeof apiKey === 'string' && apiKey.length > 0;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const settings = await api.site.settings();\n} catch (e) {\n  if (e instanceof Error && e.message === 'Failed to fetch site data') {\n    // render comments in a degraded state or hide with a message\n  }\n}","preventionTips":["Ensure the comments-ui script tag has valid data-api-key and data-api-url attributes.","Verify CORS is configured on the Ghost Content API for the embedding origin.","Confirm the Content API key matches the site integration before deploying the embed."],"tags":["network","fetch","comments-ui","content-api","settings"],"backgroundTag":null,"analyzedSha":"47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe","analyzedAt":"2026-08-13T01:25:26.651Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}