<?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 Re: Portal API content.add and .publish overwrite option not working in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/portal-api-content-add-and-publish-overwrite/m-p/1570539#M73403</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/852729"&gt;@chris_del101&lt;/a&gt;&amp;nbsp;try the following:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;item_properties = {
        'title': itemTitle,
        'type': 'File Geodatabase',
        'description': item.description,
        'accessInformation': item.accessInformation,
        'licenseInfo': item.licenseInfo,
        'overwrite': True
    }
root_folder = trg.content.folders.get()
fgd = root_folder.add(item_properties=fgd_properties, file=download_result).result()
targetService = fgd.publish(overwrite=True)&lt;/LI-CODE&gt;&lt;P&gt;Note:&amp;nbsp; The property &lt;STRONG&gt;`overwrite`&lt;/STRONG&gt; is deprecated and support will be removed two releases after 2.4.0 for the&amp;nbsp;&lt;STRONG&gt;item_properties&lt;/STRONG&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 20 Dec 2024 12:14:35 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2024-12-20T12:14:35Z</dc:date>
    <item>
      <title>Portal API content.add and .publish overwrite option not working</title>
      <link>https://community.esri.com/t5/python-questions/portal-api-content-add-and-publish-overwrite/m-p/1570012#M73390</link>
      <description>&lt;P&gt;I'm trying to add a feature layer to portal and I get the error, even though I include overwrite=True:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Exception: {'message': "Service name 'myService' already exists for '123abc'"}
Arguments: (Exception('Unable to Add messages Job Event\nUnable to Add messages Job Event\n(Error Code: 500)'),)&lt;/LI-CODE&gt;&lt;P&gt;I am including overwrite in the properties &lt;EM&gt;and&lt;/EM&gt; in the function itself, just in case at least one might work, yet it does nothing. It's specified&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.add" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;The content.add problem can be overcome by either deleting the item from portal, or adding a script to do it, but the .publish one is fatal. I DO NOT have any item with that name and this error is still occurring. How do I make the overwrite param work?&lt;/P&gt;&lt;LI-CODE lang="c"&gt; item_properties = {
        'title': itemTitle,
        'type': 'File Geodatabase',
        'description': item.description,
        'accessInformation': item.accessInformation,
        'licenseInfo': item.licenseInfo, 
        'overwrite': True
    }
fgd = trg.content.add(item_properties=item_properties, owner=username,
                                 data=download_result,  overwrite=True)
targetService = fgd.publish(overwrite=True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not looking for a better way to do this overall, but to solve this issue.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 22:24:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/portal-api-content-add-and-publish-overwrite/m-p/1570012#M73390</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2024-12-18T22:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Portal API content.add and .publish overwrite option not working</title>
      <link>https://community.esri.com/t5/python-questions/portal-api-content-add-and-publish-overwrite/m-p/1570176#M73396</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/852729"&gt;@chris_del101&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;What version of Enterprise and what version of the ArcGIS API for Python are you using?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2024 14:40:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/portal-api-content-add-and-publish-overwrite/m-p/1570176#M73396</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-12-19T14:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Portal API content.add and .publish overwrite option not working</title>
      <link>https://community.esri.com/t5/python-questions/portal-api-content-add-and-publish-overwrite/m-p/1570296#M73398</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;,&amp;nbsp;this taken from your migration tools for Pro. I am having trouble authenticating with those but the code looks useful.&lt;/P&gt;&lt;P&gt;Enterprise: 11.3.0&lt;/P&gt;&lt;P&gt;arcgis PY: 2.4.0&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2024 18:15:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/portal-api-content-add-and-publish-overwrite/m-p/1570296#M73398</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2024-12-19T18:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Portal API content.add and .publish overwrite option not working</title>
      <link>https://community.esri.com/t5/python-questions/portal-api-content-add-and-publish-overwrite/m-p/1570539#M73403</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/852729"&gt;@chris_del101&lt;/a&gt;&amp;nbsp;try the following:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;item_properties = {
        'title': itemTitle,
        'type': 'File Geodatabase',
        'description': item.description,
        'accessInformation': item.accessInformation,
        'licenseInfo': item.licenseInfo,
        'overwrite': True
    }
root_folder = trg.content.folders.get()
fgd = root_folder.add(item_properties=fgd_properties, file=download_result).result()
targetService = fgd.publish(overwrite=True)&lt;/LI-CODE&gt;&lt;P&gt;Note:&amp;nbsp; The property &lt;STRONG&gt;`overwrite`&lt;/STRONG&gt; is deprecated and support will be removed two releases after 2.4.0 for the&amp;nbsp;&lt;STRONG&gt;item_properties&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 12:14:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/portal-api-content-add-and-publish-overwrite/m-p/1570539#M73403</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-12-20T12:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Portal API content.add and .publish overwrite option not working</title>
      <link>https://community.esri.com/t5/python-questions/portal-api-content-add-and-publish-overwrite/m-p/1570697#M73411</link>
      <description>&lt;P&gt;I tried a layer and this seemed to solve that problem, but not for long. I hit some other errors now, and they are just cryptic af.&lt;/P&gt;&lt;P&gt;I was able to copy a layer once, but when I tried a different layer I got this with no additional information.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;result_item = item.export(itemTitle, 'File Geodatabase', wait=True)
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\me\code\source\repos\arcgis-cloner\src\service_app.py", line 66, in copy_layer_to_folder
    result_item = item.export(itemTitle, 'File Geodatabase', wait=True)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\__init__.py", line 14038, in export      
    raise Exception("Could not export item: %s" % self.itemid)
Exception: Could not export item: 4ba901c8e2f248c6882a5b11552af741
Error exporting item &lt;/LI-CODE&gt;&lt;P&gt;I went back to the first item and tried it again I get this. It makes a new folder first, so it's not an issue of existing items existing&lt;/P&gt;&lt;LI-CODE lang="python"&gt;targetService = fgd.publish(overwrite=True)
--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\me\code\source\repos\arcgis-cloner\src\service_app.py", line 105, in copy_layer_to_folder
    targetService = fgd.publish(overwrite=True)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\__init__.py", line 16273, in publish     
    return job.result()
           ^^^^^^^^^^^^
  File "C:\Python312\Lib\concurrent\futures\_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "C:\Python312\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\__init__.py", line 16550, in _publish    
    ret = self._portal.publish_item(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\_impl\_portalpy.py", line 509, in publish_item
    resp = self.con.post(path, postdata, files)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1504, in post
    return self._handle_response(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 979, in _handle_response
    self._handle_json_error(data["error"], errorcode)
  File "C:\Users\me\.virtualenvs\arcgis-cloner-pO5T1BLr\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1002, in _handle_json_error
    raise Exception(errormessage)
Exception: Unable to Add messages Job Event
Unable to Add messages Job Event
(Error Code: 500)&lt;/LI-CODE&gt;&lt;P&gt;Code I'm using&lt;/P&gt;&lt;LI-CODE lang="python"&gt;folder_name = f"_testing_{item_properties['title']}_{str(uuid.uuid4())[:4]}"
 # create new folder to hold
new_folder = trg.content.folders.create(folder_name)
fgd = new_folder.add(item_properties=item_properties, file=download_result).result()
targetService = fgd.publish(overwrite=True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 18:45:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/portal-api-content-add-and-publish-overwrite/m-p/1570697#M73411</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2024-12-20T18:45:22Z</dc:date>
    </item>
  </channel>
</rss>

