Bad Request 400 error while using Invoke Rest Post method of Graph API for uploading ipa file

I am trying to create an LOB [.ipa] app at Intune by calling Graph API through Powershell 2.
I am able to create the application at Intune but when I try to upload an ipa file, I receive:

Bad Request : 400 error.

Below is code snippet:

$tenantId = "XXXXXXXXXXXXXXXXXXX"
$clientId = "XXXXXXXXXXXXXXXXXXXX"
$clientSecret = "XXXXXXXXXXXXXXXXXXX"

$appPath = "./Path to .ipa file" ## Relative Path
$resource = "https://graph.microsoft.com/"
$authUrl = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"

$authBody = @{   
   client_id     = $clientId
   client_secret = $clientSecret
   scope         = "https://graph.microsoft.com/.default"
   grant_type    = "client_credentials"
}
$tkResponse = Invoke-RestMethod -Method Post -Uri $authUrl -ContentType "application/x-www-form-urlencoded" -Body $authBody
$origToken = $tkResponse.access_token

$initialheaders = @{
   Authorization = "Bearer $origToken"
   "Content-Type" = "application/json"
}
$body = @{
   "@odata.type" = "#microsoft.graph.iosLobApp"
   displayName = "Test"
   bundleId = "self.test.sample.app"
   buildNumber = "1.0.0"
   versionNumber = "1.0.0"
   description = "Test description"
   publisher = "Test Publisher"
   fileName = "Test.ipa"
   committedContentVersion = "1"
   informationUrl = "https://yourappwebsite.com"
   privacyInformationUrl = "https://yourappwebsite.com/privacy"
   minimumSupportedOperatingSystem = @{
       v8_0 = $true
   }
   applicableDeviceType = @{
       iPad = $true
       iPhoneAndIPod = $true
   }
}

$mobJson = $body | ConvertTo-Json -Depth 10
$graphApiUrl = "https://graph.microsoft.com/v1.0/deviceAppManagement/mobileApps"
try{
    $response = Invoke-RestMethod -Method Post -Uri $graphApiUrl -Headers $initialheaders -Body $mobJson -ErrorAction Stop -verbose
    $applicationId = $response.id
    } catch {
   Write-Host "$($_.Exception.Response.StatusCode)"
    }
`
        $fileUpUrl = "https://graph.microsoft.com/v1.0/deviceAppManagement/mobileApps/$applicationId/contentVersions/1/files"

        $fContent = [System.IO.File]::ReadAllBytes($appPath)
        $baseContent = [Convert]::ToBase64String($fContent)

        $contheaders = @{
        Authorization = "Bearer $origToken"
        "Content-Type" = "application/octet-stream"
        }
            $uploadBody = @{
                       "@odata.type" = "#microsoft.graph.mobileAppContentFile"
                        name = (Get-Item $appPath).Name
                        sizeInBytes = (Get-Item $appPath).Length
                        versionCode = "1.0.0"
                        versionName = "Version Name"
                        contentBytes = $baseContent
                       } | ConvertTo-Json
      
     try{
            **## ERROR COMES FROM BELOW INVOKE METHOD ##**
               * $uploadResp = Invoke-RestMethod -Uri $fileUpUrl -Method Post -Headers $contheaders -Body $uploadBody -Verbose*

        } catch {
                 $error = $_.Exception
    }

I also tried different ways like sending data as bytes, byte stream, sending body parameter as String but every time I receive “Bad Request : 400” error.

  1. Application get created perfectly fine
  2. Bad Request Error comes at second invoke rest method

Below is the error details

2024-12-23T18:16:34.9342611Z Error uploading IPA file: The remote server returned an error: (400) Bad Request.
2024-12-23T18:16:34.9370301Z System.Net.WebException: The remote server returned an error: (400) Bad Request.
2024-12-23T18:16:34.9372124Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
2024-12-23T18:16:34.9392176Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
2024-12-23T18:16:34.9404004Z Error11: System.Net.WebException: The remote server returned an error: (400) Bad Request.
2024-12-23T18:16:34.9404570Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
2024-12-23T18:16:34.9405060Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
2024-12-23T18:16:34.9406974Z Error11 Message: System.Net.WebException: The remote server returned an error: (400) Bad Request.
2024-12-23T18:16:34.9407299Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
2024-12-23T18:16:34.9408070Z    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord().Message

New contributor

Amit Saxena is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật