Cognos.Office.Tm1.Connections.Tm1WebException: The remote server returned an error

Product:
Planning Analytics 2.0.5
PAX and PAW
Cognos Analytics 11.0.12
Microsoft Windows 2016 server

Problem:
When starting Excel and selecting Planning Analytics for Excel (TM1) you get a error after the login dialog.

Error message:
Cognos.Office.Tm1.Connections.Tm1WebException: The remote server returned an error: (503) Server Unavailable. —> System.Net.WebException: The remote server returned an error: (503) Server Unavailable.
at System.Net.HttpWebRequest.GetResponse()
at Cognos.Office.Tm1.Connections.Tm1Request.GetResponse()
— End of inner exception stack trace —
at Cognos.Office.Tm1.Connections.Tm1Connection.HandleWebException(Tm1WebException x, Uri path)
at Cognos.Office.Tm1.Connections.Tm1Connection.GetResponse(Tm1Request request)
at Cognos.Office.Tm1.Connections.Tm1Connection.SendRequest(Tm1Request webRequest, AcceptReturnEnum returns)
at Cognos.Office.Tm1.Connections.Tm1Connection.SendRequest(String method, String path, String postData, AcceptReturnEnum returns, Int32 timeout)
at Cognos.Office.Tm1.Connections.Tm1Connection.Get(String path, AcceptReturnEnum file, Int32 timeout)
at Cognos.Office.Tm1.Rest.Tm1RestCapabilities..ctor(Tm1Connection connection, String server, Int32 timeout)
at Cognos.Office.Tm1.Rest.Tm1RestConnection.RefreshCapabilities(String server, String path)
at Cognos.Office.Tm1.Rest.Tm1RestServer.UpdateCapabilities(String serverName)
at Cognos.Office.Tm1.Rest.Tm1RestDataSource.UpdateCapabilities(String serverName)
at Cognos.Office.Tm1.Tm1DataSource.On_LogOn(String server)
at Cognos.Office.Tm1.Tm1DataSource.Logon(LogonType logonType, DataSourcePropertiesCollection properties)
at Cognos.Office.Framework.Communications.DataSourceManager.LogOn(String dsType, String connectionString, String serverName, IDataSource& source)

Solution:
Check the values in PAW Admintool, special for the TM1 Application Server gateway URI. If that is wrong, like use HTTP instead of HTTPS when you have switch TM1WEB to use SSL, you will get above error inside PAX. To surf to PAW will still work fine.

When a user start Excel and PAX, the first connection is to the PAW server.
Then the PAW server will check the TM1S.CFG for value ClientCAMURI=http://caservername.domain.com/ibmcognos/bi/v1/disp
this URL will be used by PAX to log you in. After you login, the PMHUB.HTML file need to list the URL to PAW to allow you to get back.
You need to check the pmhub.html file in folder c:\Program Files\ibm\cognos\analytics\webcontent and c:\Program Files\ibm\cognos\analytics\webcontent\bi.
Open it in notepad++ and check that the PAW servers name or DNS alias at var pmhubURLs = [“https://tm1web.domain.com:9443” , “https://centospaw.lab.local”];
When you are back at PAW server in the communication route – pax will use the PAW ADMINTOOLS value in TM1 Application Server gateway URI before it show you are connected. If that value does not point to the CA11 server you get above error.

PAX is not using the PAW ADMINTOOLS value for IBM Cognos BI Gateway URI, instead you have the value  export TM1LoginServerURL=”https://tm1serverhost:12345″ in the paw.env file. The TM1 application that use the HTTPPortNumber = 12345, that value in its tm1s.cfg file is used.

If the value in PMHUB.HTML is wrong you get a error like “Cannot redirect back to planning analytics because the host URL (http://centospaw.lab.local) has not been whitelisted.”

Do not enter the port number for paw server in the PMHUB.HTML file.