I have registered an Incoming Messages Webhook in one of my Teams channels.
I am using Microsoft Teams PowerShell to create an adaptive card and send it to a channel:
$SimpleCard = #{
type = "message";
attachments = #(#{
contentType = 'application/vnd.microsoft.card.adaptive';
contentUrl = $null;
content = #{
'$schema' = 'http://adaptivecards.io/schemas/adaptive-card.json';
type = 'AdaptiveCard';
version = '1.2';
body = #(#{
type = 'TextBlock';
text = "Hello <at>andrea.tino#mycompany.com</at>";
})
}
});
msteams = #{
entities = #(#{
type = 'mention';
text = "<at>andrea.tino#mycompany.com</at>";
mentioned = #{
id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
name = 'Andrea Tino';
}
})
}
}
Invoke-RestMethod -Method post
-ContentType 'Application/Json'
-Body ($SimpleCard | ConvertTo-Json -Depth 10)
-Uri "https://myorg.webhook.office.com/webhookb2/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx#xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/IncomingWebhook/xxxxxxxx/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
The card is correctly sent but the mention is not correctly rendered.
Wrong ID?
It is worth mentioning that the doc makes explicit reference to a type of User ID:
{
"type": "mention",
"text": "<at>John Doe</at>",
"mentioned": {
"id": "29:123124124124",
"name": "John Doe"
}
}
You can see that the ID in the example is: "id": "29:123124124124" while mine is a GUID. I retrieved that User ID by means of Get-TeamUser.
What am I doing wrong?
Mention in adaptive card is supported only in context of bot and the available ways to get id are listed in the document - mention-support-within-adaptive-cards-v12
Concerned team is working to support user mention using AAD Object Id and UPN(use Graph API) in Incoming Webhook.
ID and Name can be fetched from the activity as follows
from: {
id: '29:15fREhoUuf6vVCOuaJYVH-AB6QXXX',
name: 'MOD Administrator',
aadObjectId: 'XXXX'
}
Giving a reference that will help - mention-support-within-adaptive-cards-v12
Related
I have created a webhook in Azure Automation. I am looking to pass the body when the webhook is called to a logic app. Please see the powershell code designed of runbook.
param
(
[Parameter(Mandatory=$false)]
[object] $WebhookData
#[string] $jobId
)
if ($WebhookData.RequestBody) {
$names = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)
Write-Output $names
$webhookName = $WebhookData.WebhookName
$logicappURI = "https://logicapp/api/test/triggers/manual/invoke/properties/"+$webhookName+"?api-version=2022-05-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig={signature_certificate"
$response = Invoke-WebRequest -Method GET -Uri $logicappURI
}
else {
Write-Output "Hello World!"
}
Currently I am able to call the logic app and pass the webhook name, but the i would like to pass the complete request body. Below is the request body for webhook.
{
"WebhookName": "wh-test-webhook-ext-cus-001",
"RequestBody": "[{\"Name\": \"Hawaii\" },{\"Name\": \"Seattle\"},{ \"Name\": \"Florida\"}]",
"RequestHeader": {
"Connection": "Keep-Alive",
"Host": "14304127-e302-4499-b819-8ac4493555e9.webhook.cus.azure-automation.net",
"User-Agent": "Mozilla/5.0",
"x-ms-request-id": "47ca3f1a-2418-4553-94c4-9f20c2095c80"
}
}
The logic app is designed to trigger when an HTTP request is recieved. As shown in the image I am passing passing webhook name. Similarly is there a way I can pass the complete ReuqestBody.
Thanks in advance.
Logic App Design
I'm learning both Grafana, AND how to interact with APIs in Powershell. I was able to use the Grafana HTTP API to create a dashboard, however I cannot get the same API to create a Datasource. My code is as follows:
$header = #{"Authorization" = "Bearer apikey="}
$createDatasourceUri = "http://localhost:3000/api/datasources"
$createDatasourcejson = #'
{
"datasource": {
"name": "prometheusApiTest",
"type": "prometheus",
"url": "http://localhost:9090",
"access": "proxy",
"basicAuth": false,
"isDefault": true
}
}
'#
$datasourceParameters = #{
Method = "POST"
URI = $createDatasourceUri
Body = $createDatasourcejson
Headers = $header
ContentType = "application/json"
}
Invoke-RestMethod #datasourceParameters
I am presented with the following error:
Invoke-RestMethod : [{"fieldNames":["Name"],"classification":"RequiredError","message":"Required"},{"fieldNames":["Type"],"classification":"RequiredError","message":"Required"},{"fieldNames":["Access"],"classificat
ion":"RequiredError","message":"Required"}]
I do not know what's going on. Anything I can find about this error says I need to specify the ContentType as "application/json", but I've very clearly done so. I do receive data when I do a "GET" on that API endpoint, and even copying the data that gets returned still results in the above error. I'm at a complete loss, as this same code worked to create a dashboard (albeit with the right json payload for a dashboard). Any ideas?
The Grafana docs for the Datasource API only has the datasource element in the response, not the initial call. Line 5 of my code, and the subsequent {} for that element, are not needed, and the script functions with those lines removed.
I'm querying the Monday API v2 (https://monday.com/developers/v2) I'm getting stuck in getting the PowerShell query to work, the script is below:
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
$url = "https://api.monday.com/v2/"
$hdr = #{ }
$hdr.Add("Authorization", "redacted")
$hdr.Add("Content-Type", "application/json")
$bodytxt = '{"query":"mutation{change_column_value (board_id: 528033866, item_id: 574335355, column_id: \"status_1\", value: "{\"index\": 1}") {id}}"}'
$response = Invoke-WebRequest -Uri $url -Headers $hdr -Method Post -body $bodytxt
Write-Host $response
And it keeps returning
{"errors":[{"message":"Parse error on \": 1}\" (STRING) at [1, 110]","locations":[{"line":1,"column":110}]}],"account_id":5305133}
The mutation query in Postman works fine
change_column_value (board_id: 528033866, item_id: 574335355, column_id: "status_1", value: "{\"index\": 1}"){id}
}
I have tried working with what quotes are escaped, but I still haven't been able to get it to run succesfully. I was referencing the tips here https://www.reddit.com/r/PowerShell/comments/b9jasa/query_graphql_with_powershell/
Any thoughts on how to fix this error?
EDIT: Sorry forgot to add the current query (not mutation) that works fine through Powershell
$bodytxt = '{"query":"{ boards (ids: 528033866) { groups (ids: \"group_title\"){ items () { id name updates () { body } column_values () { id title value text } } title } } }"}'
The easiest way to create a GraphQL query is
create a hashtable with HERE-STRINGS
convert it to a JSON string with ConvertTo-Json.
$bodytxt = #{"query" = #'
mutation {
change_column_value(
board_id: 123123
item_id: 456456
column_id: "status1"
value: "{\"index\":1}"
) {
id
}
}
'#
} | ConvertTo-Json
White spaces inside #'...'# are optional.
reply to this comment
it should always work in the API call with the GraphQL?
I think it depends on services, but in most cases, yes. application/json is the GraphQL default content type for the request body.
and for monday.com
Be sure to use the application/json content type
I want to add users to my Azure DevOps Services Organization programatically without them getting notifications. I've started with a script like below using the User Entitlement Rest API but users still get notifications:
$method = 'POST'
$devopsuri = "https://vsaex.dev.azure.com/<Devops org name>/_apis/userentitlements?api-version=5.1-preview.1"
$pat = "<pat>"
$encodedPat = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$pat"))
$header = # {
Authorization = "Basic $encodedPat"
}
$body = # {
"accessLevel" = # {
"accountLicenseType" = "stakeholder"
}
"user" = # {
"principalName" = "<UPN>"
"subjectKind" = "user"
}
} | ConvertTo - Json - Depth 5
$result = Invoke - RestMethod - Uri $devopsuri - Method $method - Headers $header - Body $body - UseBasicParsing - ContentType 'application/json'
https://stackoverflow.com/questions/ask#
When we don’t check Send email invites in UI, invitees will not receive notification.
So we can grab this api by pressing f12 in the browser.
Rest api: need to add doNotSendInviteForNewUsers=true to the url and use PATCH method.
PATCH https://vsaex.dev.azure.com/{org}/_apis/UserEntitlements?doNotSendInviteForNewUsers=true&api-version=5.1-preview.1
Sample request body:
[{"from":"","op":0,"path":"","value":{"accessLevel":{"licensingSource":1,"accountLicenseType":2,"msdnLicenseType":0,"licenseDisplayName":"Basic","status":0,"statusMessage":"","assignmentSource":1},"user":{"principalName":"XXXX#outlook.com","subjectKind":"user"}}}]
My test in Postman:
I can create a post to Glip with the following code:
$AddPostHeader = #{'Content-Type' = 'application/json';'Authorization'='Bearer ' + $token}
$AddPostURL = 'https://platform.devtest.ringcentral.com/restapi/v1.0/glip/chats/' + $selectedGroup + '/posts'
$AddPostBody = #{'type' = 'TextMessage'; 'text' = 'This post was written from Powershell'}
$AddPostBody = ConvertTo-Json $AddPostBody
$NewPost = Invoke-RestMethod -h $AddPostHeader -Body $AddPostBody $AddPostURL -Method 'POST'
$AddPostURL
$NewPost
But how can I create a Task?
This says I can: https://medium.com/ringcentral-developers/automating-team-productivity-with-glip-748a05aa32e9
I have referenced https://developers.ringcentral.com/api-reference without any luck? Is there an option 'type' for a post?
The API References now has a set of RingCentral Tasks APIs. The Create Tasks API is here:
https://developers.ringcentral.com/api-reference/Tasks/createTask
A quick example of using this API using HTTP is as follows:
Required fields:
chatId (path)
subject (body) Task name
assignees (body) personId for assignee
Example Request:
POST https://platform.ringcentral.com/restapi/v1.0/glip/chats/{chatId}/tasks
Authorization: Bearer <myToken>
Content-Type: application/json
{
"subject": "My New Task",
"assignees": [{"id":"123"}]
}