Upload package with REST-API fails

Upload package with REST-API fails

Hi

I'm trying to upload a package by using the MobiControl REST-API. Im using MobiControl Version 14.4.2.1307

The API call is described in https://serverurl/MobiControl/api/docs/index#!/Packages/Packages_CreateNewPackage

Here's the request and MobiControls answer (Stirngs in Italic are replaced for privacy reasons):

2019-09-27 15:37:02,937 9768 DEBUG < POST /MobiControl/api/packages HTTP/1.1
< Host: mobicontrolhostname.com
< User-Agent: python-requests/2.22.0
< Accept-Encoding: gzip, deflate
< Accept: */*
< Connection: keep-alive
< Authorization: Bearer here_comes_the_bearer_token
< Content-Type: multipart/related; boundary="===============0510829778131399783=="
< MIME-Version: 1.0
< Content-Length: 1231
<
< --===============0510829778131399783==
Content-Type: application/vnd.soti.mobicontrol.package.metadata+json
MIME-Version: 1.0

{ "deviceFamily" : "AndroidPlus" }
--===============0510829778131399783==
Content-Type: application/vnd.soti.mobicontrol.package
MIME-Version: 1.0
Content-Transfer-Encoding: base64

AQMDKgThisIsShortenedF9Q==

--===============0510829778131399783==--

> HTTP/1.1 400 Bad Request
> Content-Length: 186
> Content-Type: application/json; charset=utf-8
> Server: Microsoft-HTTPAPI/2.0
> Date: Fri, 27 Sep 2019 13:37:54 GMT
>
{
  "$type": "ErrorDetails",
  "ErrorCode": 0,
  "Message": "Unexpected end of MIME multipart stream. MIME multipart message is not complete.",
  "Data": null,
  "HelpLink": null
}

I have shortened the package in the printout above and replaced the bearer token and hostname. The rest is untouched.

I believe this should be a valid request or I am wrong?

I also tried the example request in the API documentation but got the same answers. Any ideas?

  • 27 September 2019
  • SOTI MobiControl
  • 3 Answers
  • 0 Upvote
  • 3 Followers
  • 602 Views
    • 3 Answers
    • 0 Upvote
    • 3 Followers

3 Answers

Order By:   Standard | Newest | Votes
TJ Bukoski | posted this 01 October 2019

Hi Thomas,

 

The error "Unexpected end of MIME multipart stream. MIME multipart message is not complete." usually means your content length value does not accurately reflect the length of your Body. 

There are also a few things in your body I don't think you need. I have a Powershell Script that does a similar thing. Here is an excerpt:


 $headers = @{}
$headers["Authorization"] = "Bearer " + $script:AccessToken

# Grab the Device Family from parameters and put it in a Hash table
$DevFamily = @{}
$DevFamily["deviceFamily"] = $DeviceFamily

# I need the filename
$FileName = Split-Path -leaf $FilePath

# Grab the file and encode it to base64
$Base64EncodedFile = [Convert]::ToBase64String([IO.File]::ReadAllBytes($FilePath))

# Create the Body... I need a better way to do this. I'm appending variables to the body as needed

$Body = @'
--mobicontrol_boundary
Content-Type: application/vnd.soti.mobicontrol.package.metadata+json


'@

$Body = $Body + ($DevFamily | ConvertTo-Json)

$Body = $Body + @'

--mobicontrol_boundary
Content-Type: application/vnd.soti.mobicontrol.package
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=
'@

$Body = $Body + '"' + $FileName + '"'

$Body = $Body + "`r`n`r`n"

$Body = $Body + $Base64EncodedFile

$Body = $Body + @'

--mobicontrol_boundary--
'@

try
{
$result = Invoke-restmethod -Uri "https://$script:ServerFQN/mobicontrol/api/packages" -ContentType "multipart/related; boundary=mobicontrol_boundary" -Method POST -Headers $headers -body $body
}
catch
{
$_.Exception.Message
}

I've found that spacing matters in the body as well. Not having newline characters in the right place in your body will result in an invalid request error.

  • 1
  • 0
AKMOD@SOTI | posted this 04 October 2019

Hi Thomas 

 

Thanks, T J for sharing the Power shell excerpt.

Can you please share if the Powershell Script excerpt shared by T J worked for you?

 

Regards

Technical Support | SOTI Inc. |1.905.624.9828 | support@soti.net | www.soti.net |

  • 0
  • 0
Thomas K | posted this 06 October 2019

Hi all

@TJ: Thank you very much for sharing your Powershell Script.

I could not do any additional testing this week and I am on holidays next week. I'll give it another try when I am back and will report my results here.

Best regards and thank you all

Thomas

  • 0
  • 0

Give us your feedback
Give us your feedback
Feedback