Error on PS script that installs app to Hololens using device portal APIs
Asked Answered
A

1

1

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'```
Amphibrach answered 29/3, 2019 at 19:50 Comment(2)
Have you considered removing the ContentType?Thrust
Yes, and it throws Invoke-RestMethod : {"Reason" : "Missing .msix (or .emsix) or .appx (or .eappx) or .appinstaller file in uploaded files"}Amphibrach
A
0

The answer from jklemmack on this post helped solve this problem. Also I should be using ISO-8859-1 encoding instead of UTF-8 to make the appxbundle read successful.

powershell invoke-restmethod multipart/form-data

Solved !

Amphibrach answered 1/4, 2019 at 8:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.