How to search sharepoint file across document library - sharepoint

I'm trying to search files in SharePoint with GET https://graph.microsoft.com/v1.0/sites/root/drive/root/search(q='text file') but it searches only in the root site. Is there any way to search across the document library using graph API?
Something similar to POST https://graph.microsoft.com/v1.0/search/query. This endpoint searches files across the document library.
Is it possible to implement the POST api call behavior in the GET api call? Why because the response from POST api call doesn't provide information about file-mimeType, so I need to switch to GET api call.

You can specify the fields you want back in the response, as part of the fields sub-property. Specify mimeType.
To retrieve a custom property for a driveItem, query listItem instead.
POST https://graph.microsoft.com/v1.0/search/query
Request body
{
"requests": [
{
"entityTypes": [
"listItem"
],
"query": {
"queryString": "text file"
// filter by contentClass
//"queryString": "text file contentclass:STS_ListItem_DocumentLibrary"
},
"fields": [
"id",
"fileName",
"contentClass",
"createdDateTime",
"lastModifiedDateTime",
"webUrl",
"sharepointIds",
"createdBy",
"modifiedBy",
"parentReference",
"mimeType",
"fileType"
]
}
]
}
Specify select properties

Related

How to get data from multiple SharePoint groups with one query in Graph Explorer?

Basically I need to get Information from Multiple Groups in one Query.
https://graph.microsoft.com/v1.0/groups/{I Need Multiple ID-s Here}/conversations
The Microsoft Graph explorer only lets me get conversations from one group with one query. In my case, I have 6, and I want to get the last conversations at the same time. If I delete the ID I get an Error that the Query needs an Object Identifier. Is there a Multi-Object-Identifier? Can this even be done with the Graph explorer? If not, is there another way? Thanks!
You can try batching:
https://learn.microsoft.com/en-us/graph/json-batching
POST https://graph.microsoft.com/v1.0/$batch
body:
{
"requests": [
{
"id": "1",
"method": "GET",
"url": "/groups/{first-group-id}/conversations"
},
{
"id": "2",
"method": "GET",
"url": "/groups/{second-group-id}/conversations"
}
]
}
pnpjs has a built-in support for batching (a bit more convenient), if you use it.

Azure DevOps API TFS: How to get a file history if it was renamed and/or branched?

Is this possible somehow to get a file history (all related changesets) with API request if the file was branched or/and renamed?
For example, if I need to find a history of the object in Azure DevOps UI I can search this object in the project, in a certain path like this:
And if I need to find the first appearance of the object in a repository, I can get it by expanding a "branch and rename" history
There is a need to get this information via API requests.
I had tried to find some API requests which can do it, but found only the requests which can return only the changesets which are on the first picture, where the object has the same name and is located under the path defined in the search parameter - there is no information about renaming/branching operations.
GET https://dev.azure.com/Contoso/_apis/tfvc/changesets?api-version=6.0&searchCriteria.itemPath=$/Contoso/Trunk/Main/Metadata/Application_Ext_Contoso/Application_Ext_Contoso/AxSecurityPrivilege/Entity.xml
returns only 3 changesets - 2162, 2161, 391
POST https://dev.azure.com/Contoso/Contoso/_api/_versioncontrol/history?api-version=6.0
With the body request
{
"repositoryId":"",
"searchCriteria":"{\"itemPaths\":[\"$/Contoso/Trunk/Main/Metadata/Application_Ext_Contoso/Application_Ext_Contoso/AxSecurityPrivilege/Entity.xml\" ], \"followRenames\" : true ,\"top\":50}",
"includeSourceRename" : true
}
Also returns only 3 changesets, it only finds a specific item path, I tried to experiment with includeSourceRename and followRenames , but they do not work as I expected.
POST https://almsearch.dev.azure.com/Contoso/Contoso/_apis/search/codesearchresults?api-version=6.0-preview.1
with the body
{
"searchText": "Entity.xml",
"$skip": 0,
"$top": 25,
"filters": {
"Project": [
"Contoso"
],
"Repository": [
"$/Contoso"
],
"Path": [
"$/Contoso/"
]
},
"$orderBy": [
{
"field": "filename",
"sortOrder": "ASC"
}
],
"includeFacets": true
}
Also returns information only about 3 changesets.
Are there some approaches to get this information from the API request?

Get all entries with included images using Contentful REST API

I am using typescript,and the Contentful-ManagementAPI (that's the reason I'm not using the SDK client), and I want to retrieve all entries from a specific type. I am calling th Api like this:
axios.get("https://api.contentful.com/spaces/" +
space_id +
"/entries?content_type=" +
content_type+"&include="+2)
I am receiving all the entries requested, but in the image field I am getting this:
poster:en-US:
sys:
{type: "Link", linkType: "Asset", id: "222xxm9aaAu4GiAc2ESw0Q"}
So, How could I get the image URL?
I would appreciate any help. Thanks
From the Contentful docs:
The CMA does not support the include and locale parameters.
So, I might be better using the delivery api for retrieve content, and the management api for create/update/delete. That's the way it should be used.
The referenced assets and entries can be found in the includes object in the API response.
The response should look something like this:
{
"sys": {
"type": "Array"
},
"total": 9,
"skip": 0,
"limit": 100,
"items": [ // Your items here ],
"includes": {
"Asset": [ // Your included assets here, this is where you find the url to the image ]
"Entry": [ // Any referenced entries not included in the items array above ]
}
So to find the actual asset that includes all your data (including the url) you would have to find the correct asset, using the id of the reference (222xxm9aaAu4GiAc2ESw0Q), in the includes.Asset object.
Try include=10, If you are using multi locales provide fallback for each locale.
This worked for me.

node.js swagger x-ms-dynamic-value

I'm using swagger with node.js. I want to use x-ms-dynamic-values to return values to my parameter dynamically.
Basically the first parameter will have a URL then the node.js endpoint will make a get request to that URL and pull back lets say questions, Each URL can have a different amount of questions and the questions can also vary. The get request can get a json response with amount of questions on the page. In my next parameter I want to be able to select a question based on that response.
This is where the x-ms-dynamic-values will come in to play, But I'm nearly 100% sure there are no examples of this being used with node.js only thing I could find was c# example which i will link under this.
So basically my questions is, can anyone provide my with a little example of the node.js I may be able to work from ?
example of the swagger code :
"paths":{
"/api/contacts/{name}":{
"get":{
"tags":[
"DynamicSchemas"
],
"summary":"Get Contact Info",
"description":"Gets contact info of the specified type",
"operationId":"GetContactInfo",
"consumes":[
],
"produces":[
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters":[
{
"name":"name",
"in":"path",
"required":true,
"type":"string",
"x-ms-summary":"Contact Name"
},
{
"name":"contactType",
"in":"query",
"description":"Try either \"Phone\" or \"Email\"",
"required":true,
"type":"string",
"x-ms-summary":"Contact Type"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/ContactInfo"
}
},
"400":{
"description":"Invalid type specified"
},
"default":{
"description":"OK",
"schema":{
"$ref":"#/definitions/ContactInfo"
}
}
}
Api Example: https://github.com/nihaue/TRex/tree/master/Source

Outlook Mail REST API: send message with attachment

I'm trying to use next API method: https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#SendMessages. Sending messages without attachments works just fine, but I can not understand how to send message with attachments.
According to docs, Message structure can contain array of Attachments with items of type https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#RESTAPIResourcesFileAttachment . Problem is in the field ContentBytes -- it is impossible to dump bytes to JSON before sending request to this API method (actually dumping any BLOB to JSON is nonsense).
How should I pass Attachments using REST API at all?
Thanks.
There's an example of passing the attachment on that page: https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#SendMessageOnTheFly
I know I'm 3 years late but, you can look at this example:
https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#create-and-send-messages (if you don't get forwarded to the section "Create and send messages", please scroll manually).
I know it is 365 and not Microsoft Graph but request is absolutely same.
This is basically how JSON representation of the post method looks:
https://outlook.office.com/api/v2.0/me/sendmail
{
"Message":
{
"Subject": "Meet for lunch?",
"Body": {
"ContentType": "Text",
"Content": "The new cafeteria is open."
},
"ToRecipients": [
{
"EmailAddress": {
"Address": "garthf#a830edad9050849NDA1.onmicrosoft.com"
}
}
],
"Attachments": [
{
"#odata.type": "#Microsoft.OutlookServices.FileAttachment",
"Name": "menu.txt",
"ContentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}
]
}
}

Resources