Content Delivery API returns null content if browser has wrong language set

Vote:
 

Hey,

I've spent couple of hours investigating why my content API returns null content response. I've finally managed to find the reson. It has turned out that my browser has set multiple languages and the first one was "en-US" so it is different then the one that is set in my cms, which is "en". My question is, if it is a bug? or there is some logic behind this?

In ContentApiController only first language is taken so I guess this is the reason, why the api couldn't load any content. I know that we can manually pass accept-language header but I'm not sure If an api response should depends on which language I have configured in my browser. 

 return this.ResultFromContent(this._contentLoaderService.Get(new ContentReference(contentReference), languages != null ? languages.FirstOrDefault<string>() : (string) null), expand);
#200914
Edited, Jan 30, 2019 15:02
Vote:
 

Hi, sorry for the late reply but hope that this answer could help other people.

You are right that ContentDeliveryApi returns the content based on the language passed in the Accept-Language header. And I think that Accept-Language header is not really meant to be the language you configured in your browser, but it is more likely to be used to specify the locale variant of content that the client prefers (please check for more detail here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language).

The problem is some browser (Chrome for example) automatically adds it's preferred language to the Accept-Language header if the header value is not manually set by the user. So in this case, I think that the client should manually pass Accept-Language header to prevent the browser from adding its own header value.

#219264
Apr 01, 2020 6:39
Vote:
 

Hi Maciej

If you are using the Content Delivery API in an AJAX application, you can simply specify/override the Accept-Language header value in your front end code. I have a code sample about this at the very bottom of this blog post.

#221817
Apr 26, 2020 6:08
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.