Correct body contents to create a mobileAppContentFile resource using the MsGraph REST API?

Viewed 60

I'm attempting to automate the update process for a Line-of-Business app in Intune.

Here is my current code:

function New-AppContentFile {
    param(
        [Parameter(Mandatory=$true)][System.String]$AppId,
        [Parameter(Mandatory=$true)][System.String]$AppContentId
    )
    $Uri = "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/8dda54ec-992a-478d-984a-260cd59c1c33/microsoft.graph.mobileLobApp/contentVersions/1/files"
    $script:ReqBody = [ordered]@{
        "@odata.type" = "#microsoft.graph.mobileAppContentFile"
        "name" = "google.msi"
        "size" = 4
        "sizeEncrypted" = 13
        "manifest" = $null
        "isCommitted" = $false
    } | ConvertTo-Json
    $header = @{
        Authorization = "Bearer $($token.AccessToken)"
        "content-length" = $ReqBody.Length
        "Accept" = "application/json"
    }
    Invoke-RestMethod -Uri $Uri -Headers $header -Method Post -Body $ReqBody -ContentType "application/json"
}

A few things that I've noticed when testing, the endpoint listed on the REST API is most likely incorrect. If I use a GET method on the following URL "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/8dda54ec-992a-478d-984a-260cd59c1c33/microsoft.graph.mobileLobApp/contentVersions/1/files" I will get a return. If I use the one mentioned in the REST API it returns a (400) Bad Request.

I've also tested numerous variations of the body to include all or some of the properties listed in the example request. Referencing the first of the two references listed below (Line 617), the body in theory should work as the following:

$ReqBody = [ordered]@{
     "@odata.type" = "#microsoft.graph.mobileAppContentFile"
     "name" = "google.msi"
     "size" = 4
     "sizeEncrypted" = 13
     "manifest" = $null
}

In the example request, the "azureStorageUri" property is specified. In my case I can't specify that, this POST should generate the azureStorageUri so that I can upload the file to that storage endpoint.

I've used these two sources as a reference: https://github.com/microsoftgraph/powershell-intune-samples/blob/master/LOB_Application/Application_LOB_Add.ps1 https://github.com/MSEndpointMgr/IntuneWin32App/blob/master/Public/Add-IntuneWin32App.ps1

And the following documentation from the Microsoft Graph REST API https://docs.microsoft.com/en-us/graph/api/intune-apps-mobileappcontentfile-create?view=graph-rest-beta I should also note that I have tested this with both the BETA and v1.0 of the MsGraph REST API.

0 Answers
Related