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
Related
We have PowerShell script that will automate creating branch.
Now we are trying to automate branch policies using api using PowerShell Invoke-RestMethod.
We have option to manually add policies using cross repository policies, but we have build validation enabled for repositories which is different for each repo.
I'm able to get the policy configurations using GET https://dev.azure.com/$organization/$project/_apis/policy/configurations/repo=$repoName&api-version=6.0
But don't know how to get the get the particular value and add policies.
You can use the Configurations - Create Rest API:
POST https://dev.azure.com/{organization}/{project}/_apis/policy/configurations/{configurationId}?api-version=6.1-preview.1
In the body you specify the branch policy you want to add, for example - build policy:
{
"isEnabled": true,
"isBlocking": false,
"type": {
"id": "0609b952-1397-4640-95ec-e00a01b2c241"
},
"settings": {
"buildDefinitionId": 5,
"scope": [
{
"repositoryId": null,
"refName": "refs/heads/feature",
"matchKind": "prefix"
}
]
}
}
In the above body you add branch (build) policy to branch feature that requires build 5 to pass.
You cans see all the available policy types in the Types - List api.
To add the Build validation in Branch Policy, you could refer to the following PowerShell Sample:
$token = "PAT"
$url="https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/policy/configurations?api-version=6.1-preview.1"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON = #'
{
"type":{
"id":"0609b952-1397-4640-95ec-e00a01b2c241"
},
"revision":1,
"isDeleted":false,
"isBlocking":true,
"isEnabled":true,
"settings":{
"buildDefinitionId":592,
"displayName":null,
"manualQueueOnly":false,
"queueOnSourceUpdateOnly":true,
"validDuration":720,
"scope":[
{
"repositoryId":"RepoID",
"refName":"refs/heads/BranchName",
"matchKind":"Exact"
}
]
}
}
'#
$response = Invoke-RestMethod -Uri $url -Headers #{Authorization = "Basic $token"} -Method POST -Body $JSON -ContentType application/json
You could refer to this doc about Configurations - Create and Repositories - List
Result:
I have a very basic pipeline with 4 stages, for prod stage i want to run from separate pipeline . I was trying to use build queue rest api as per documentation and using below payload
{
"stagesToSkip": [
"Build"
],
"definition":
{
"id": "24"
},
"resources": {
"repositories": {
"self": {
"refName": "refs/heads/master"
}
}
},
"variables": {}
}
I got this payload when i manually run the build by selecting only one stage and run it works as expected as highlighted but whn i use the rest api with the same request payload , it runs both the stages.
any pointers what i'm doing wrong??
You can use Run Pipeline rest api to skip stages.
POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1
See below example in powershell script:
$url="https://dev.azure.com/{org}/{proj}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1"
$PAT='personal access token'
$body='{
"stagesToSkip":[ "Test" ]
}'
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$result1 = Invoke-RestMethod -Uri $url -Headers #{authorization = "Basic $base64AuthInfo"} -Method post -Body $body -ContentType "application/json"
See below test result. The stage was successfully skipped.
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:
currently i'm attempting to setup GoPhish to launch campaigns through a Windows PowerShell script using it's API. The issue that i'm running into that is i'm getting this error.
Invoke-WebRequest : { "message": "Invalid JSON structure", "success": false, "data": null }
The thing is I have triple checked my JSON structure and it doesn't show any errors in JSON formatting checkers. So my question is if there are any errors in the code I have below for actually pushing these campaigns via PowerShell.
$jsonString = #"
{
"name":"Test6",
"template":{
"name":"Test"
},
"url":"http://redacted",
"page":{
"name":"Test"
},
"smtp":{
"name":"Test SMTP"
},
"launch_date":"2019-25-07T08:20:00+00:00",
"send_by_date":null,
"groups":{
"name":"Test Group"
}
}
"#
Invoke-WebRequest -Uri https://redacted/api/campaigns/?api_key=redacted -Method POST -Body $jsonString
So if you see any errors in what I have an could help me out, that'd be awesome. The API documentation shows that it should be in this format
{
"name":"CC Example Campaign",
"template":{"name":"Example Template"},
"url":"http://localhost",
"page":{"name":"Example Landing Page"},
"smtp":{"name":"Example Sending Profile"},
"launch_date":"2018-10-08T16:20:00+00:00",
"send_by_date":null,
"groups":[{"name":"Example Group"}]
}