嗨,我正在使用Azure管道中的powershell任务运行REST API调用,如何将$ body值传递给以下API端点
Invoke-RestMethod -Uri $ uri -Method Post -ContentType“ application / json” -Headers $ header -Body $ body
以下请求正文的引用
答案 0 :(得分:0)
似乎您正在尝试移动文件,请检查以下示例:
Param(
[string]$organisation = "organisation",
[string]$repositoryId = "f2aa1d87-xxxx-48df-xxxx-6505ffxxxxf9",
[string]$keepForever = "true",
[string]$user = "user",
[string]$token = "token" )
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$postresults = "https://dev.azure.com/$organisation/_apis/git/repositories/$repositoryId/pushes?api-version=6.0"
$body = '{
"refUpdates": [
{
"name": "refs/heads/master",
"oldObjectId": "6e3c1f07d12eaf805a16db1352771816148c24b5"
}
],
"commits": [
{
"comment": "Moving activetasks.md to a new folder.",
"changes": [
{
"changeType": "rename",
"sourceServerItem": "/activetasks.md",
"item": {
"path": "/tasks/content/activetasks.md"
}
}
]
}
]
}'
$result = Invoke-RestMethod -Uri $postresults -Method Post -Body $body -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}