clay1
July 22, 2024, 11:21pm
1
When querying data through the DatoCMS Content Delivery API, I am getting build errors when including the header ‘X-Include-Drafts’ with the value ‘false’. If the value is set to ‘true’, or if that header is excluded entirely, then the query seems to work just fine.
My goal is to set different values for that header depending on the build environment.
roger
July 23, 2024, 8:16pm
2
Hi @clay1 ,
Sorry, this appears to be by design. If you log the API response, it explicitly says:
{
"data": [
{
"id": "c6822a",
"type": "api_error",
"attributes": {
"code": "INVALID_X_INCLUDE_DRAFTS_HEADER",
"details": {
"message": "X-Include-Drafts header can only be set to `true`"
}
}
}
]
}
Can you change the conditional to just not set that header depending on the build environment?
For example, instead of something like this:
const headers = {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json',
'X-Include-Drafts': isProduction ? true : false,
};
Can it be something like this?
const headers = {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json',
...(isProduction && {'X-Include-Drafts': true})
};
clay1
August 2, 2024, 3:22pm
3
@roger That works. It might be worth updating the docs to indicate that this header is not actually boolean. Thanks for your help.
1 Like
roger
August 12, 2024, 10:14pm
4
Good idea! I’ll add it to the next batch of documentation updates. Thanks for the report
Edit: It’s been updated now:
Learn how to use the DatoCMS API endpoint and various header modes to customize your content delivery. Explore environment specifications, preview mode, strict mode, and visual editing setup.
1 Like