0

Using JavaScript REST API, we can get a list by URL path. Thus:

http://vmdevsharepoint:12345/_api/web/lists/

Concatenating with this:

?$expand=RootFolder&$filter‌​=RootFolder/ServerRe‌​lativeUrl eq '/Lists/MyList'

That result this:

http://vmdevsharepoint:12345/_api/web/lists/?$expand=RootFolder&$filter‌​=RootFolder/ServerRe‌​lativeUrl eq '/Lists/MyList'

It works properly!

But how to get items from that list at same time? At same line of code too!

I tried to concatenate the above code with this:

&/items?$select=Title,DocType,DocNumber,Author

Resulting this (final line of code to copy and test in your environment):

http://vmdevsharepoint:12345/_api/web/lists/?$expand=RootFolder&$filter‌​=RootFolder/ServerRe‌​lativeUrl eq '/Lists/MyList'&/items?$select=Title,DocType,DocNumber,Author

But it does not worked!

Can someone help-me?

Update: For context purposes, you can see that reference: How to get List by Url using SharePoint 2013 CSOM

1 Answer 1

1

your query is extracting the lists, if you want to extract the list items you need to wo write a new query to request an specific list and then extract its items :

http://site url/_api/web/lists/GetByTitle('ListTitle')/items

more info: https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest

3
  • The list's title can be updated by the customer and I want to avoid any error in my code if it's occur! Because of that, I want to get list by Url and get their items :) How to solve this using JS REST API? Commented Dec 8, 2017 at 15:55
  • then you can use the GUID, that one never changes or also you can use the Title extracted from the previous call, this way you'll always get the current TITLE
    – Mike
    Commented Dec 8, 2017 at 16:30
  • Additionally, Rest doesn't work like CSOM where you can perform more than 1 request in 1 single call. you'll have to write an additional query for each new request you want to make, that's the reason you cannot get the items when you are requesting a list
    – Mike
    Commented Dec 8, 2017 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.