Issues with package/v2 api and post-install script

P
PCallaw
Versatrans School Transportation Software - Tyler Technologies

Hi everyone,

I am currently on MobiControl version 2025.1.0.1007. I am strictly an Android Shop with devices ranging from OS 10-15. Device Agent version(s) 2024.1.4.1149 through 2026.0.0.1104. I am attemping to use a python script to make the POST packages/v2 api call. I have no issue with the creation and upload of the created package. I am running into an issue when trying to get the files in the package copied to the correct folder/folders on the Samsung device. I have tried using a post-install script (I referenced the Android Agent JavaScript documentation) but for whatever reason, I can not get the files on the device. 

I find it strange that this isn't working since the profile status states that the package was installed successfully. When I check the file structure, no files are copied into the specified directories.

I have even tried adding the PackageGroupFile and PackageFileFlags parameters in the script but still no luck. I was wondering if anyone else had any luck using this API call to build -> upload ->deploy successfully. The files in question are files that are generated in ESI. Building the same package in Pack Studio works without fail. I am wondering if I am missing something crucial. Any help would be greatly appriciated. Thank you. 

If any other information is needed, I would be happy to discuss.

2 days ago
SOTI MobiControl
ANSWERS
RS
Rafael Schäfer
yesterday (edited yesterday)

I don't think that there's a connection between API created profile/package incl. assignment and your issue.

So, fist try it the manual way if the files get copied to the correct location, i guess no.

If not, please provide the relevant scripts and where the package should copy the files to.

P
PCallaw
yesterday

Hi Rafael,

Thank you for your response. When I build in package studio I have no issues with getting the files where they need to be or selecting PackageFileFlags. In Package studio instead of adding files one by one, I upload a parent folder with multiple children folders and subfolders. The structure looks like:

ParentFolder/
├── Layers/
│   └── SomeClient.geodatabase
├── RoutingFolder/
│   ├── version.json
│   ├── SomeClient.geodatabase
│   └── routing.tn/
│       ├── HelperFiles.x
│       ├── HelperFiles.x
│       ├── HelperFiles.x
│       ├── HelperFiles.x
│       └── HelperFiles.x

Package Studio handles that just fine. However, when using the api, I follow the same steps and the files always seems to land outside the directory that I need the files copied to. We are a larger operation (more than 30,000 devices) and I am working on a way to automate package creation. Currently, when the package is created via the API they are packaged in a flat file format (when I try to use destination fields in the script, it always throws the error "A file name cannot contain any of the following characters: \\ / : * ? \" < > |").

As for the post install script here is the relevant snippit:

if (!src.exists || !src.isDirectory) {
       mobicontrol.log.error('Post-install: Source directory missing or not a directory: ' + srcPath);
       return;
   }

   if (!dest.exists && dest.mkdirs) {
       dest.mkdirs();
   }

   src.copyTo(dest);
   mobicontrol.log.info('Post-install: Copied directory: ' + srcPath + ' → ' + destPath);
}

try {
   copyDirSafe('/sdcard/MyApp/Layers', '/sdcard/MyApp/Layers');
   copyDirSafe('/sdcard/MyApp/Routing',  '/sdcard/MyApp/Routing');
   copyDirSafe('/sdcard/MyApp/Routing/routing.tn','/sdcard/MyApp/Routing/routing.tn');
} catch (e) {
   mobicontrol.log.error('Post-install: Error copying directories: ' + e);
}

We are very new to using post install scripts, we were able to manage for a while without but with a fleet so large, we are now modernizing how we operate. Any feed back is greatly appriciated.