I'm trying to develop a PS script that install app package to Hololens via the device portal APIs. Looking for some troubleshooting tips on the 400 BAD REQUEST response.
Here are the references I used : https://learn.microsoft.com/en-us/windows/mixed-reality/device-portal-api-reference
END POINT /api/app/packagemanager/package (POST)
$user = 'snarain'
$pass = 'snarain'
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
$FilePath = 'C:\Users\snarain\Downloads\My HololensApp.appxbundle'
Invoke-RestMethod -Uri 'http://127.0.0.1:10080/api/app/packagemanager/package?package=My%20HololensApp.appxbundle' -Headers $Headers -Method Post -InFile $FilePath -ContentType 'multipart/form-data'
The output is Invoke-RestMethod : The remote server returned an error: (400) Bad Request
. However, I am able to use Postman to hit the end point and upload the app successfully. I saved the request from POSTMAN to its curl equivalent here it is, for the experts to quickly debug it.
--url 'http://127.0.0.1:10080/api/app/packagemanager/package?package=My%20HololensApp.appxbundle' \
--header 'Authorization: Basic c25hcmFpbjpzbmFyYWlu' \
--header 'Postman-Token: c6613653-3ff0-43c1-896c-63d62b125277' \
--header 'cache-control: no-cache' \
--header 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
--form '=@C:\Users\snarain\Downloads\My HololensApp.appxbundle'```
ContentType
? – ThrustInvoke-RestMethod : {"Reason" : "Missing .msix (or .emsix) or .appx (or .eappx) or .appinstaller file in uploaded files"}
– Amphibrach