GetIdServerToken - Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

Error:
[-------------- CommerceEngine-Initialize_GetIdServerToken : GetIdServerToken ----------------------------------------]
VERBOSE: Resolving ConfigFunction extension 'concat'
VERBOSE: Resolved 'Invoke-ConcatConfigFunction'
VERBOSE: Resolving ConfigFunction extension 'concat'
VERBOSE: Resolved 'Invoke-ConcatConfigFunction'
VERBOSE: Invoke-ConcatConfigFunction
VERBOSE: Concatenating: \ admin
VERBOSE: Result: \admin
VERBOSE: Invoke-ConcatConfigFunction
VERBOSE: Concatenating: sitecore \admin
VERBOSE: Result: sitecore\admin
VERBOSE: Resolving ConfigFunction extension 'concat'
VERBOSE: Resolved 'Invoke-ConcatConfigFunction'
VERBOSE: Invoke-ConcatConfigFunction
VERBOSE: Concatenating: https://sc92commdev2.local.IdentityServer /connect/token
VERBOSE: Result: https://sc92commdev2.local.IdentityServer/connect/token
Get Token From Sitecore.IdentityServer
VERBOSE: POST https://sc92commdev2.local.identityserver/connect/token with -1-byte payload
Install-SitecoreConfiguration : The remote server returned an error: (400) Bad Request.
At C:\deploy\Sitecore.Commerce.WDP.2019.07-4.0.165\SIF.Sitecore.Commerce.3.0.28\My-SC9-XC-Deploy-Sitecore-Commerce -
latest-2 - dev.ps1:93 char:1
+ Install-SitecoreConfiguration @params -Verbose *>&1 | Tee-Object "$PS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Install-SitecoreConfiguration

[TIME] 00:24:38
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At C:\deploy\Sitecore.Commerce.WDP.2019.07-4.0.165\SIF.Sitecore.Commerce.3.0.28\Modules\InitializeCommerce\InitializeCo
mmerce.psm1:86 char:17
+ ... $response = Invoke-RestMethod $UrlIdentityServerGetToken -Method Post ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Solution:
If you are sure you are passing the correct sitecore user name and password that was created for the SXA instance, the possibility for this error, is if you are trying to create a second commerce instance on your machine, there is some kind of overlap or wrong credentials passed. I always ensure that my new instance is unique with respect to names and ports. Also, the windows user name and password must be correct. What was passed first time must be passed  in the subsequent installs too. The other option is, to pass unique windows username and password for each installation.

Here is the list of params to take care of during Sitecore commerce 10 installation. The unique ones should be unique across commerce installs to avert this error.

[string]$SiteNamePrefix = "sc10sxa" (same as sxa install)
[string]$SiteName = "sc10sxasc.dev.local" (same as sxa install)
[string]$IdentityServerSiteName = "sc10sxaIdentityserver.dev.local" (same as sxa install)
[string]$SitecoreIdentityServerUrl = "https://sc10sxaIdentityserver.dev.local" (same as sxa install)
[string]$SiteHostHeaderName = "sc10sxasc.storefront.com" (better keep unique)

[string]$InstallDir = "C:\inetpub\wwwroot\sc10sxasc.dev.local" (same as sxa install)
[string]$XConnectInstallDir = "C:\inetpub\wwwroot\sc10sxaxconnect.dev.local"  (same as sxa install)
[string]$SqlDbPrefix = $SiteNamePrefix (same as sxa install)
[string]$SitecoreCoreDbName = "$($SqlDbPrefix)_Core" (same as sxa install)
[string]$SqlUser = "sa", (same as sxa install, must be correct)
[string]$SqlPass = "xysss", (same as sxa install, must be correct)

[string]$SitecoreDomain = "sitecore", (must be correct)
[string]$SitecoreUsername = "admin", (must be correct)
[string]$SitecoreUserPassword = "b", (must be correct)

[string]$SearchIndexPrefix = "sc10sxasc.dev.local" (better keep unique)
[string]$SolrUrl = "https://solr840:8988/solr", (must be correct, same as sxa install)
[string]$SolrRoot = "C:\Solr\solr-8.4.0", (must be correct, same as sxa install)
[string]$SolrService = "solr-8.4.0", (must be correct, same as sxa install)
[string]$StorefrontIndexPrefix = $SiteNamePrefix

[string]$CommerceServicesDbServer = "newspotvm202008" (must be correct)
[string]$CommerceServicesDbName = "sc10sxasc_SitecoreCommerce_SharedEnvironments" (better keep unique)
[string]$CommerceServicesGlobalDbName = "sc10sxasc_SitecoreCommerce_Global" (better keep unique)
[string]$CommerceOpsServicesPort = "6015" (better keep  unique)
[string]$CommerceShopsServicesPort = "6005" (better keep  unique)
[string]$CommerceAuthoringServicesPort = "6000" (better keep  unique)
[string]$CommerceMinionsServicesPort = "6010" (better keep  unique)
[string]$CommerceServicesPostfix = "sc10sxasc" (better keep  unique)
[string]$CommerceServicesHostPostfix = "sc10sxasc.com" (better keep unique)
[string]$BizFxSiteName = "SitecoreBizFx-sc10sxasc" (better keep unique)
[string]$BizFxPort = "5200" (better keep unique)

[string]$UserName = "sc10sxasc_User" (windows user name , better keep unique)

Comments

Popular Posts