I am doing basic OData/REST calls to a SP2013 doc library. I am trying to get down to the item's URL and can't determine how to do this. I am very familiar with the server-side object model and understand that the file object is one level deeper than the item. Can someone point me in the right direction or share documentation on how to get down to the file level? I have scoured google. Here's my code that works for simply getting access to all the items in doc library and any metadata columns I wish to target:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
</html>
<script>
// workaround for access error
jQuery.support.cors = true;
// create REST query
var requestUri = "http://sp2013/_api/Web/Lists/getByTitle('Documents')/items";
// execute AJAX request
$.ajax({
url: requestUri,
type: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function(data){
alert(data.d.results);
$.each(data.d.results, function(index, item){
if (item["Meta1"] == null) {
$("body").append("<h1>No Title</h1>");
}
else {
$("body").append("<h1>" + item["Meta1"] + "</h1>");
}
});
},
error: function(jqXHR, textStatus, errorThrown){
alert(textStatus);
}
});
</script>
For the full url, try:
"http://sp2013/_api/Web/Lists/getByTitle('Documents')/items?$select=EncodedAbsUrl"
Use the $select query option with FileRef
parameter to return document Url:
https://contoso.sharepoint.com/_api/web/lists/getbytitle('Documents')/items?$select=FileRef
Use OData query operations in SharePoint REST requests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With