0
votes

Hi I am running REST API call using the powershell task in Azure pipeline, how do i pass the $body value to the below API endpoint

Invoke-RestMethod -Uri $uri -Method Post -ContentType "application/json" -Headers $header -Body $body

Reference of the below request body,

enter image description here

1
Is your issue solved? Have you checked my sample? Is it working for you? - Cece Dong - MSFT

1 Answers

0
votes

It seems you are trying to move a file, check the sample below:

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)}