SharePoint API - Retrieve site contents - api

I'm trying to call a SharePoint API to get the all the items from Site contents. I have tried using requests such as https://ipagovtest.sharepoint.com/sites/IPTesting/_api/web/lists to get a list but doesn't seem to be working. I have a screenshot below of the items I'm trying to get via the uRL. Any assistance on how I can convert the URL to an api call would be appreciated. Thanks

You original question was not specific in terms of which API you're calling or how you're authenticating to it. Let's consider Microsoft's recommended approach which is using OAuth2/MSAL and the Graph API to get all lists of a given site. You would begin by retrieving a list of all the lists on a given site like this:
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var lists = await graphClient.Sites["{site-id}"].Lists.Request().GetAsync();
You can then iterate through each list the usual way like this:
foreach (var list in lists)
{
//Do something with list
}
Reference
More information about working with SharePoint lists using Graph

Related

How to retrieve a document from Sharepoint API when only the document id is known?

I'm using Sharepoint v1.0 API and want to retrieve a file by it's document id. I can't find any documentation on how to retrieve a file this way. If I use the URL:
https://xxxxxxxx.sharepoint.com/sites/xxxxxxx/_layouts/15/DocIdRedir.aspx?ID=MLVDK4UWQQ8B-763006743-3089
The response is a 401 so direct calls don't work. I can query the API but I don't know how to translate the above URL to an URL I can use with that API. The URL should be something like:
https://xxxxxxxx.sharepoint.com/sites/xxxxxxx/_api/
What is the correct way to retrieve the document using the API? I've tried:
https://xxxxxxxx.sharepoint.com/sites/xxxxxxx/_api/search/query?refinementfilters=DlcDocId:equals("MLVDK4UWQQ8B-763006743-3089")
https://xxxxxxxx.sharepoint.com/sites/xxxxxxx/_api/search/query?DlcDocId='MLVDK4UWQQ8B-763006743-3089'
https://xxxxxxxx.sharepoint.com/sites/xxxxxxx/_api/Web/GetFolderByServerRelativeUrl('Shared
Documents')/Files
https://xxxxxxxx.sharepoint.com/sites/xxxxxxx/_api/Web/GetFileByServerRelativeUrl('_layouts/15/DocIdRedir.aspx?ID=MLVDK4UWQQ8B-763006743-3089')/Versions
Try to use DocId=MLVDK4UWQQ8B-763006743-3089 in search rest api:
https://xxxxxxxx.sharepoint.com/sites/xxxxxxx/_api/search/query?querytext='DocId=MLVDK4UWQQ8B-763006743-3089'
Reference:
Search By Document ID In SharePoint 2013
I know that is not an official API endpoint you are maybe looking for but if you want to download the document with SharePoint url you may try to use the download.aspx like
https://xxxxxxx.sharepoint.com/sites/xxxxx/_layouts/15/download.aspx?UniqueId=MLVDK4UWQQ8B-763006743-3089
I hope this will be of any help

Sharepoint error: Likes are not supported in this item

I'm trying to create a Sharepoint iOS app and using the rest api I get the error "Likes are not supported in this item." after doing a POST to https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234')/like.
Anyone knows more about this kind of error?
The Rating settings seems to be set correctly on the Sharepoint server, because the like option works correctly on the website, and also in the app I can see the likesCount properties on the response for the Rest API call https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234').
I don't think there is something wrong with the client app implementation, but it is something related to the Sharepoint configuration, although I haven't seen any more settings in regards to the Rating settings including the Sharepoint access for the mobile app.
The web seems to handle this using the Microsoft.Office.Server.ReputationModel.Reputation.setLike function which again works correctly on the web parts, but I couldn't find a way to do it from the mobile app.
To set Likes for the list item, we need use the API below with POST request.
https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234')
And pass the data of the POST request as below.
var item = {
"__metadata": { "type": "SP.Data.PagesItem"},
"LikedByStringId": {"results": ["11"]},
"LikesCount": 2
};
Before set Likes for the item, we need get the "LikedByStringId" and "LikesCount" value of the list item using API below with GET request, then set the new one.
https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234')
Check the article here: Demonstrates how to like/unlike resource via SharePoint REST API

How to use Foswiki API to access form META data (cell contents) from external system

I am new to Foswiki and am wondering if it is possible to access the contents of a META form directly using an API call. A simple example of code to do this would be helpful.
Do you mean using a REST API or from within Perl?
Here is how to create custom REST API to access a formfield of some source:
(1) Create a topic, say FoswikiAPI, with content:
<verbatim class="tml">
%STARTSECTION{"getformfield"}%%FORMFIELD{
"%URLPARAM{"formfield"}%"
topic="%URLPARAM{"source"}%"
}%%ENDSECTION{"getformfield"}%
</verbatim>
(2) call it like this:
http://.../FoswikiAPI?skin=text&section=getformfield&formfield=FooBar&source=SomeWeb.SomeTopic
To read a topic and access its meta data from within perl please have a look at
https://foswiki.org/System/PerlDoc?module=Foswiki%3A%3AFunc
https://foswiki.org/System/PerlDoc?module=Foswiki%3A%3AMeta

ServiceNow - How to get the list of possible categories for incident or change via API

How to get this list by using ServiceNow API?
The easiest way to achieve that is by using REST API, here is how the call will look like:
https://yourinstance.service-now.com/api/now/table/sys_choice?sysparm_query=name=incident^element=category
If you are only interested in label the call will look like this:
https://yourinstance.service-now.com/api/now/table/sys_choice?sysparm_query=name=incident^element=category&sysparm_fields=label
You didn't clarify whether you're looking for client-side, server-side, or REST API, but here's the answer for server-side:
var gr = new GlideRecord('incident');
gr.get('e8caedcbc0a80164017df472f39eaed1');
gs.print(gr.category.getChoices());
This getChoices() API is a GlideElement API, so you call it on a field element in a server-side GlideRecord.
You can find this API documentation here.

SharePoint web service call to retrieve file information for the contents of a specific SPFolder

I have a large SharePoint document library with many levels of subfolders in it, my goal is to make one service call to list the file information (Name, size, AbsoluteUrl, etc.) of the files contained in that specific folder without enumerating through all of them.
The client application I'm writing will always have the path of the folder (ex: DocLibraryName\Folder\SubFolder1). I cannot use the SharePoint API access the data, I'm forced to use the Lists.asmx, dws.asmx, etc.. services built into MOSS 2007. My client app is in C# .Net 4.
It seems like I should be using the Lists.GetListItems method, if that is the case, what is the CAML query for just hitting a specific folder?
You can use the code like this:
XmlDocument document = new XmlDocument();
XmlElement queryOptions = document.CreateElement("QueryOptions");
queryOptions.InnerXml = #"<Folder>DocLibraryName\Folder\SubFolder1</Folder>";
and pass it as queryOptions element of Lists.GetListItems call.