Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

powershell script for installing package in AEM from Octopus

Avatar

Level 2

power shell script for installing package in AEM through Octopus

HI,

I am wroking on automating the build using the octopus.

with the user of power shell script i have taken the package from nexus repository and uploaded in my local crxde.

but i am not able to install the package. i am facing below error when installing the pacakge. please advice what i am missing.

_______________________________

$url = "http://localhost:4502/crx/packmgr/service/.json/etc/packages/export/{2}?cmd=install"

#$pair = "$($user):$($pass)"

#$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))

#$basicAuthValue = "Basic $encodedCreds"

#$Headers = @{

#    Authorization = $basicAuthValue

#}

$JSON = @{

    "@type" = "login"

    "username" = 'admin'

    "password" = 'admin'

} | ConvertTo-Json

$response = Invoke-RestMethod -Uri $url -Method POST -Body $JSON -ContentType "application/json"

Write-Host $response

Write-Host "Done"

ERROR

Invoke-RestMethod : The remote server returned an error: (403) Forbidden.

At line:20 char:14

+ ... $response = Invoke-RestMethod -Uri $url -Method POST -Body $JSON -Con ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebE

   xception

    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

1 Accepted Solution

Avatar

Correct answer by
Level 10

Configure Sling Referrer Filter and CSRF filter to work with this script or otherwise pass additional headers to make it work

Refer - How to make a simple HTTP POST request to AEM with a HTTP Rest Client, Postman - Sourced Code

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

Configure Sling Referrer Filter and CSRF filter to work with this script or otherwise pass additional headers to make it work

Refer - How to make a simple HTTP POST request to AEM with a HTTP Rest Client, Postman - Sourced Code