Microsoft Teams Graph API - Invalid bind property name owners in request - microsoft-graph-api

I'm currently having major issues with creating teams from the Graph API. I was initially trying to create teams based on groups, however I have found out today that you can now create a team without creating a group first then waiting 15 minutes to then create the team from the following link. This would make things considerably simpler.
https://learn.microsoft.com/en-us/graph/api/team-post?view=graph-rest-1.0
I am using the Microsoft.Graph SDK (v3.12.0 released 26th Aug) so replicated the http call using the SDK as follows.
var team = new Team
{
DisplayName = "My Group Name",
Description = "My Group Description",
AdditionalData = new Dictionary<string, object>()
{
{"template#odata.bind", "https://graph.microsoft.com/v1.0/teamsTemplates('educationClass')"},
{"owners#odata.bind", $"[\"https://graph.microsoft.com/v1.0/users('{usersGuid}')\"]"}
},
};
var response = await _graphClient.Teams
.Request()
.AddAsync(team);
The code above gives a:
[16:14:01 ERR] An unhandled exception has occurred while executing the request.
Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: BadRequest
Message: Invalid bind property name owners in request.
If I remove the line
{"owners#odata.bind", $"[\"https://graph.microsoft.com/v1.0/users('{usersGuid}')\"]"}
from the code I get the following:
ErrorMessage : {"errors":[{"message":"A team owner must be provided when creating a team in application context."}]
Any advice would be greatly appreciated.
Thanks,
Nick

In v1.0 the owners relationship is not currently present, so you have to use the beta endpoint.
POST: https://graph.microsoft.com/beta/teams
with the following body format
{ "template#odata.bind":"https://graph.microsoft.com/beta/teamsTemplates('standard')", "displayName":"Test Team", "description":"Test description", "owners#odata.bind":["https://graph.microsoft.com/v1.0/users/{user guid}"] }
Note: the user guid should also be bare, i.e without the brackets and quotes in your example.

Related

Create team from group fails with exception

I created teams in Microsoft Teams (from groups as documented here) via the C# graph-api sdk without any problems - everything was working just fine.
But suddenly this is not working anymore. I will always get the following exception at the line return await graphServiceClient.Teams.Request().AddAsync(team);:
Message: Failed to execute Templates backend request
CreateTeamFromGroupWithTemplateRequest. Request Url:
https://teams.microsoft.com/fabric/emea/templates/api/groups/theGroupId/team,
Request Method: PUT,
And further:
Team Visibility can not be specified as it is inherited from the
group.
I know that the visibility property must not be set if creating the team from a group as it states in the Microsoft documentation:
The team that's created will always inherit from the group's display name, visibility, specialization, and members. Therefore, when making this call with the group#odata.bind property, the inclusion of team displayName, visibility, specialization, or members#odata.bind properties will return an error.
But the currently used code below shows that I am not setting any forbidden properties - and this code worked for the last few days, too:
private async Task<Team> CreateTeamFromGroup(string groupId)
{
var graphServiceClient = [...]
var groupResourceLink = $"https://graph.microsoft.com/v1.0/groups('{groupId}')";
var team = new Team
{
AdditionalData = new Dictionary<string, object>()
{
{ "template#odata.bind", "https://graph.microsoft.com/beta/teamsTemplates('standard')" },
{ "group#odata.bind", groupResourceLink }
},
Channels = new TeamChannelsCollectionPage
{
new Channel
{
DisplayName = "WhatEver"
}
}
};
return await graphServiceClient.Teams.Request().AddAsync(team);
}
Is anyone else experiencing this problem? Was there an API change? Was the teams backend changed? Anyone any ideas?
P.S.: I am using the latest NuGet-Package for Microsoft Graph - downgrading didn't help.
Update (with a not very satisfying work-around)
The error can be reproduced via the graph api explorer, too.
The POST command above issues a PUT command, that is described here. With this request, the team can be created.
The documentation and the graph api snippet for C# is out-dated, though. You have to add odatatype = null to the properties when using the sdk
Unfortunately it is not possible to add channels in the same step. If you specify the property 'channels' it will just be ignored.
Update (Detailed error message)
System.AggregateException: 'One or more errors occurred. (Code:
BadRequest Message: Failed to execute Templates backend request
CreateTeamFromGroupWithTemplateRequest. Request Url:
https://teams.microsoft.com/fabric/emea/templates/api/groups/theGroupId/team,
Request Method: PUT, Response Status Code: BadRequest,
ErrorMessage : {"errors":[{"message":"Team Visibility can not be
specified as it is inherited from the
group."}],"operationId":"639448e414ece64caee8f52839585bf7"} Inner
error: AdditionalData: date: 2020-11-24T10:21:22 request-id:
37a28cac-3ac5-4bd2-a061-daf44c442fac client-request-id:
37a28cac-3ac5-4bd2-a061-daf44c442fac ClientRequestId:
37a28cac-3ac5-4bd2-a061-daf44c442fac )'
Just tested this morning and I can say, that the "old way" by using the beta API to create a team with a template works again. Don't know, how many other ways exist to do these things, but here is our current request, that works now (again).
POST https://graph.microsoft.com/beta/teams
{
"displayName": "My Group Name",
"description": "Some description",
"template#odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('educationClass')",
"owners#odata.bind": [
"https://graph.microsoft.com/beta/users('<someValidUserId>')"
]
}
I think this will be just an intermediate state and when the bugs are fixed, they will publish the new version again and this kind of creation will fail again, but if in this case the v1.0 documented way will work this wouldn't be a big problem. But being informed BEFORE there roll-out starts would be great.
This was a Microsoft issue/ bug and is currently being fixed as stated here.

Sending a chat message to a microsoft Teams channel using Microsoft Graph API C#

My goal is simple.
I want to send an automated chat message in to a MS Teams channel using the graph API.
This seems to be beta feature of the graph API and is only avalible in the Microsoft.Graph.Beta.
I have read the docs and have been trying to follow this example:
https://learn.microsoft.com/en-us/graph/api/channel-post-messages, I have all the permissions set correct in my azure portal. I keep getting 'Unknown Error' I have tried:
var graphServiceClient = MicrosoftGraphService.GetGraphServiceClient();
var chatMessage = new ChatMessage
{
Subject = null,
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = messageText
}
};
var response = await graphServiceClient.Teams["77f9c17f-54ca-4275-82d4-fff7esdacda1"].Channels["2007765c-8185-4cc7-8064-fb1b10f27e6b"].Messages.Request()
.AddAsync(chatMessage);
I have also tried to to see if I can get anything from teams:
var teams = await graphServiceClient.Teams["77f9c17f-54ca-4275-2sed4-ffsde59acda1"].Request().GetAsync();
Again all I get is Unknown error, I have used GRAPH API before to do things like get users in an organisation, so I know the genreal set up is correct.
Has anyone on the Internet somewhere in the world got this to work?! becuase its driving me crazy
Same problem here :
Everything is ok with users or groups, but I can't get anything from Teams (unknownError)
All IDs are correct and checked
Here are the authorizations I have set for the app :
Read all users' teamwork activity feed
Read all groups
Send a teamwork activity to any user
Get a list of all teams
Here is my code (based on microsoft daemon app scenario)
The access token is ok
var graphClient = new GraphServiceClient(
"https://graph.microsoft.com/beta",
new DelegateAuthenticationProvider(async (requestMessage) =>
{
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", result.AccessToken);
}));
var chatMessage = new ChatMessage
{
Subject = "Message de test",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Contenu de test"
}
};
await graphClient.Teams["218a4b1d-84d5-48a2-97a0-023e4e4c3e85"].Channels["19:adbf8ddf37a049aa9f63a0f8ee0e8054#thread.tacv2"].Messages
.Request()
.AddAsync(chatMessage);
And the result :
Token acquired
Code: UnknownError
Inner error:
AdditionalData:
request-id: e2e433d8-cedd-4401-b5b2-6f34cf5611cf
date: 2020-03-30T12:14:15
ClientRequestId: e2e433d8-cedd-4401-b5b2-6f34cf5611cf
Edit(2020-04-01) :
No solution at the time being : there are answers to comments at the bottom of the page "Create chatMessage in a channel" in ms doc (feedback section)
It seems that applications cannot be granted the permission to send chatMessages up to now.
RamjotSingh commented on Jun 11, 2019 Contributor
#pythonpsycho1337 - As the permission table above notes, Application
only context is not supported on this API at the moment.
RamjotSingh commented on Dec 16, 2019 Contributor
Supporting application permissions is something we plan to do but we do not have a date yet.
RamjotSingh commented a day ago Contributor
We will share on Microsoft Graph Blog once we have application
permissions for this API. Since the original question for this issue
was answered. Closing it.

Devops server 2019 - Is there an REST api to add members to project and team

I was looking to add members to Project using REST API.
I was able to create project using API:
POST https://{instance}/{collection}/_apis/projects?api-version=5.0
Also, I was able to create a team in a project using REST API:
POST https://{instance}/{collection}/_apis/projects/{projectId}/teams?api-version=5.0
However, I was not able to get a REST API to add members to team and project.
Can you please help?
Devops server 2019 - Is there an REST api to add members to project
and team
For this issue,I think there is no out of box rest api to achieve it . The Members - Add rest api is currently not available for Azure DevOps Server 2019.
As a workaround ,we can track this rest api by press F12 in browser then select Network.
Sample request url :
https://collectionName/DefaultCollection/projectId/_api/_identity/AddIdentities?__v=5
Sample request body:
{
"newUsersJson": "[]",
"existingUsersJson": "[\"55b98726-c6f5-48d2-976b-xxxxxx\"]",
"groupsToJoinJson": "[\"7283653f-54b2-4ebf-86c3-xxxxxxx\"]",
"aadGroupsJson": "[]"
}
In this step ,you need to convert the name of the member you want to add and the name of the team to json, then add to the request body. Here is a case states how to convert a string to JSON in C#.
From this record ,we can get the request url and request body.
I test this with postman and can successfully add a member to a project team.
Here are two cases(case1 , case2) with similar problems. You can also refer to them.
The use voice instance in the above case is no longer available. You could submit a new one to our main forum for product suggestions. Our PM and Product Group are reviewing these suggestion regularly and considering take it as plan.
The REST API to add members to projects and team is not documented. As Hugh mentioned we can track the REST API with develop tools (press F12 in browser), however as we can see we can only use the user and team/group GUID in the request json body.
Post https://wsicads2019/DefaultCollection/{project}/_api/_identity/AddIdentities?api-version=5.0
Request Body:
{
"newUsersJson": "[]",
"existingUsersJson": "[\"55b98726-c6f5-48d2-976b-xxxxxx\"]",
"groupsToJoinJson": "[\"7283653f-54b2-4ebf-86c3-xxxxxxx\"]",
"aadGroupsJson": "[]"
}
For the specific team/groups we can use the REST APIs Projects and teams to get their GUID.
For the user, actually it's used the TeamFoundationId, the unique TeamFoundationId is automatically generated when a user is added to Azure DevOps Server. We cannot generate the ID with external tools.
So, to use that REST API, we need to get the TeamFoundationId of the specific user which you want to add it to the projects/teams.
Currently, no REST API to list TeamFoundationId of the users in Azure DevOps Server 2019, however we can get it with Client API:
Below sample for your reference to get the TeamFoundationId of a specific user: (It will also export the user list with their TeamFoundationId to userlist.txt)
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using System.Linq;
using System.IO;
namespace Getuserlist
{
class Program
{
static void Main(string[] args)
{
TfsConfigurationServer tcs = new TfsConfigurationServer(new Uri("https://wsicads2019"));
IIdentityManagementService ims = tcs.GetService<IIdentityManagementService>();
TeamFoundationIdentity tfi = ims.ReadIdentity(IdentitySearchFactor.AccountName, "[DefaultCollection]\\Project Collection Valid Users", MembershipQuery.Expanded, ReadIdentityOptions.None);
TeamFoundationIdentity[] ids = ims.ReadIdentities(tfi.Members, MembershipQuery.None, ReadIdentityOptions.None);
using (StreamWriter file = new StreamWriter("userlist.txt"))
foreach (TeamFoundationIdentity id in ids)
{
if (id.Descriptor.IdentityType == "System.Security.Principal.WindowsIdentity" && id.UniqueName == "Domain\\User")
{ Console.WriteLine("[{0},{1}]", id.UniqueName, id.TeamFoundationId); }
file.WriteLine("[{0},{1}]", id.UniqueName, id.TeamFoundationId);
}
var count = ids.Count(x => ids.Contains(x));
Console.WriteLine(count);
Console.ReadLine();
}
}
}

Getting #Mention to work with a TFS Extension on TFS 2017.3

I am trying to programmatically add the mention of users that are members of groups in TFS in the discussion area of work items. We were using the 1.0 version with TFS 2017 update 2 with success:
#{id.DisplayName}
However upgrading to TFS 2017 update 3 fails to send emails on the notifications. We also tried all of the "user ids" we could find on the TeamFoundationIdentitiy object for the solutions found here:
VSTS - uploading via an excel macro and getting #mentions to work
So how can we get emails for #mentions to work again in TFS 2017.3?
Update: 9/11/2018
Verified service account fails to send emails while my account running the same code will send emails for mentions:
using (var connection = new VssConnection(collectionUri, cred))
using (var client = connection.GetClient<WorkItemTrackingHttpClient>())
{
var wi = new JsonPatchDocument
{
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.History",
Value = $"#{id.DisplayName} <br/>"
}
};
using (var response = client.UpdateWorkItemAsync(wi, workItemId, suppressNotifications: false))
{
response.Wait();
}
}
We solved by dropping use of the WorkItemHttpClient and going back to loading the SOAP WorkItemStore as the user that submitted the changes instead of the service account. It would be nice if we could use impersonation of a user with TFS's WebApi

Create managedDevice in Intune using Graph API

I am trying to create a managed device in Intune using the following Microsoft Graph but it keeps erroring out.
I also get an error when trying to update an existing device record.
I have the appropriate scopes and my account is an Intune admin. Any suggestions?
Here is the example error I receive when trying to update using PATCH
"error": {
"code": "InternalError",
"message": "An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: 7d3aea54-282a-4911-99a5-af3d2422f81a - Url: https://fef.amsua0502.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/managedDevices%28%278f312966-1c51-403b-9b3a-6cf52643fa70%27%29?api-version=5017-09-07 - CustomApiErrorPhrase: ",
"innerError": {
"request-id": "7d3aea54-282a-4911-99a5-af3d2422f81a",
"date": "2017-11-02T12:16:55"
}
}
They have changed the endpoint without updating the documentation..
Use: /deviceManagement/managedDevices
It's a beta so endpoints and (more frequently) required parameters in the json object chances..
I've figured out a lot of these changes by simply looking at posts from the developer mode in a browser.
The documentation is often behind the actual implementation.
And yea this worked. sorry for late response..
Edit2:
I don't have an example to create a managed device. But this is an example on how to create an empty device configuration:
$Endpoint = "https://graph.microsoft.com/beta"
## Win10
$Win10 = [pscustomobject]#{
'#odata.type' = "#microsoft.graph.windows10GeneralConfiguration"
'description' = "standard Windows 10 Device Restriction Configuration"
'displayName' = "Win10"
}
$Win10params = #{
ContentType = 'application/json'
Headers = $Header
Body = $Win10 | ConvertTo-Json -Compress
Method = 'POST'
URI = "$Endpoint/deviceManagement/deviceConfigurations"
}
Invoke-RestMethod #Win10params
But again. Take a look at the POST in the developer tab, and then start by trying out parameters from the top. If the documentation isn't updated with the least required parameters, you will have to go through it step by step..
They have changed the endpoint without updating the documentation..
Use: /deviceManagement/managedDevices

Resources