locked
Pull request's comments list are not coming by using Azure DevOps rest api within PowerShell RRS feed

  • Question


  • I am using Azure DevOps rest api for getting all the comments of the every pull request. I have go through Microsoft documentation. I followed same. But when i see my json response, it does not show list of comments. it is getting following result as i fire get request.

    official url given in documentation

    https://dev.azure.com/myorg/_apis/git/repositories/jd7489eiu-e5bb-37f7-kl05-098kd4dd/pullRequests/192/threads/{threadId}/comments?api-version=5.1"

    I tried following urls for achieve my result 

    https://dev.azure.com/myorg/_apis/git/repositories/jd7489eiu-e5bb-37f7-kl05-098kd4dd/pullRequests/192/threads?api-version=5.1"

    I have written following powershell code to get things done.

    $orgUrl = "https://dev.azure.com/MyOrg"
    function GetUrl() {
        param(
            [string]$orgUrl, 
            [hashtable]$header, 
            [string]$AreaId
        )
    
        # Build the URL for calling the org-level Resource Areas REST API for the RM APIs
        $orgResourceAreasUrl = [string]::Format("{0}/_apis/resourceAreas/{1}?api-preview=5.0-preview.1", $orgUrl, $AreaId)
        #$orgResourceAreasUrl = [string]::Format("{0}/_apis/git/pullrequests?api-version=5.1", $orgUrl)
        
        # Do a GET on this URL (this returns an object with a "locationUrl" field)
        $results = Invoke-RestMethod -Uri $orgResourceAreasUrl -Headers $header
    
        # The "locationUrl" field reflects the correct base URL for RM REST API calls
        if ("null" -eq $results) {
            $areaUrl = $orgUrl
        }
        else {
            $areaUrl = $results.locationUrl
        }
    
        return $areaUrl
    }
    $currentAzureContext = Get-AzContext
    $azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile;
    $profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azureRmProfile);
    $profileClient.AcquireAccessToken($currentAzureContext.Subscription.TenantId).AccessToken;
    
    $personalToken = $profileClient.AcquireAccessToken($currentAzureContext.Subscription.TenantId).AccessToken;
    
    Write-Host "Initialize authentication context" -ForegroundColor Yellow
    $token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalToken)"))
    $header = @{authorization = "Basic $token"}
    # Area ids
    # https://docs.microsoft.com/en-us/azure/devops/extend/develop/work-with-urls?view=azure-devops&tabs=http&viewFallbackFrom=vsts#resource-area-ids-reference
    # https://dev.azure.com/_apis/resourceAreas/79134C72-4A58-4B42-976C-04E7115F32BF?accountName=HEWDevOps&api-version=5.0-preview.1
    
    # DEMO 1 List of projects
    Write-Host "Demo 1"
    $coreAreaId = "efc2f575-36ef-48e9-b672-0c6fb4a48ac5"
    $tfsBaseUrl = GetUrl -orgUrl $orgUrl -header $header -AreaId $coreAreaId
    # https://docs.microsoft.com/en-us/rest/api/azure/devops/core/projects/list?view=azure-devops-rest-5.0
    $removevsrm = $tfsBaseUrl.Replace("vsrm.","")
    $projectsUrl = "$($removevsrm)_apis/git/repositories/75juis74-e5bb-445f-b407-9085idk75l93/pullRequests/192/threads/comments?api-version=5.1"
    $projects = Invoke-RestMethod -Uri $projectsUrl -Method Get -ContentType "application/json" -Headers $header
    Write-Output $projects | ConvertTo-Json

    returning comments are empty

    {
       "pullRequestThreadContext":  null,
       "id":  1341,
       "publishedDate":  "2019-02-05T13:15:20.903Z",
       "lastUpdatedDate":  "2019-02-05T13:15:20.903Z",
       "comments":  "",
       "threadContext":  null,
       "properties":  "@{BypassPolicy=; BypassReason=; CodeReviewStatus=; CodeReviewStatusUpdateAssociatedCommit=; CodeReviewThreadType=; CodeReviewStatusUpdatedByIdentity=}",
       "identities":  "@{1=}",
       "isDeleted":  false,
       "_links":  "@{self=; repository=}"
    }

    https://dev.azure.com/myOrg/_apis/git/repositories/75juis74-e5bb-445f-b407-9085idk75l93/pullRequests/192/threads/131/comments?api-version=5.1"

    Above url is returning same result as above.

    https://dev.azure.com/myorg/_apis/git/repositories/75juis74-e5bb-445f-b407-9085idk75l93/pullRequests/192/threads/131?api-version=5.1"

    returning comments are empty

    {
       "pullRequestThreadContext":  null,
       "id":  1341,
       "publishedDate":  "2019-02-05T13:15:20.903Z",
       "lastUpdatedDate":  "2019-02-05T13:15:20.903Z",
       "comments":  "",
       "threadContext":  null,
       "properties":  "@{BypassPolicy=; BypassReason=; CodeReviewStatus=; CodeReviewStatusUpdateAssociatedCommit=; CodeReviewThreadType=; CodeReviewStatusUpdatedByIdentity=}",
       "identities":  "@{1=}",
       "isDeleted":  false,
       "_links":  "@{self=; repository=}"
    }

    As you can see comments section is empty while originally pull request has 10 comments.

    Did anyone facing the same problem, or know the solution please let me know. while i am running same URl on my browser (which already cached my Azure DevOps credentials) returning full comments section.



    Tuesday, September 24, 2019 9:53 AM

All replies

  • Azure DeVos questions should be posted here: https://azure.microsoft.com/en-us/support/devops/


    \_(ツ)_/

    Tuesday, September 24, 2019 11:18 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Thursday, October 3, 2019 2:23 AM