Update MMPK on Portal through Python API

478
6
05-17-2019 08:44 AM
Highlighted
Occasional Contributor III

Is there a way to update an already uploaded MMPK in Portal through the Python API? In Portal, I have the option to update an already existing MMPK, but I would like to automate that in some way, and I am assuming the Python API would be the best option (but am open to any way to automate that). I've looked through the documentation and I haven't been able to find anything yet that can do this.

6 Replies
Highlighted
New Contributor III

I had this same issue and finally found what I needed in the API documentation. Here are the basics:

from arcgis.gis import GIS

gis = GIS(your_portal_url, your_username, your_password)

mmpk = gis.content.search("title:The Title of Your MMPK In Your Portal")
mmpk[0].update(data=r"c:\Your_Directory_Path\Your_Map_Package.mmpk") 

Note that gis.content.search returns a list, so you'll want to make sure your search only returns one item.

The documentation says that item_properties is a required argument for Item.update, but I found that it works with only the data argument, like I have above.

Ref: arcgis.gis module — arcgis 1.6.2 documentation 

Edited to add:

I update the .mmpk itself by using arcpy.management.CreateMobileMapPackage then get it into Portal using the above process.

Create Mobile Map Package—Data Management toolbox | ArcGIS Desktop 

Highlighted
New Contributor II

I tried your mmpk[0].update(data=r"c:\Your_Directory_Path\Your_Map_Package.mmpk") script for standalone ArcGIS Online MMPK (we don't have Portal) from Jupyter Notebook, and I received the following error message:

So, maybe I do need to specify item properties?

Reply
0 Kudos
Highlighted
New Contributor III

Add the data= key in front of the path to your MMPK. Data is the second argument for this function, so you have to specify that the path string belongs to the data argument otherwise it thinks you're giving it the first argument, which is item_property.

So in this case, it thinks the path string you've given is an item_property... and since it's a string instead of a dictionary, you're getting an error since 'pop' can't be used on a string.

(All that said, I'll freely admit that item_property might actually be required for ArcGIS Online, since I've only done it without in Portal... but that's not what's happening yet)

Reply
0 Kudos
Highlighted
New Contributor II

Hi Josh,

Many thanks. I made your suggested addition in the script, and it ran without error. It appears that the MMPK was overwritten on ArcGIS Online, but I have not yet opened it up. The good news is that there were no error messages.

Thanks again!

Reply
0 Kudos
Highlighted
New Contributor II

Hi Josh,

What is the syntax for setting the input map to create a mobile map package?

For example using the python console in pro mine would be as follows:

arcpy.management.CreateMobileMapPackage("Map Title", r"J:\path\PackageName.mmpk", None, None, "DEFAULT", "SELECT", "Title", "Summary", '<DIV STYLE="text-align:Left;font-size:12pt"><P><SPAN>Sewer Network</SPAN></P></DIV>', "Sewers", None, None, "STANDARD")

The code sample in the help article you provided for a stand alone script is as follows:

arcpy.management.CreateMobileMapPackage( [r"C:\data\Basemap1.mapx", r"C:\data\Map1.mapx"], outputfile, None, r"\\share\layers\AreaOfInterest.lyrx", "DEFAULT", "CLIP", "Title", "Summary", "description", "Tag", "Credits", "Use", "STANDARD", "ENABLE_MAP_EXPIRATION", "DONOT_ALLOW_TO_OPEN", expiration_date, "This map is expired. Contact the map publisher for an updated map.")

but the input is a map file, how do i set the input to be a map within a project? Or do i have to save the map as a map file first?

Any help would be much appreciated.

Thanks

Reply
0 Kudos
Highlighted
New Contributor II

Hi Josh,

Is there a limit to the file size that can be used following this process?

I have a mobile map package approx 1gb which times out following your script. I had tested the process with a smaller mobile map package of a sample area 30mb which worked perfectly.

Any help greatly appreacted.

Thanks!!!

Reply
0 Kudos