microsoft / powerplatform-vscode

The Power Platform VSCode extension makes it easy to manage Power Platform environments and allows the developer to create, build and deploy Power Platform solutions, packages and portals.
MIT License
211 stars 38 forks source link

`pac admin reset` crashes if currency specified #191

Closed filcole closed 2 years ago

filcole commented 2 years ago

When the --currency property is specified for the pac admin reset command an error is output, e.g.

PS C:\Dev\XXX> pac admin reset --environment https://myenvurl.crm11.dynamics.com  --currency GBP
Resetting environment...
Microsoft PowerPlatform CLI
Version: 1.14.2+g7205df7

Error: The request failed with error: '{"errors":{"code":"BadRequest","message":"The request does not match the contract","details":[{"code":"BadRequest","message":"The Name field is required.","target":"UnknownTarget"},{"code":"BadRequest","message":"The Symbol field is required.","target":"UnknownTarget"}]}}'. The tracking Id is '51165ec5-08c4-40d8-9a12-ea9f9db9ac83'.

it also occurs when the default USD currency is used

PS C:\Dev\XXX> pac admin reset --environment https://myenvurl.crm11.dynamics.com  --currency USD
Resetting environment...
Microsoft PowerPlatform CLI
Version: 1.14.2+g7205df7

Error: The request failed with error: '{"errors":{"code":"BadRequest","message":"The request does not match the contract","details":[{"code":"BadRequest","message":"The Name field is required.","target":"UnknownTarget"},{"code":"BadRequest","message":"The Symbol field is required.","target":"UnknownTarget"}]}}'. The tracking Id is 'e2017942-c147-49c6-8655-f24bfb3d2b7e'.

Resetting the environment without the --currency flag works, but the currency in the reset environment is always USD.


PS C:\Dev\XXX> pac admin reset --environment https://myenvurl.crm11.dynamics.com                
Resetting environment...
Polling to check the status of your Environment... Execution time: 00:00:05.2646130
Polling to check the status of your Environment... Execution time: 00:00:10.5002040
[... snip ...]
Polling to check the status of your Environment... Execution time: 00:05:19.4620225
Polling to check the status of your Environment... Execution time: 00:05:24.7533558
Polling to check the status of your Environment... Execution time: 00:05:30.2747509
Polling to check the status of your Environment... Execution time: 00:05:35.8037650
Polling completed with status code : OK

 Environment Url                                    Environment Id                           Friendly Name                  Domain Name                    Organization Id                          Version

 https://myenvurl.crm11.dynamics.com/            046d00c3-XXXX-XXXX-XXXX-f0f4a56dfb08     My Env Name                   myenvurl                    9ee5ccab-XXXX-XXXX-XXXX-5281574eabb9     9.2.22034.00148
filcole commented 2 years ago

It looks like there's maybe a requirement to supply the Code, Name and Symbol parameters, as per the PowerShell documents, but it's unclear what syntax is required when used with pac, or if it's a bug with pac.

A fiddler trace of pac shows only the code parameter being sent

POST https://api.bap.microsoft.com//providers/Microsoft.BusinessAppPlatform/environments/046d00c3-XXXX-XXXX-XXXX-f0f4a56dfb08/reset?api-version=2020-08-01 HTTP/1.1
Authorization: Bearer XXXXX
User-Agent: pac/1.0 (win; Microsoft PowerPlatform CLI; 1.14.2+g7205df7)
Content-Type: application/json; charset=utf-8
Host: api.bap.microsoft.com
Content-Length: 130
Expect: 100-continue

{"BaseLanguageCode":1033,"Currency":{"Code":"GBP"},"DomainName":null,"FriendlyName":null,"Purpose":null,"Templates":[]}

Using Reset-PowerAppEnvironment via Powershell https://docs.microsoft.com/en-us/powershell/module/microsoft.powerapps.administration.powershell/reset-powerappenvironment?view=pa-ps-latest is sending the currency as follows (with Code, Name & Symbol).

POST https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/environments/046d00c3-XXXX-XXXX-XXXX-XXXXXXXXXXXX/reset?api-version=2019-05-01 HTTP/1.1
Authorization: Bearer [...snip...]
User-Agent: PowerShell cmdlets 1.0
Content-Type: application/json; charset=utf-8
Host: api.bap.microsoft.com
Content-Length: 437

{
    "FriendlyName":  "My Friendly Name",
    "DomainName":  "mydomainname",
    "Purpose":  "My purpopse",
    "BaseLanguageCode":  "1033",
    "Currency":  {
                     "Code":  "GBP",
                     "Name":  "GBP",
                     "Symbol":  "£"
                 },
    "Templates":  []
}
davidjenni commented 2 years ago

@filcole thanks for both reporting and analyzing! We're figuring out if there's an API change that has caused this to regress :-( ? There's a similar error when specifying --language

Our internal tracking error: AB#2691378

tehcrashxor commented 2 years ago

The fix has been rolled out with PAC v1.16.6 / powerplatform-vscode v1.0.16 in #216