Reputation: 724
I need to link to a given site's Documents Library, I know I simply need to append the /Shared%20Documents/Forms/AllItems.aspx
to the site URL, however how can I get that site URL with just its title?
I've tried using _api/Web/Lists/getByTitle('<Page Title>')/
but I get an error saying that the list does not exist in the site even though I can veryify in the site configuration that is indeed the title.
Upvotes: 0
Views: 294
Reputation: 121
I wasn't completely sure what you were trying to do based on your question; but after reading the answer you provided, you need use the OData $filter query option:
function setDepartmentLink(department){
$.ajax({
url: "_api/web/webs?$select=Url&$filter=Title eq '" + department + "'",
type: "GET",
headers: { "accept": "application/json;odata=verbose" },
success: function (data) {
if(data.d.results.length > 0){
$("#SPDDeptFolderLink").text(department).prop("href", encodeURI(data.d.results[0].Url + "/Shared Files/Forms/AllItems.aspx"));
}
}
});
}
Upvotes: 1
Reputation: 724
Managed to do it with the following method:
function setDepartmentLink(department){
$.ajax({
url: "_api/web/webs",
type: "GET",
headers: { "accept": "application/json;odata=verbose" },
success: function (data) {
data.d.results.forEach(function (site) {
if(site.Title === department){
$("#SPDDeptFolderLink").text(department).prop("href", encodeURI(site.Url + "/Shared Files/Forms/AllItems.aspx"));
}
})
}
}
Since I wasn't able to find a method that returned a site's URL given its title I decided to iterate over all the sites and simply look for the title.
Upvotes: 0
Reputation: 187
Try with the correct name of the list
/_api/Web/Lists/GetByTitle('listname')/Items
The above api will result the all items in a list.
OR try with GUID of the list
/_api/Web/Lists(guid'guid id of your list')
If you are looking for list guid,
1.Go to the list in the site
2.Click the LIST or LIBRARY tab and click LIST/LIBRARY Settings
3.Look in the browser’s address bar and you will see something like this:
http://yourserver/sites/training/_layouts/listedit.aspx?List=%7B81588B61%2D860D%2D4487%2DB81F%2DA1846A37954B%7D
4.Copy everything after the “List=” and paste into Notepad
You should now have something like this in Notepad:
%7B81588B61%2D860D%2D4487%2DB81F%2DA1846A37954B%7D
5.The GUID you copied is encoded. You now need to clean this up
1.Delete the “%7B” at the beginning
2.Delete the “%7D” at the end
3.Do a search and replace and change “%2D” to “-“ (a dash)
Upvotes: 0