Uploaded image for project: 'Artifactory Binary Repository'
  1. Artifactory Binary Repository
  2. RTFACT-20175

403 Forbidden using DELETE Invoke-RestMethod/Invoke-WebRequest

    Details

    • Type: Bug
    • Status: Open
    • Priority: High
    • Resolution: Unresolved
    • Affects Version/s: 6.12.2
    • Fix Version/s: None
    • Component/s: REST API
    • Labels:
    • Environment:

      Windows

      Description

      Unable to delete a file using the Rest API from a Powershell script. The user has permission to delete from the repository and is able to delete files from the repositroy using the UI. However, a (403) Forbidden is returned when deleteing file through the API.

       
      $credentials = New-Object System.Management.Automation.PSCredential ($user_name, $password)  

      Invoke-RestMethod -Method Delete -Uri "http://10.2.94.239:8081/artifactory/pla-nuget-dev-local/pla.1.0.0.219.nupkg" -Credential $credentials
       
      Invoke-RestMethod : The remote server returned an error: (403) Forbidden.
      At C:\PowerShell\ShowArtifactoryUser.ps1:13 char:1
      + Invoke-RestMethod -Method Delete -Uri "http://10.2.94.239:8081/artifa ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

       

      UPDATE:

      Looking at the artifactory logs it appears that the credentials are not being passed as expected. The logs show that the delete api is being made by anonymous. Artifactory logs here:

      2019-09-23 14:17:09,527 [http-nio-8081-exec-8731] [WARN ] (o.a.r.ArtifactoryResponseBase:125) - Sending HTTP error code 403: Not enough permissions to delete/overwrite artifact 'pla-nuget-dev-local:pla-testArtifactoryRepo.1.0.0.221.nupkg' (user 'anonymous' needs DELETE permission).

       

      RESOLVED:

      I needed to use the -Header for authentication instead of -Credentials with Invoke-RestMethod

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              johngriffin John Griffin
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: