RussGove
RussGove

Reputation: 342

Whats the sharepoint rest endpoint to get a web by its id

I have a webid and a listid in a sharepoint page. I'm trying to construct a rest url to get to the list.

I cant figure out the url to get the web given the WebID.

I tried https://xxxx.sharepoint.com/_api/web/webs(guid'33213c5c-30e5-468c-87f7-52b48a7b6a3d') https://xxxx.sharepoint.com/_api/web/webs('33213c5c-30e5-468c-87f7-52b48a7b6a3d') https://xxxx.sharepoint.com/_api/web/webs/GetById('33213c5c-30e5-468c-87f7-52b48a7b6a3d')

How do I get at the web with that id? I need to get a list in the web. I was thinking it was going to be as simple as https://xxxx.sharepoint.com/_api/web/webs(guid'33213c5c-30e5-468c-87f7-52b48a7b6a3d')/lists(guid'the-list-id'), but I cant get at the web!

++++++++++++++++ mReply to vadim ++++++++++++++++++++++++

Thanks Vadim, You got me pointed in the right direction

This url will get me to the web: https://xxx.sharepoint.com/_api/web/webs?$filter=iD eq guid'33213c5c-30e5-468c-87f7-52b48a7b6a3d'

This url will get me all items in all lists in all webs https://xxx.sharepoint.com/_api/web/webs?$expand=lists,lists/items

This url will get me all items in all lists in a specified web: https://xxx.sharepoint.com/_api/web/webs?$expand=lists,lists/items&$filter=iD eq guid'33213c5c-30e5-468c-87f7-52b48a7b6a3d'

But how doe I get all items in a specified list in a specified web? This doesnt work: https://xxx.sharepoint.com/_api/web/webs?$expand=lists,lists/items&$filter=((iD eq guid'33213c5c-30e5-468c-87f7-52b48a7b6a3d' ) and (Lists/Id eq guid'd38444af-dd7f-404b-9e75-b1f8c6cdee7d' ))

Its a valid Web id and a valid list id, but sharepoint complains :m:message xml:lang="en-US">Field or property "Id" does not exist.

any ideas?

Upvotes: 2

Views: 6131

Answers (1)

Vadim Gremyachev
Vadim Gremyachev

Reputation: 59358

Web resource could be retrieved using $filter query option as demonstrated below:

/_api/web/webs?$filter=ID eq guid'c01e1b4a-e671-431d-97aa-4b02a57803c7'

In order to retrieve the corresponding List resource by id you could consider the following approach:

  1. Perform request to get Web Url by its Id: /_api/web/webs?$select=ServerRelativeUrl&$filter=ID eq guid'c01e1b4a-e671-431d-97aa-4b02a57803c7'
  2. Get List by id: {web url}/_api/Web/Lists(guid'b778bbec-dd69-4a6c-9437-c73972c36292')

where {web url} is web site url found in the first request

Upvotes: 3

Related Questions