I am trying to create Channel of Team with email address (for example, General - Test Team 72 <527ce911.YYY.XX#emea.teams.ms>). I can create Channel but without email address.
I have tried following using Graph API (Powershell):
1. Graph API v1.0 and beta
2. Create Team (public, private with email) with default (General) Channel
3. Create additional Channels for existing Team
4. Create O365 group and from group create Team
5. Add members and owners to Team
6. Update/change settings of Team and channel
7. Create Channel's folder in the document library of SharePoint site linked to Team
function create-team($TeamName, $Visibility, $UserId){
$ApiUrl = "https://graph.microsoft.com/beta/teams"
$Method = "Post"
$MailNickname = $TeamName -replace '\s',''
$Body = #{
"template#odata.bind" = "https://graph.microsoft.com/beta/teamsTemplates('standard')";
"displayName" = "$TeamName";
"description" = "$TeamName";
"owners#odata.bind" = #("https://graph.microsoft.com/beta/users('$UserId')");
"Visibility" = "$Visibility";
"mailNickname" = "$MailNickname"
}
$BodyJSON = ConvertTo-Json $Body
$ContentType = "application/json"
#$AccessToken is not shown here
return Invoke-RestMethod -Headers #{Authorization = "Bearer $AccessToken"} -Uri $ApiUrl -Method $Method -Body $BodyJSON -ContentType $ContentType
}
function create-channel($TeamId, $DisplayName, $Description){
$ApiUrl = "https://graph.microsoft.com/beta/teams/$TeamId/channels"
$Method = "Post"
$Body = #{
"displayName" = "$DisplayName";
"description" = "$Description";
#"channelState" = "Active";
"groupId" = "$TeamId"
}
$BodyJSON = ConvertTo-Json $Body
$ContentType = "application/json"
#$AccessToken is not shown here
return Invoke-RestMethod -Headers #{Authorization = "Bearer $AccessToken"} -Uri $ApiUrl -Method $Method -Body $BodyJSON -ContentType $ContentType
}
I can not create a Channel using Graph API (Powershell) of Microsoft Team with email address. I can create Team with default Channel (General) or/and add additional Channels but they all do not have email addresses. When I choose " ... -> Get email Address" of the Channel in the web page I get following message infinitely (couple days):
We're still setting up your team.
Please try again later.
In the document library (Documents) of the SharePoint linked site I do not see a folder General if we talking about General Channel. But after I click to attach a document to Channel in the Conversations tab I get following message:
We're setting up your files.
Check back in a few minutes.
and after several seconds arrise email address in the Channel and folder General in the SharePoint site.
Is it possible to create Channel using GraphAPI with email?
Related
I am trying to list all work item type states for an organisation (visible to the authenticated user) via REST API. It seemed more efficient to list all processes (https://learn.microsoft.com/en-us/rest/api/azure/devops/core/processes/list?view=azure-devops-rest-4.1) and then use the endpoint to list all work item types of those processes together with the states (https://learn.microsoft.com/en-us/rest/api/azure/devops/processes/work-item-types/list?view=azure-devops-rest-4.1&tabs=HTTP). However, I am missing some custom states in the response.
When I list all projects (https://learn.microsoft.com/en-us/rest/api/azure/devops/core/projects/list?view=azure-devops-rest-4.1&tabs=HTTP), then all work item types of those projects (https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work-item-types/list?view=azure-devops-rest-4.1&tabs=HTTP) and then all states of those types (https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work-item-type-states/list?view=azure-devops-rest-4.1&tabs=HTTP), there is everything. But that is sooo many requests.
Can someone explain, why is the first approach not working? Every projet should be associated with a process. Or not? Do you know a better way to get all those states as efficiently as possible?
Thanks in advance. :)
As we can see from the official documentation : Work Item Type States - List, it's in project level not the organization level. So, we need to get the states by project scope.
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitemtypes/{type}/states?api-version=4.1-preview.1
We can write a script to retrieve the projects and work item types in a loop, then get the states of each work item type.
UPDATE:
We can use States - List REST API to return a list of all state definitions in a work item type of the process.
Below PowerShell script for your reference to return the states from a specific process:
Param(
[string]$orgurl = "https://dev.azure.com/{org}",
[string]$processname = "Your-Process-Name",
[string]$user = "",
[string]$token = "PAT"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
#Get Process ID
$processesurl = "$orgurl/_apis/process/processes?api-version=6.0"
$processes = (Invoke-RestMethod -Uri $processesurl -Method Get -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)}).value | where {$_.name -eq $processname }
$processesid = $processes.id
#List Work item types and witRefName
$witsurl = "$orgurl/_apis/work/processes/$processesid/workitemtypes?api-version=6.0"
$witRefNames = (Invoke-RestMethod -Uri $witsurl -Method Get -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)}).value.referenceName #| where {$_.name -eq $processname }
#List WIT states
foreach ($witRefName in $witRefNames){
$statesurl = "$orgurl/_apis/work/processes/$processesid/workItemTypes/$witRefName/states?api-version=6.0"
$states = (Invoke-RestMethod -Uri $statesurl -Method Get -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)}).value.name
Write-Host "==================================================================================="
Write-Host "$witRefName - States:" $states
Write-Host "==================================================================================="
echo `n
}
If you want to retrieve all states from all processes, then you can get the processes and loop them in the script.
I was successfully able to fetch the workitems under a project using the below http request.
http://dev.azure.com/{organization}/{project}/_apis/wit/reporting/workitemrevisions?includeLatestOnly=true&api-version=5.0-preview.2
Similarly, i need to fetch the team workitems, this is the request i had used.
http://dev.azure.com/{organization}/{project}/{team}/_apis/wit/reporting/workitemrevisions?includeLatestOnly=true&api-version=5.0-preview.2
But, i am not getting the workitems.
Can anyone help me with the syntax.
You can get the work items on a team's Taskboard with:
GET https://dev.azure.com/{organization}/{project}/{team}/_apis/work/taskboardworkitems/{iterationId}?api-version=6.0-preview.1
and on a team Iteration with:
GET https://dev.azure.com/{organization}/{project}/{team}/_apis/work/teamsettings/iterations/{iterationId}/workitems?api-version=6.0-preview.1
You could also do a WIQL query:
$AreaPath = "{Project}\{PathYou'reInterestedIn}"
# Example WIQL gets all User Stories and Bugs that are not removed
$wiql = #"
SELECT
[System.Id]
FROM workitems
WHERE
[System.TeamProject] = '$($AreaPath.Split("\")[0])'
AND [System.AreaPath] UNDER '$($AreaPath.Replace("\", "\\"))'
AND [System.State] <> 'Removed'
AND [System.WorkItemType] IN ('User Story', 'Bug')
ORDER BY [System.ChangedDate] DESC
"#
$uri = "https://dev.azure.com/{org}/_apis/wit/wiql?api-version=6.1-preview.2"
# add your access token to the headers
$headers = #{ Authorization = "Basic " + + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$YourAccessTokenValue"))
# I wrote the WIQL to be readable - this makes it suitable for a JSON request
$query = #{ query = ($wiql.split([System.Environment]::NewLine) | `
ForEach-Object { "$($_.Trim())" }) -join " " } | `
ConvertTo-Json
$workItemList = (Invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Body $query).workItems
We are automating the release trigger procedure.
in one of our scenarios we need to trigger release though rest api's, and triggering release should be auto approve.
is there a way I can auto approve the release, do we have any rest api which performs approval.
considering the account which is triggering it got permission to approve the release.
How can I tirgger vsts rest API for a release with auto approver?
For this issue ,you can use Approvals - Update rest api :
PATCH https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/approvals/{approvalId}?api-version=5.1
Sample request body:
{
"status": "approved",
"comments": "go!"
}
If you want to performs approval,you only need to set status to approved.
With Approvals - List rest api,you can get approvalId. You can add parameters to the request url according to your needs, and filter out the exact approval to get approvalId .
Below is my test result with postman :
I have tried this
$deployUrl = "https://vsrm.dev.azure.com/{ornizationName}/{projectName}/_apis/release/approvals/{approvalid}?api-version=5.1"
$body = #{
status = "approved"
comments = "go !"
} | ConvertTo-Json -Depth 4
"body= $body"
$verb= "Patch"
Invoke-RestMethod -Method $verb -ContentType "application/json" -Uri $deployUrl -Headers #{Authorization=("Basic {0}" -f $base64authinfo)} -Body $body
I have an automatic branching utility that does various operations.
We have upgraded to VSTS and I am having trouble using the Tfs calls with the new server:
//login
NetworkCredential netCred = new NetworkCredential("emailAddress", password");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;
TfsTeamProjectCollection tfsServer = new TfsTeamProjectCollection(new Uri("https://myco.visualstudio.com/mycoll"), tfsCred);
// get a local workspace
VersionControlServer sc = server.GetService(typeof(VersionControlServer)) as VersionControlServer;
... other code
and then boom!
"You are not authorized to access https://myco.visualstudio.com/mycoll"
Is there some setting somewhere?
Should I try and use the REST API?
Am I calling something I shouldn't?
I've tried all sorts of formats for the URI, with :8080, with /tfs in the path to no avail!
You can use PAT (Personal Access Token) to access VSTS. Click on your profile in VSTS and go to security menu item. You can define a PAT in there. Keep the PAT saved as it will only be shown once.
Define the scope as per your needs
You can use the PAT to access TFS REST API as shown in following PowerShell sample. Using https://yourAccount.visualstudio.com or https://yourAccount.visualstudio.com/DefaultCollection for ColletionUri parameter is OK.
param(
[Parameter(Mandatory=$true)]
[string] $token,
[Parameter(Mandatory=$true)]
[string] $collectionUri
)
$User=""
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User,$token)));
$header = #{Authorization=("Basic {0}" -f $base64AuthInfo)};
$Uri = $collectionUri + '/_apis/projects?api-version=1.0'
$projects = Invoke-RestMethod -Method Get -ContentType application/json -Uri $Uri -Headers $header
You can find C# code samples here https://www.domstamand.com/accessing-tfs-2017-programmatically/
Alright, so after chatting with Microsoft "Professional Support" they couldn't help me. Told me to access the reports via the SfB Report GUI and export to Excel.
Yeah that's completely worthless to me.
After doing a lot more reading, my 1st example to authenticate was out of date.
Now I have a fully functional oAuth2 PowerShell script that gets me a valid token.
But I'm having the same issue when I use the Graph Explorer (403 Forbidden).
I know the token is working because I can query other information \ if I take away the VAR for the token from the GET header it errors stating the the Bearer Token is empty so everything is right.
Microsoft, if you're out there can someone please confirm that the SfB Report API is up and running for the statistics I'm attempting to pull?
UPDATED SCRIPT
#Obtaining oAuth2 Token from Microsoft Azure \ communicate with Microsoft Graph API
$ClientID = "MyID"
$client_Secret = "MySecretKey"
#Define URI for Azure Tenant
$Uri = "https://login.microsoftonline.com/MyTenantID/oauth2/token"
#Define Microsoft Graph - Skype for Business reports interface URI
$exportSfB = "https://graph.microsoft.com/beta/reports/SfbActivity(view='Detail',date='2017-04-11')/content"
#Define the body of the request
$Body = #{grant_type='client_credentials';client_id=$ClientID;client_secret=$client_secret;resource='https://graph.microsoft.com'}
#Define the content type for the request
$ContentType = "application/x-www-form-urlencoded"
#Invoke REST method. This handles the deserialization of the JSON result. Less effort than invoke-webrequest
$admAuth=Invoke-RestMethod -Uri $Uri -Body $Body -Method Post
#Construct the header value with the access_token just recieved
$HeaderValue = "Bearer " + $admauth.access_token
#Query Microsoft Graph with new Token
$result = Invoke-RestMethod -Headers #{Authorization=$HeaderValue} -Uri $exportSfB –Method Get -Verbose
#Results should be a .CSV
$result.string.'#text'
ORIGINAL THREAD
Can someone please have a look at this REST code and tell me what they think?
I'm receiving:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
CategoryInfo : InvalidOperation
I haven't been able to pull a single Skype for Business activity report using Graph.
$tenant = "MyTenant.onmicrosoft.com"
function GetAuthToken
{
param
(
[Parameter(Mandatory=$true)]
$TenantName
)
$adal = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"
[System.Reflection.Assembly]::LoadFrom($adal) | Out-Null
[System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null
$clientId = "MyID"
$redirectUri = "urn:ietf:wg:oauth:2.0:oob"
$resourceAppIdURI = "https://graph.microsoft.com/"
$authority = "https://login.windows.net/$TenantName"
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId,$redirectUri, "Auto")
return $authResult
}
# Set Token var
$token = GetAuthToken -TenantName $tenant
# Building Rest Api header with authorization token
$authHeader = #{
'Content-Type'='application\json'
'Authorization'=$token.CreateAuthorizationHeader()
}
$uri = "https://graph.microsoft.com/beta/reports/SfbActivity(view='Detail',date='2017-04-11')"
$output = (Invoke-RestMethod -Uri $uri –Headers $authHeader –Method Get –Verbose).value
You're missing /content in your URI. See doc here.
$uri = "https://graph.microsoft.com/beta/reports/SfbActivity(view='Detail',date='2017-04-11')/content"
Ok so after messing with the API and reading I decided to start over from scratch.
Turns out the problem the entire time was the App type in Azure. I was using an app that someone had created prior to me taking on the project. It's application type was set to "Web \ API" in Azure which was incorrect apparently. I created a new App with application type "Native", altered my code with the new secret access key and application client ID and I was able to start pulling down .csv files. The problem now is that the PSTN data isn't there. I created a ticket with the Microsoft Graph group on GitHub requesting information about whether or not they're aware of this problem. At this time, I'm unable to find a programmatic method of exporting PSTN call details via the API. You can keep an eye on their progress here for that request but beyond that I'm stuck until Microsoft Dev makes the SfBActivity detail report include those data fields: https://github.com/microsoftgraph/microsoft-graph-docs/issues/1133