Bug: 'X-Include-Drafts': 'false' header breaks query

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.

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})
};

@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

Good idea! I’ll add it to the next batch of documentation updates. Thanks for the report :slight_smile:

Edit: It’s been updated now: