I'm trying to use the following Graph API endpoint in C#
https://graph.microsoft.com/v1.0/drive/items/{driveItem-id}/versions/{driveItemVersion-id}/content
I can execute this API with GET method, but PUT method is returning an error.
GET:
await _graphServiceClient
.Sites[siteId]
.Drives[driveId]
.Items[itemId]
.Versions["1.0"]
.Content
.Request()
.GetAsync();
PUT:
await _graphServiceClient
.Sites[siteId]
.Drives[driveId]
.Items[itemId]
.Versions["1.0"]
.Content
.Request()
.PutAsync<DriveItemVersion>(file);
Exception:
Microsoft.Graph.ServiceException: 'Code: itemNotFound Message: Item
not found
I assume that you want to update the content. In that case you need to call the following endpoint
PUT /sites/{site-id}/drives/{drive-id}/items/{item-id}/content
C# code
await _graphServiceClient
.Sites[siteId]
.Drives[driveId]
.Items[itemId]
.Content
.Request()
.PutAsync<DriveItem>(fileStream);
It will create a new version. You can check the list of all versions
var versions = await _graphServiceClient
.Sites[siteId]
.Drives[driveId]
.Items[itemId]
.Versions
.Request()
.GetAsync();
Related
I have this code for testing my form
import { expect, test } from '#playwright/test'
test('Form test', async ({ page }) => {
await expect(page.locator('#feedback_form'))
await page.locator('input#name[type="text"]').fill('John Doe')
await page.locator('input#email[type="email"]').fill('troum#outlook.com')
await page.locator('input#phone[type="text"]').fill('+47 89 89678 90')
await page.locator('input#subject[type="text"]').fill('Test subject')
await page.locator('input#purpose[type="text"]').fill('Test purpose')
await page.locator('input#contactWay[type="text"]').fill('Via e-mail')
await page
.locator('textarea#message')
.fill('Contrary to popular belief, Lorem Ipsum is not simply random text')
await page.click('button[type="submit"]', { force: true })
await page.screenshot({ path: 'scrapingant.png' })
})
but I've got this problems for each browsers
it's my screenshort
Complete the assertion first:
await expect(page.locator('#feedback_form')).toBeVisible()
Then You can modify your selector a bit like this and try:
await page.locator('input#name').fill('John Doe')
Or, you can do a click before fill and try:
await page.locator('input#name').click().fill('John Doe')
try to use different selectors if its still not working,go for playwright Codegen's generated locator using command npx playwright codegen as i was facing the same issue and it worked for me even though i was using unique locator.
Tried this:
graphServiceClient
.sites(siteId)
.pages(pageId)
.buildRequest()
.get() but seems earlier pages method was supported and now it's not appearing.
Is there any way to get site page collection?
thanks for reaching out ,I understood that you are trying to get list of sites, looks like you are using async await ,please convert your get() function to GetAync() and add await.
Could you please try by using the below sample code
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var items = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items .Request()
.GetAsync();
ref docs - https://learn.microsoft.com/en-us/graph/api/listitem-list?view=graph-rest-1.0&tabs=csharp#request
Hope this helps , please let us know if you have any query
thanks
In my C# application I am trying to search for a User via Graph API. The only parameter I have is the username which is stored in onPremisesSamAccountName field.
Through Graph Explorer I can successfully run the query
https://graph.microsoft.com/v1.0/users?$count=true&$search="onPremisesSamAccountName:myusername"&$select=id,displayName
And Graph Explorer gives me the C# code to use
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var users = await graphClient.Users
.Request()
.Search("onPremisesSamAccountName:myusername")
.Select("id,displayName")
.GetAsync();
Now when I try to use that code I get an error saying that Search is not a method, do I need to add an extra package to use Search?
I also didn't find any nuget package with Search method.
You can specify search value by using query option. $search query parameter requires a request header ConsistencyLevel: eventual
var queryOptions = new List<Option>()
{
new QueryOption("$search", "\"onPremisesSamAccountName:myusername\""),
new HeaderOption("ConsistencyLevel", "eventual")
};
var users = await graphClient.Users
.Request(queryOptions)
.Select("id,displayName")
.GetAsync();
Contrary to the documentation on https://learn.microsoft.com/en-us/graph/api/profilephoto-update?view=graph-rest-1.0&tabs=http there is no .Content object available under .Photo.
group.Photo.Content.Request().PutAsync(photoStream).Result;
I am looking to update the profile photo for the group and it does not seam to be available.
Below code is working for me. Can you please try similar way.
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var stream = await graphClient.Groups["groupId"].Photo.Content
.Request()
.GetAsync();
I have installed Microsoft.Graph Nuget version 3.4.0.
Your c# example for https://graph.microsoft.com/v1.0/me/people?$search="jesper"
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var people = await graphClient.Me.People
.Request()
.Search("jesper")
.GetAsync();
Error I'm getting:
not sure if this is meant to happen but seems wrong that you cant use the search function
https://developer.microsoft.com/en-us/graph/graph-explorer
Yes, you're absolutely right. Those snippets are generated by a tool, and sometimes it gets it wrong. Thanks for reporting!
You can add any query parameters to requests sent by the SDK though, so you can still make this work like so:
var options = new List<QueryOption> { new QueryOption("$search", "j") };
var people = await graphClient.Me.People.Request(options).GetAsync();