Trouble with accessing metadata

Jun 11, 2011 at 8:12 PM

Hi I am getting an error back when trying to read metadata for Netflix.

I get the message 'AccessRestricted URI Denied'

I am using the following code


OData.defaultHttpClient.enableJsonpCallback = true;"$metadata", function (metadata) {
    // success callback
    console.debug('made it');
}, function (error) {
    // error callback
    alert("Error occurred " + error.message);
}, OData.metadataHandler);

Everything is find if I read regular data such as"", function (data) {....




Jun 12, 2011 at 2:11 AM

The underlying problem is that the server at doesn't support serializing OData metadata as JSON/JSONP, so you can't really get at it from a different domain. OData doesn't specify a JSON representation for metadata at the moment.

Another problem that you might run into is that the URLs specified don't start with "http://", so they look like URLs relative to the page that the script is running in, directly on the same server.

The recommended approach for dealing with metadata however should help work around. Typically you can get by without metadata, but if you need it to process things like content-mapped properties (which I believe the Netflix service doesn't require), the best way is to get the representation at development time and embed it along with the page in JavaScript literal format, to save an additional round-trip to the server. You can use datajs from a test page or shell script to help out with this, or just selectively embed the bits of metadata you care about.


Jun 12, 2011 at 3:56 AM


I've switched to pulling metadata via the server.

Just for general data (not metadata) is there a means to determine what formats a server supports? i.e. if remote server supports JSONP read data directly using datajs otherwise access via proxy?

Jun 12, 2011 at 7:00 AM

The protocol doesn't define a way of querying which formats it supports. Typically you can set the Accept header to ask for a specific format and rely on falling back to something else if it's not supported. The datajs handlers set up a preference for JSON but will deal with XML if that's all the server can handle. If the server really can't handle any of the formats you're asking for, it returns a specific HTTP status code, 415 - Unsupported Media Type.

That said, the story changes a bit with JSONP, because the mechanism relies on javascript injected into a SCRIPT tag in the browser to work around same-origin restrictions. So most of the read scenarios work, except those that can't produce javascript, produce broken javascript or rely on header information (as headers are inaccessible when using JSONP).

If you own the service, then you can often find ways to work around many of these problems, either by supporting additional query parameters or having service operations that can help out. Ultimately, it's up to the service owner to make these decisions (for good reasons - it's up to them to determine whether opening things up further is a safe thing to do!)