Issues with the /packages/v2 API when uploading APKs

EC
Enric Correa Yusa
mercadona001

Hi all,

We are trying to upload an APK to a SOTI MobiControl package, but we are unable to do so.

We are using the following script:

#######

#!/bin/bash

SERVER_URL="https://<SERVER_HERE>.mobicontrol.cloud/MobiControl/api/packages/v2"
API_TOKEN="TOKEN_HERE"

PACKAGE_NAME="0_APK_Package"
PACKAGE_VERSION="1.0.0"
PACKAGE_PLATFORM="AndroidPlus"

APK_FILE="App1.apk"
BOUNDARY="test"

# Check if the APK file exists
if [ ! -f "$APK_FILE" ]; then
echo "ERROR: File $APK_FILE not found in the current directory."
exit 1
fi

echo "Uploading package to SOTI MobiControl..."

# Build the multipart body and pass it directly to curl
(
# 1. Part: JSON metadata
printf -- "--%s\r\n" "$BOUNDARY"
printf "Content-Type: application/vnd.soti.mobicontrol.packagearchive.metadata+json\r\n\r\n"
 
cat <<END_JSON
{
"PackageName": "$PACKAGE_NAME",
"PackageVersion": "$PACKAGE_VERSION",
"PackagePlatform": "$PACKAGE_PLATFORM",
"PackageFiles": [
{
"FileName": "$APK_FILE",
"FileSourceType": "Binary",
"Destination": "%sdcard%",
"FileFlags": "DoNotUninstall, AllowUserUninstall"
}
]
}
END_JSON

# 2. Part: APK file (binary)
printf -- "\r\n--%s\r\n" "$BOUNDARY"
printf "Content-Type: application/octet-stream\r\n"
printf "Content-Transfer-Encoding: binary\r\n"
printf 'Content-Disposition: attachment; filename="%s"\r\n\r\n' "$APK_FILE"
 
# Inject the actual binary content of the APK
cat "$APK_FILE"
 
# 3. Close the multipart
printf -- "\r\n--%s--\r\n" "$BOUNDARY"

) | curl -v -X POST "$SERVER_URL" \
-H "Accept: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: multipart/related; boundary=$BOUNDARY" \
--data-binary @-

echo
echo "Process completed."

#######

When we execute it, the request returns HTTP/2 200. However, when we check the package in MobiControl, the Files tab does not show the uploaded APK:

Do you have any idea why this might be happening?

Thanks in advance.

15 days ago
SOTI MobiControl
ANSWERS
RS
Robert Schäfer
15 days ago

Im only familiar with the /packages api, not v2. However the structure of what you pasted above looks okay.

It could be an issue with the structure as its incredibly finicky when it comes to spaces, however if its returning 200 have you checked whether the user you are using in your api request has the relevant package permissions? (usually expect a 403 but it depends)

A
AMMOD@SOTI
2 days ago

Hi @Enric Correa Yusa,

Thankyou for posting on soti pulse.

Were you able to resolve the issue?

If you are still facing the same problem, kindly create a support ticket so we can assist you further and investigate this in detail.

EC

Hi @AMMOD@SOTI,

We are still experiencing the issue. We already have an open case; the case number is C01656861.

Regards.