<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ImportDocument for Portal Item (.mapx) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/importdocument-for-portal-item-mapx/m-p/1501755#M71001</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using a python script in which I imported .mapx-files succesfully from a server.&lt;/P&gt;&lt;P&gt;Now I need the same script to import the .mapx from our portal, but it seems I get the URL wrong, since the tool throws an OS Error.&lt;/P&gt;&lt;P&gt;The first 3 lines show the working part of the script, setting the document path to NK.mapx on our server.&lt;/P&gt;&lt;P&gt;The last 2 lines show two different document paths to the portal item I tried. The first one is the same which is used when importing the .mapx-file in ArcGIS Pro via the menu.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HF_LBD_0-1720166529197.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/108876i080BB78C90C4E587/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HF_LBD_0-1720166529197.png" alt="HF_LBD_0-1720166529197.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HF_LBD_1-1720166963403.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/108877i57454D4ADEF6F9D4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HF_LBD_1-1720166963403.png" alt="HF_LBD_1-1720166963403.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks for any ideas.&lt;/P&gt;&lt;P&gt;Greetings from Germany&lt;/P&gt;&lt;P&gt;Holger&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jul 2024 08:19:20 GMT</pubDate>
    <dc:creator>HF_LBD</dc:creator>
    <dc:date>2024-07-05T08:19:20Z</dc:date>
    <item>
      <title>ImportDocument for Portal Item (.mapx)</title>
      <link>https://community.esri.com/t5/python-questions/importdocument-for-portal-item-mapx/m-p/1501755#M71001</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using a python script in which I imported .mapx-files succesfully from a server.&lt;/P&gt;&lt;P&gt;Now I need the same script to import the .mapx from our portal, but it seems I get the URL wrong, since the tool throws an OS Error.&lt;/P&gt;&lt;P&gt;The first 3 lines show the working part of the script, setting the document path to NK.mapx on our server.&lt;/P&gt;&lt;P&gt;The last 2 lines show two different document paths to the portal item I tried. The first one is the same which is used when importing the .mapx-file in ArcGIS Pro via the menu.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HF_LBD_0-1720166529197.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/108876i080BB78C90C4E587/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HF_LBD_0-1720166529197.png" alt="HF_LBD_0-1720166529197.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HF_LBD_1-1720166963403.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/108877i57454D4ADEF6F9D4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HF_LBD_1-1720166963403.png" alt="HF_LBD_1-1720166963403.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks for any ideas.&lt;/P&gt;&lt;P&gt;Greetings from Germany&lt;/P&gt;&lt;P&gt;Holger&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2024 08:19:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/importdocument-for-portal-item-mapx/m-p/1501755#M71001</guid>
      <dc:creator>HF_LBD</dc:creator>
      <dc:date>2024-07-05T08:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: ImportDocument for Portal Item (.mapx)</title>
      <link>https://community.esri.com/t5/python-questions/importdocument-for-portal-item-mapx/m-p/1502408#M71007</link>
      <description>&lt;P&gt;It could be that your portal requires authentication, using the GIS module to interact with portal items might be necessary in your case. It's not totally clear to me if the importDocument method for .mp allows network paths. You could try signing in and downloading the map to a tempfolder then adding it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import tempfile

from arcgis.gis import GIS, ContentManager, Item

def connect_to_portal(url: str = None, username: str = None, password: str = None) -&amp;gt; GIS:
    return GIS(url, username, password)

def get_manager(portal: GIS) -&amp;gt; ContentManager:
    return portal.content

def get_item_by_id(manager: ContentManager, item_id: str) -&amp;gt; Item:
    return manager.get(item_id)

def download_item(item, output_folder: os.PathLike) -&amp;gt; os.PathLike:
    item.download(save_path=output_folder, file_name=item.name)
    return os.path.join(output_folder, item.name)
    
if __name__ == "__main__":
    aprx = arcpy.mp.ArcGISProject("CURRENT")

    tempfolder = tempfile.gettempdir()
    # Connect to the portal
    portal = connect_to_portal("https://www.arcgis.com", "username", "password")
    # Get portal content manager
    manager = get_manager(portal)
    # OPTIONAL use search to find the item
    # items = manager.search("title:Item Title")
    # Get item by id
    item = get_item_by_id(manager, "&amp;lt;item_id&amp;gt;")
    # download the item to a temporary folder
    map_item = download_item(item, tempfolder)
    # import the item into the current project
    aprx.importDocument(map_item)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html" target="_self"&gt;Link to the full documentation for the GIS module&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 12:47:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/importdocument-for-portal-item-mapx/m-p/1502408#M71007</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-07-15T12:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: ImportDocument for Portal Item (.mapx)</title>
      <link>https://community.esri.com/t5/python-questions/importdocument-for-portal-item-mapx/m-p/1505266#M71064</link>
      <description>&lt;P&gt;Hi Hayden,&lt;/P&gt;&lt;P&gt;Thanks a lot. This works well.&lt;/P&gt;&lt;P&gt;Only correction: it has to be file_name in line 17.&lt;/P&gt;&lt;P&gt;Greetings&lt;/P&gt;&lt;P&gt;Holger&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 07:22:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/importdocument-for-portal-item-mapx/m-p/1505266#M71064</guid>
      <dc:creator>HF_LBD</dc:creator>
      <dc:date>2024-07-15T07:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: ImportDocument for Portal Item (.mapx)</title>
      <link>https://community.esri.com/t5/python-questions/importdocument-for-portal-item-mapx/m-p/1505328#M71069</link>
      <description>&lt;P&gt;Good catch, made the change so it doesn't cause issues for anyone else that might be reading this in the future&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 12:48:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/importdocument-for-portal-item-mapx/m-p/1505328#M71069</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-07-15T12:48:23Z</dc:date>
    </item>
  </channel>
</rss>

