1

I'm attempting to follow the documentation for SXA in a CI/CD process.

Configuration Details:

  • Sitecore 9.1 (Standalone Config - My Local Dev)
  • SXA 1.8 initial release
  • PowerShell 5
  • Running on Windows Server 2016 Standard Edition

Per the documentation, I created my own Web API endpoints in my Project folder of the PowerShell Scripts. I copied the scripts for import and export into my respective copies of the script items.

When I called the web API endpoint using the following path: /-/script/v2/master/site-export-script

I received the following response:

> Exception calling "Run" with "2" argument(s): "startIndex cannot be larger than length of string.
Parameter name: startIndex"
At line:135 char:9
+         [Sitecore.Pipelines.CorePipeline]::Run("ceExport.export", $ex ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException  

This is the Cmdlet from the Get-CreativeExchangeExportResponse

Function Path:

/sitecore/system/Modules/PowerShell/Script Library/SXA/SXA - Creative Exchange/Functions/CI/Get-CreativeExchangeExportResponse

[Sitecore.Pipelines.CorePipeline]::Run("ceExport.export", $exportArgs);

I'm adding this in hopes someone can help speed my research up. Thanks in advance.

Update: 6/24/2019

This is the script file that is run and give the exception below:

Import-Function Get-CreativeExchangeExportResponse

$item = Get-Item -Path "/sitecore/content/Tenant/Site/Home"

$exportArgs = Get-CreativeExchangeExportResponse -CurrentItem $item -DeviceId "{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}"

$responseObject = @{
    "Messages" = $exportArgs.Messages;
    "Result"   = $exportArgs.CreativeExchangeExportStorage.GetResult()
}
Set-HostProperty -HostWidth 9999
[Newtonsoft.Json.JsonConvert]::SerializeObject($responseObject)

Running this code in the PowerShell ISE for Sitecore still produces the following stack trace:

New-Object : Exception calling ".ctor" with "0" argument(s): "Object reference not set to an instance of an object."
At line:115 char:39
+ ... ntextData = New-Object -TypeName "Sitecore.XA.Feature.CreativeExchang ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At line:2 char:5
+     $websitePath = [System.Web.HttpContext]::Current.Server.MapPath(" ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Set-Content : Cannot find path 'master:\CE_auth_c4464daa-f673-4505-81d7-62f3940748fc-2019-06-24T13.55.16.8315406-05.00.aspx' because it does not exist.
At line:16 char:5
+     Set-Content -Value $loginString -Path $filePath
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (master:\CE_auth...5406-05.00.aspx:String) [Set-Content], IOException
    + FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.SetContentCommand

Send-AuthenticationRequest : An Error occured during authentication. Please clean all authentication data
At line:116 char:23
+ ...        $exportArgs = Send-AuthenticationRequest $exportArgs $UserName
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Send-AuthenticationRequest

System.Collections.DictionaryEntry System.Collections.DictionaryEntry
You cannot call a method on a null-valued expression.
At line:42 char:9
+         $websitePath = [System.Web.HttpContext]::Current.Server.MapPa ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "GetCookies" with "1" argument(s): "This operation is not supported for a relative URI."
At line:45 char:5
+     $s.Cookies.GetCookies($Uri) | % {
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidOperationException

Exception calling "Run" with "2" argument(s): "Object reference not set to an instance of an object."
At line:135 char:9
+         [Sitecore.Pipelines.CorePipeline]::Run("ceExport.export", $ex ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException

{"Result":{"Result":" /App_Data/packages/CreativeExchange\\FileStorage\\Site","Type":2},"Messages":[]}
4
  • Can you provide the script and demonstrate that it works from within the ISE? Commented Jun 24, 2019 at 16:12
  • @MichaelWest I have added the details above.
    – Derek Port
    Commented Jun 24, 2019 at 18:58
  • @DerekPort were you able to find the solutions of this issue? I am facing with same on Sitecore 9.3...
    – Anton
    Commented Apr 2, 2021 at 9:14
  • @Anton I got the import working in 9.3 using the included web-api endpoint as an example. I made my own api-endpoint that is called during our release process. In the case above for 9.1, I did get a sitecore support modified script, but didn't have time to implement that for the specific project I was working on at the time.
    – Derek Port
    Commented Apr 16, 2021 at 15:55

1 Answer 1

0

I got the same issue on a different version of Sitecore and SXA. And here is the solution that works for me.

Get-CreativeExchangeExportResponse executes ceExport.export pipeline.

ceExport.export pipeline requires initialization of ExportArgs

ExportArgs has many properties, but we are interested in HttpContextData

public class ExportArgs : PipelineArgs, IMessages
{
    ...
    public HttpContextData HttpContextData
    {
        get;
        set;
    }
    ...
}

HttpContextData parameterless constructor depends on HttpContext.Current

public class HttpContextData
{
    public HttpContextData()
        : this(HttpContext.Current)
    {
    }
}

It means that we need to execute Sitecore Powershell script with HttpContext, otherwise it will throw an exception.

It means that we if you are using Sitecover Powershell ISE: by default, the script executes as a background job. You can try to click on dropdown under Execute button and select "Execute in http request context"

enter image description here

And if we execute Sitecore Powershell as a remote script then we should not use -AsJob parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.