I'm using Graph SDK to search files in SharePoint. Is it possible to search them only by the name?
var request = _graphServiceClient
.Drives[id]
.Root
.Search($"{searched}")
.Request();
The request above returns files that have the given phrase in content or metadata and I need to filter them by name in code. I would like to avoid this approach if possible.
You can use search api like following
POST /search/query
Content-Type: application/json
{
"requests": [
{
"entityTypes": [
"driveItem"
],
"query": {
"queryString": "contoso"
}
}
]
}
Here is the document for details
https://learn.microsoft.com/en-us/graph/search-concept-files
Related
I am trying to create a virtual machine through a post method but I have not been able to create it since I cannot send the json file correctly.
This is my code:
// Create a json object
var deploy = new Deploy
{
name = "RandomName",
folder = "folder_3044",
resource_pool = "resgroup-4035"
};
//Change it into a json file
var deployResult = JsonConvert.SerializeObject(deploy);
//Change this file into a string so we can send it to the post method
var jsonContent = new StringContent(deployResult);
//Make post and send the needed information
var postResponse = await httpClient.PostAsync("URI", jsonContent);
return (content);
When executing my code in Postman it gives me a false positive because it sends something but it seems that it does not send the json as I wanted but the code below:
{
"headers": [
{
"key": "Content-Type",
"value": [
"text/plain; charset=utf-8"
]
},
{
"key": "Content-Length",
"value": [
"97"
]
}
]
}
Can anyone help me with this? I just need to send that json in my post like I do when sending from Postman.
Ps: I use .Net core and I can't change even if I want to.
This is the json that should be sent for it to work:
{
"name": "RandomName",
"placement": {
"folder": "folder_3044",
"resource_pool": "resgroup-4035"
}
}
Thank you to #Peter Csala's comment: When I specified the content-type as you advised, it worked. Just for future references, we need these two lines of code. (Don't forget to include the assembly System.Text on top.)
using System.Text;
new StringContent(deployResult, Encoding.UTF8, "application/json");
I am trying to automate some processes in our organization and part of that includes being able to transfer a repository in one of our azure devops organizations to another (think of it as a dev organization and a test organization so we are pushing from dev to test)
Through the API https://learn.microsoft.com/en-us/rest/api/azure/devops/git/import%20requests/create?view=azure-devops-rest-6.0 I am trying to create an import request.
Here's where I'm stumped and the documentation doesn't say much about.
If I use a request body like in the example:
{
"parameters": {
"gitSource": {
"url": "https://github.com/Microsoft/vsts-agent.git"
}
}
}
The import request works fine as long as I'm importing to an empty repository. However I need to be able to sync an existing repository.
[There's a property in the documentation called overwrite that seems to be for this purpose][1]: https://i.stack.imgur.com/ezCB3.png
The only problem is when I add this to the request body and set to true
{
"parameters": {
"gitSource": {
"url": "https://github.com/Microsoft/vsts-agent.git",
"overwrite": true
}
}
}
I get bad request message saying invalid combination of parameters
If I set this to false it works if I'm trying to import to an empty repository. If the repository isn't empty I get an error saying I can only import into an empty repo.
So it seems this property is meant for exactly what I'm doing, however it seems there are more parameters needed when that property is set to true in order to make the request succeed, but the documentation is lacking in this area.
Any help would be much appreciated
I suspect that overwrite = true is giving you error because there may be some permission issues or Auth problem in your latter repo.
Alternatively, you can fork your parent repository and sync only the provided refs:
CURL:
POST https://dev.azure.com/{organization}/_apis/git/repositories?sourceRef=users/heads/master&api-version=6.0
Request Body:
{
"name": "forkRepositoryWithOnlySourceRef",
"project": {
"id": "3b046b6a-d070-4cd5-ad59-2eace5d05b90"
},
"parentRepository": {
"id": "76b510af-7910-4a96-9902-b978d6226bee"
}
}
Sample response (HTTP 201):
{
"id": "29230c30-9125-459b-a3f6-ffab329053bd",
"name": "forkRepositoryWithOnlySourceRef",
"url": "https://dev.azure.com/fabrikam/MyFirstProject/_apis/git/repositories/29230c30-9125-459b-a3f6-ffab329053bd",
"project": {
"id": "3b046b6a-d070-4cd5-ad59-2eace5d05b90",
"name": "MyFirstProject",
"url": "https://dev.azure.com/fabrikam/_apis/projects/3b046b6a-d070-4cd5-ad59-2eace5d05b90",
"state": "wellFormed",
"revision": 12,
"visibility": "private",
"defaultTeamImageUrl": null
},
"size": 0,
"remoteUrl": "https://dev.azure.com/fabrikam/MyFirstProject/_git/forkRepositoryWithOnlySourceRef",
"sshUrl": "git#ssh.dev.azure.com:v3/fabrikam/MyFirstProject/forkRepositoryWithOnlySourceRef",
"isFork": true,
"_links": {
"forkSyncOperation": {
"href": "https://dev.azure.com/fabrikam/_apis/git/repositories/29230c30-9125-459b-a3f6-ffab329053bd/forkSyncRequests/7"
}
}
}
I want to be able to print the body of a google docs in the console using c#.
I am able to print the title using this code
DocumentsResource.GetRequest request = service.Documents.Get(documentId);
Document doc = request.Execute();
Console.WriteLine(doc.Title);
but I am unable to do the same thing with the body of the text using this code
DocumentsResource.GetRequest request = service.Documents.Get(documentId);
Document doc = request.Execute();
Console.WriteLine(doc.Body);
The output is Google.Apis.Docs.v1.Data.Body.
What is the problem with the code and what should I change ?
Answer:
You need to extract the data out of the body object.
More Information:
As per the documentation on the Document Resource, the body is an object containing more than just a string of data:
{
"documentId": string,
"title": string,
"body": {
"content": [
{
"startIndex": integer,
"endIndex": integer,
"paragraph": {
object (Paragraph)
},
"sectionBreak": {
object (SectionBreak)
},
"table": {
object (Table)
},
"tableOfContents": {
object (TableOfContents)
}
}
]
},
// ...
}
The Document resource goes quite a few layers deep, so depending on what information you are trying to extract from the Body, you will have to reference this directly - something like doc.Body.Content[0].Paragraph.Elements[0].TextRun.Content - but this will highly depend on what your document contains.
You can also try viewing the whole object with by serialising the object with the JavaScriptSerializer Class as recommended by Microsoft.
References:
REST Resource: documents | Google Docs API | Google Developers
JavaScriptSerializer Class (System.Web.Script.Serialization) | Microsoft Docs
I have the following model for a REST API end point i'm writing with SwaggerUI using swashbuckle to self document:
{
"Searchs": [
{
"Text": "SearchText1",
"SearchType": "string"
},
{
"Text": "SearchText2",
"SearchType": "string"
}
]
}
In this model there are N number of SearchTypes available for the user to use:
InFoo
NotInFoo
AllExceptFoo
I need to surface this list to the user in a friendly way, but can't see a way other than adding it to the XML comments, is there a better way to surface this to the user?
I want to get number of comments and/or likes for video with specific YouTube ID.
I am using YouTube API v3.0.
I was searching through API documentation and can't find appropriate method.
After having better look at Google API documentation here, I have found that I can use "statistics" part parameter of Videos.List API in order to get what I want.
Exact HTTP post request should be (notice part=statistics parameter):
GET https://www.googleapis.com/youtube/v3/videos?part=statistics&id=sTPtBvcYkO8&key={YOUR_API_KEY}
And response is:
{
"kind": "youtube#videoListResponse",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/XN5YXMZGQaruwTWTekZu7fQthdY\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/QbzZs_aBNpzkZJxTVM7YgQeEY3g\"",
"id": "sTPtBvcYkO8",
"statistics": {
"viewCount": "3215321",
"likeCount": "17003",
"dislikeCount": "263",
"favoriteCount": "0",
"commentCount": "621"
}
}
]
}
If you want number of comments and/or likes for video with specific YouTube ID, you need to use the YouTube API V3 with youtube.videos.list
with the parameters :
part=id, statistics
id=VIDEO_ID
This is the output :
"items": [
{
"kind": "youtube#video",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/-hharrXKffaZ3z4sIleW9K-Nf2Q\"",
"id": "_RtGuUAQOC4",
"statistics": {
"viewCount": "484851",
"likeCount": "3993",
"dislikeCount": "72",
"favoriteCount": "0",
"commentCount": "262"
}
}
]
LIVE DEMO
You can find all informations about video list in the doc :https://developers.google.com/youtube/v3/docs/videos/list?hl=fr :