I have an application, with which to query Microsoft's API graph. When I run the GET query:
$url = "https://graph.microsoft.com/beta/reports/getTeamsTeamActivityDetail(period='D90')"
$response = Invoke-RestMethod -Headers #{ Authorization = "Bearer $token" } -Uri $url -Method Get
I get back a bunch of results that look like this:
reportRefreshDate : 2022-08-09
teamId : 00000000-0000-0000-0000-000000000000
teamName : 12A19E853726F969FDB1377DFE59408F
lastActivityDate : 2022-08-03
teamType : Private
isDeleted : False
details : {#{activeSharedChannels=0; activeExternalUsers=0; reportPeriod=90;
activeUsers=2; activeChannels=1; channelMessages=0; reactions=0;
meetingsOrganized=0; postMessages=0; replyMessages=0;
urgentMessages=0; mentions=0; guests=0}}
In this example, I have 1580 results, but they all have the same teamId (00000000-0000-0000-0000-000000000000) and different, random values for teamName (that is to say that none of the team names are actually names of our groups/teams).
I can get groups with:
https://graph.microsoft.com/v1.0/groups?`$filter=resourceProvisioningOptions/Any(x:x eq 'Team')
What is going on with this activity report?
Had the same issue as you.
This fixes it:
https://blog.atwork.at/post/Get-the-latest-Teams-activity-with-Graph
Related
the first try catch works, he is adding the ms graph AD group in office365.
But the second try catch (converting the group to a Team does not work. I receive an 404 error??
The groupID exists on the server I notice.
Whats going wrong to get an 404?
I did add a secret token on the azure control panel.
The script has the token, appid and tenantid in live time.
also: the tenant has graph roles like group.ReadWriteAll. same for Teams and Directories.
Clear-Host
$env:graphApiDemoAppId = "" # Replace with your Azure AD app id
$env:graphApiDemoAppSecret = "" # Replace with your Azure AD app secret
$env:tenantId = "" # Replace with your Azure AD tenant ID
$oauthUri = "https://login.microsoftonline.com/$env:tenantId/oauth2/v2.0/token"
# Create token request body
$tokenBody = #{
client_id = $env:graphApiDemoAppId
client_secret = $env:graphApiDemoAppSecret
scope = "https://graph.microsoft.com/.default"
grant_type = "client_credentials"
}
# Retrieve access token
$tokenRequest = Invoke-RestMethod -Uri $oauthUri -Method POST -ContentType "application/x-www-form-urlencoded" -Body $tokenBody -UseBasicParsing
# Save access token
$accessToken = ($tokenRequest).access_token
$headers = #{
"Authorization" = "Bearer $accessToken"
"Content-type" = "application/json"
}
try
{
# Create group request body
$groupName = "Test_Kenvh16"
$groupBodyParams = #{
displayName = $groupName
description = $groupName
mailNickName = $groupName
groupTypes = #("Unified")
mailEnabled = $true
securityEnabled = $false
visibility = "Private"
}
$groupBody = ConvertTo-Json -InputObject $groupBodyParams
$newGroup = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/groups" -Method POST -Headers $headers -Body $groupBody
$groupId = $newGroup.id
Write-Host "group created:" $groupName "id:" $groupId
try
{
#convert group to team..
$teamBodyParams = #{
memberSettings = #{
allowCreateUpdateChannels = $true
}
messagingSettings = #{
allowUserEditMessages = $true
allowUserDeleteMessages = $true
}
funSettings = #{
allowGiphy = $true
giphyContentRating = "strict"
}
}
$teamBody = ConvertTo-Json -InputObject $teamBodyParams
$teamUri = "https://graph.microsoft.com/v1.0/groups/" + $groupId + "/team"
$newTeam = Invoke-RestMethod -Uri $teamUri -Method POST -Headers $headers -Body $teamBody
$teamId = $newTeam.id
}
catch
{
Write-Host "createTeam ExceptionMessage:" $_.Exception.Message
Write-Host "createTeam StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "createTeam StatusDescription:" $_.Exception.Response.StatusDescription
}
}
catch
{
Write-Host "createGroup ExceptionMessage:" $_.Exception.Message
Write-Host "createGroup StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "createGroup StatusDescription:" $_.Exception.Response.StatusDescription
}
I am using this api end to post user in audience list id(which i am creating dynamically).
Here is code i am using -:
require '../vendor/autoload.php';
require 'config.php';
$api = TwitterAds::init(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
$responseAcc = $api->get('accounts');
$account = $responseAcc->getBody();
$twAdsAccId = $account->data[0]->id;
$response = $api->post('accounts/'.$twAdsAccId.'/tailored_audiences',array('name'=>'Test'));
$newAudiDat = $response->getBody();
$audienceId = $newAudiDat->data->id;
$userJson = '{
{
"users": [
{
"email": [
"c88a2aba7408c019ea7e721832cc89aeec2f91169872a977fbbe46d642c8fdd9"
]
}
]
}
}';
$responseAudieUser =$api->post('accounts/'.$twAdsAccId.'/tailored_audiences/'.$audienceId.'/users',array('operation_type'=>'Update','params'=> $userJson));
But when I am printing the response it is showing error :-
caught exception 'Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError' with message 'SERVER_ERROR' in /opt/lampp/htdocs/demo/tweets-php/vendor/hborras/twitter-php-ads-sdk/src/TwitterAds.php:501
I think I am passing parameter in wrong way so i searched but did not get any lead .
Note -: All parameters are sent in the request body and a Content-Type of application/json is required (Please see).
Here Hector, maintainer of this project
Could you create a new Issue here : https://github.com/hborras/twitter-php-ads-sdk/issues ?
Meantime I'll try to see what is happening
Thanks!
I am trying to dismiss/close risk events using an automated process. For this we would need to make use of Graph API https://graph.microsoft.com/beta/riskyUsers/dismiss
I did searched for examples and couldn't find any.
I did tried using Post man by providing OAuth Bearer token in the header and I did tried with a PowerShell script and I also tried with .Net example provided in the page. None of them worked
PowerShell Code
{
$body = #{grant_type="client_credentials";resource=$resource;client_id=$ClientID;client_secret=$ClientSecret}
$oauthResponse = Invoke-RestMethod -Method POST -Uri $loginURL/$TenantName/oauth2/token?api-version=1.0 -Body $body
return $oauthResponse
}
$loginURL = "https://login.windows.net"
$resource = "https://graph.microsoft.com"
$ClientSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$ClientID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$TenantName="xxxxx.com"
$oauth=RefreshToken -loginURL $loginURL -resource $resource -ClientID $ClientID -clientSecret $ClientSecret -tenantName $TenantName
$headerParams = #{'Authorization'="$($oauth.token_type) $($oauth.access_token)"}
$url="https://graph.microsoft.com/beta/riskyUsers/dismiss"
$userIds=#()
$userIds+="xxxxx-xxxxx-xxxxx-xxxxx-xxxxx"
$body=(#{"userIds"=$userIds})|convertto-json
$Response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Body $body -Method Post -ContentType "application/Json"
Response:
Invoke-WebRequest : The remote server returned an error: (500) Internal Server Error.
At C:\SourceCode\MIMSolution\PowerShellScripts\AzurePSMA\RiskyIdentityEvents\ExportScript_debug.ps1:19 char:13
+ $Response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
C# Code:
static void Main(string[] args)
{
var userIdsList = new List<String>();
userIdsList.Add("xxxxx-xxxxx-xxxxx-xxxxx-xxxx");
dismissUser(userIdsList);
}
static async void dismissUser(List<string> userIDs)
{
ClientCredential clientCredential = new ClientCredential("xxxxxxxxxxxxxxxxxxxxxxx");
string clientId = "xxxxxxxxxxxxxxxxxxxxxx";
IConfidentialClientApplication clientApplication = ClientCredentialProvider.CreateClientApplication(clientId, clientCredential);
ClientCredentialProvider authProvider = new ClientCredentialProvider(clientApplication);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
await graphClient.RiskyUsers.Dismiss(userIDs).Request().PostAsync();
}```
Exception:
{"Code: generalException\r\nMessage: An error occurred sending the request.\r\n"}
Inner Exception:
{"Code: generalException\r\nMessage: Unexpected exception occured while authenticating the request.\r\n"}
Finally after multiple trails , I have figured out the solution:
Issue was with the token which as OAuth 1.0 earlier.
I did fixed this snippet that request OAuth 2.0 and the issue resolved:
function RefreshToken($loginURL,$ClientID,$clientSecret,$tenantName)
{ $body = #{grant_type="client_credentials";client_id=$ClientID;client_secret=$ClientSecret;scope="https://graph.microsoft.com/.default"}
$oauthResponse = Invoke-RestMethod -Method POST -Uri $loginURL/$TenantName/oauth2/v2.0/token -Body $body
return $oauthResponse
}
Using Scrum process in TFS 2018 on-premises, I'd want to change the Bug(s) state to Committed when a developer creates a pull request that references Work Items.
Any idea how to accomplish that?
You cannot achieve that automatically for now as no such a built-in feature in TFS. I have submitted a user voice here for you to suggest the feature, you can go and vote it up to achieve that in future release...
However as a workaround you can update the state for a specific work item (Bug here) manually or by calling the REST API.
Please see Fields - Update for details.
PowerShell for example:
Param(
[string]$baseurl = "http://server:8080/tfs/DefaultCollection",
[string]$projectName = "0511ScrumTFVC",
[string]$workitemid = "124",
[string]$user = "domain\user",
[string]$token = "Password"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
write-host $WorkitemType
function CreateJsonBody
{
$value = #"
[
{
"op": "test",
"path": "/rev",
"value": 2
},
{
"op": "add",
"path": "/fields/System.State",
"value": "Committed"
}
]
"#
return $value
}
$json = CreateJsonBody
$uri = "$baseurl/_apis/wit/workitems/$($workitemid)?api-version=2.2"
Write-Host $uri
$result = Invoke-RestMethod -Uri $uri -Method Patch -Body $json -ContentType "application/json-patch+json" -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)}
I made a really simple Neo4j 2.0 Server Plugin that works great without any parameters. However, I'm not sure how I'm supposed to pass a string parameter to the plugin. I have one optional parameter called "criteria". This should be very simple. I'm just not very familiar with CURL, java, or REST.
#Name( "getLabelsForSearch" )
#Description( "Get all labels that match the search criteria from the Neo4j graph database" )
#PluginTarget( GraphDatabaseService.class )
public Iterable<String> getLabelsForSearch( #Source GraphDatabaseService graphDb, #Description("The search criteria string") #Parameter (name = "criteria", optional = true) String criteria )
{
ArrayList<String> labels = new ArrayList<>();
labels.add(criteria);
try (Transaction tx = graphDb.beginTx())
{
for ( Label label : GlobalGraphOperations.at(graphDb).getAllLabels() )
{
labels.add(criteria);
//This is just for testing
labels.add(label.name());
}
tx.success();
}
return labels;
}
I tried a few different ways with curl:
curl -X POST http://icexad01:7474/db/data/ext/GetAll/graphdb/getLabelsForSearch?criteria=thisorthat
curl -X POST http://icexad01:7474/db/data/ext/GetAll/graphdb/getLabelsForSearch/criteria/thisorthat
curl -X POST http://icexad01:7474/db/data/ext/GetAll/graphdb/getLabelsForSearch -data { "criteria" : "thisorthat"}
I've been following this page and it has an example of passing a parameter. Maybe I'm just overlooking something?
http://docs.neo4j.org/chunked/snapshot/server-plugins.html
This is the json information I get back when I do a GET request on the url:
http://icexad01:7474/db/data/ext/GetAll/graphdb/getLabelsForSearch/
{
"extends" : "graphdb",
"description" : "Get all labels that match the search criteria from the Neo4j graph database",
"name" : "getLabelsForSearch",
"parameters" : [ {
"description" : "The search criteria string",
"optional" : true,
"name" : "criteria",
"type" : "string"
} ]
}
You need to pass in the parameters in JSON format. Therefore it's crucial to specify the content type and to put the payload in quotes, so try
curl -X POST -H "Content-Type: application/json" -data '{ "criteria" : "thisorthat"}' http://icexad01:7474/db/data/ext/GetAll/graphdb/getLabelsForSearch