I'm struggling at the moment to figure out how to use the JS API to return the URL for a given asset ID (the API equivalent of %globals_asset_url:[assetid]%). I know about getUrlFromLineage, but is there an easier way?
Using JS API to get the URL of an asset
There isn't an easier way to get an accurate url, the main reason is that an asset can have multiple urls so it needs to know which lineage you want the url for. If you just want to let Matrix decide which url to give you then you can use a simple getGeneral call:
<br />
var api = new Squiz_Matrix_API({<br />
key: '123456789'<br />
});<br />
api.getGeneral({<br />
asset_id: 89, // Example asset id<br />
dataCallback: function(data){<br />
if (data.error) {<br />
throw data.error;<br />
} else if (data.hasOwnProperty('web_path')) {<br />
console.log(data.web_path);<br />
}<br />
}<br />
});<br />
The 'web_path' property of the getGeneral results actually returns a full url that Matrix has guessed for you.
Ah, must have missed that property in getGeneral, thanks!
A big improvement would be to have a getUrl function which returns all of the URLs for a given asset - worth suggesting in roadmap?