MS Graph API Update PlannerTask.ConversationThreadId - c#

I want to update the "ConversationThreadId" field in a PlannerTask.
This is my code:
plannerTask = await graphClient.Planner.Tasks["XXXXXXXXX"].Request().GetAsync();
var eTagId = plannerTask.GetEtag();
plannerTask.ConversationThreadId = "YYYYYYYY";
await graphClient.Planner.Tasks[plannerTask.Id]
.Request()
.Header("Prefer", "return=representation")
.Header("If-Match", eTagId)
.UpdateAsync(plannerTask);
And it throws this error:
Message: The request is invalid: An unexpected 'StartObject' node was
found for property named 'assignedBy' when reading from the JSON
reader. A 'PrimitiveValue' node was expected.
What am I doing wrong?
Thank you

The way to get it is:
plannerTask = await graphClient.Planner.Tasks["XXXXXXXXX"].Request().GetAsync();
var eTagId = plannerTask.GetEtag();
var newTask = new PlannerTask {
ConversationThreadId = "YYYYYYYY"
};
await graphClient.Planner.Tasks[plannerTask.Id]
.Request()
.Header("Prefer", "return=representation")
.Header("If-Match", eTagId)
.UpdateAsync(newTask);
This is because it is not a PUT but a PATCH, and so we only should send the fields that have changed. I was sending the full object, and that was the problem. Now I create newTask and only specify "ConversationThreadId" in it. This way works like a charm for me.

Related

How to properly attach a bulk of small files to a task in graph api

Have the following code.
if (attachments != null)
{
if (attachments.Length > 0)
{
_newTask.Attachments = new TodoTaskAttachmentsCollectionPage();
foreach (var _attachment in attachments)
{
_newTask.Attachments.Add(new TaskFileAttachment
{
Name = _attachment.FileName,
ContentBytes = _attachment.ContentBytes,
ContentType = _attachment.ContentType
});
}
}
}
await _graphServiceClient.Users[idUser].Todo.Lists[idList].Tasks.Request().AddAsync(_newTask);
Im trying to add multiple small files to a task and then post it to the graph api.
But it results in the following error:
One or more errors occurred. (One or more errors occurred. (A type
named 'microsoft.toDo.taskFileAttachment' could not be resolved by the
model. When a model is available, each type name must resolve to a
valid type.
Basically saying that the type taskFileAttachment is not the correct type to add to the collection of attachments of a task.
But, according to MSdoc that's the correct type to add.
Cant see what i'm missing and there is not a lot of documentation of how to post small files to a task. I already done it through the api for mails and thought it was really straightforward but it looks as it is not the case.
As per the docs , there are list of property that are required when you create the todoTask , in that you can't find any property to attach the file
First try to create a new listItems , and attach the file
Sample to attach the file
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var attachmentBase = new TaskFileAttachment
{
Name = "smile",
ContentBytes = Convert.FromBase64String("a0b1c76de9f7="),
ContentType = "image/gif"
};
await graphClient.Me.Todo.Lists["{todoTaskList-id}"].Tasks["{todoTask-id}"].Attachments
.Request()
.AddAsync(attachmentBase);
So as they commented in my original post, there is no current way to attach a collection of files in one single request. They must attached to a created task one at a time.

C# OctoKit CreateFile Not found issue

I trying to commit a file to a github repo using C# and OctoKit using the following code:
static async void CommitFile()
{
var ghClient = new GitHubClient(new ProductHeaderValue("Octokit-Test"));
ghClient.Credentials = new Credentials("//...//");
// github variables
var owner = "owner";
var repo = "repo";
var branch = "main";
// create file
var createChangeSet = await ghClient.Repository.Content.CreateFile(owner,repo, "file2.txt",new CreateFileRequest("File creation", "Hello World!", branch));
}
Whenever I execute it I get:
Octokit.NotFoundException: 'Not Found'
Here are the following things I want to mention:
I generated a personal access token
The repo is private
If I put incorrect personal access token I get "Bad Credentials" error. If I
put the correct credentials I get the not found error.
var gitHubClient = new GitHubClient(new ProductHeaderValue(repoName));
gitHubClient.Credentials = new Credentials(authorizedKey);
var path = "test.txt";
var resp = await gitHubClient.Repository.Content.CreateFile(owner, repoName, path, new CreateFileRequest($"First commit ", "Hello World" , "BranchName"))
I have decided to use LibGit2Sharp. I was able to get up and running after a few mins.

Get element by key with Firebase in c#

I am coming to a problem where I have a guid style schema in my firebase database, which I want to display a text that is DisplayText, but for some reason my code is not working. I am using a FirebaseDatabase.Net Wrapper. How can I map it in order to read from the database properly using a guid way schema? thanks for the help.
Code:
private async Task ShowQuestion()
{
var firebase = new
FirebaseClient("https://PROJECT_URL.firebaseio.com/");
var dinos = await firebase
.Child("Questions")
.OrderByKey()
.StartAt("DisplayText")
.LimitToFirst(1)
.OnceAsync<GameController>();
foreach (var dino in dinos)
{
Console.WriteLine(dinos);
}
I tried doing:
string page = "https://PROJECT_URL.firebaseio.com/Questions/DisplayText.json?orderBy"DisplayText"&limitToFirst=1";
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(page))
using (HttpContent content = response.Content)
{
// Reading the string.
string result = await content.ReadAsStringAsync();
Console.WriteLine(result);
// Getting a reference to the text component.
questionDisplayText = GetComponent<Text>();
questionDisplayText.text = result.ToString();
questionDisplayText.text = result.Trim(new char[] {'"'});
}
Firebase queries take a two-step approach:
You order the child nodes on their key, their value, or the value of a property.
You then filter on values of the thing you ordered on.
Since you order by key, the filtering operations like StartAt() compare the key to the value you passed. And since there is no key DisplayText, there are no results.
If you want to read the first question, you shouldn't use a startAt().
FirebaseClient("https://PROJECT_URL.firebaseio.com/");
var dinos = await firebase
.Child("Questions")
.OrderByKey()
.LimitToFirst(1)
If you want to return the results ordered by the value of their DisplayText property, it'd be something like this:
FirebaseClient("https://PROJECT_URL.firebaseio.com/");
var dinos = await firebase
.Child("Questions")
.OrderByChild("DisplayText")
.LimitToFirst(1)
Since you indicated that you want to use the REST API, here's an example of how to do that:
https://stackoverflow.firebaseio.com/59384124.json?orderBy="DisplayText"&startAt="How"
If you want to embed this string in your code, you have a few options. The main ones:
string page = "https://PROJECT_URL.firebaseio.com/Questions/DisplayText.json?orderBy=\"DisplayText\"&startAt=\"How\"&limitToFirst=1";
Or
string page = #"https://PROJECT_URL.firebaseio.com/Questions/DisplayText.json?orderBy=""DisplayText""&startAt=""How""&limitToFirst=1";
And don't forget: in order to be able to filter on the server, you'll need to define an index in your security rules. In my case I did so with:
"59384124": { ".indexOn": "DisplayText" },
Also see:
The documentation for the Firebase REST API
This blog post on embedding quotes in C# strings

How to get group owner by CSOM

I am working with Sharepoint Online and CSOM and I need to get the owner of a
specific group.
I tried to load data from ClientContext, and got a exception with the message "unknown error".
Here is the code I tried.
MC.ClientContext context = new SPClient.ClientContext("sit url");
MC.Group group = context.Web.SiteGroups.GetById("group id");
context.Load(group, x => x.Owner);
await context.ExecuteQueryAsync();
What's the correct method to get the information that I needed?
I have solved this problem by a quite strange way.
The code is something like this:
ClientContext context = new SPClient.ClientContext("sit url");
Group group = context.Web.SiteGroups.GetById("group id");
context.Load(group, x => x.Owner.PrincipalType, x => x.Owner.LoginName);
await context.ExecuteQueryAsync();
context.Load(group.Owner);
await context.ExecuteQueryAsync();
I need to call the ExecuteQuery method twice to get the object of owner.
I don't know why. But it works.
You can use GroupCollection.GetByName or GetById to retrieve an existing group and then retrieve the groupowner.
using (var context = new ClientContext("sit url"))
{
context.Credentials = credentials;
var groupOwner = context.Web.SiteGroups.GetByName("GroupName");
ctx.ExecuteQuery();
}

How does one connect to the RootDSE and/or retrieve highestCommittedUSN with System.DirectoryServices.Protocols?

Using System.DirectoryServices, one can get the highestCommittedUSN this way:
using(DirectoryEntry entry = new DirectoryEntry("LDAP://servername:636/RootDSE"))
{
var usn = entry.Properties["highestCommittedUSN"].Value;
}
However, I need to get this information from a remote ADLDS using System.DirectoryServices.Protocols, which does not leverage ADSI. Following is a simplified code sample of what I'm attempting to do:
using(LdapConnection connection = GetWin32LdapConnection())
{
var filter = "(&(highestCommittedUSN=*))";
var searchRequest = new SearchRequest("RootDSE", filter, SearchScope.Subtree, "highestCommittedUSN");
var response = connection.SendRequest(searchRequest) as SearchResponse;
var usn = response.Entries[0].Attributes["highestCommittedUSN"][0];
}
Unfortunately this kicks back a "DirectoryOperationException: The distinguished name contains invalid syntax." At first I thought there might be something wrong in GetWin32LdapConnection() but that code is called in numerous other places to connect to the directory and never errors out.
Any ideas?
Thanks for the idea, Zilog. Apparently to connect to the RootDSE, you have to specify null for the root container. I also switched the filter to objectClass=* and the search scope to "base." Now it works!
using(LdapConnection connection = GetWin32LdapConnection())
{
var filter = "(&(objectClass=*))";
var searchRequest = new SearchRequest(null, filter, SearchScope.Base, "highestCommittedUSN");
var response = connection.SendRequest(searchRequest) as SearchResponse;
var usn = response.Entries[0].Attributes["highestcommittedusn"][0];
}
I hope this saves someone else some time in the future.

Categories