<?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 Unable to add_to_definition() since 2.4.0. - Invalid URL in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1602737#M11297</link>
    <description>&lt;P&gt;Update arcgis python API to 2.4.0 last week, now I can't seem to make FeatureLayerCollection.manager.add_to_definition() work.&lt;/P&gt;&lt;P&gt;I have this script which ran perfectly fine before where I added a layer or table to a FeatureLayerCollection: flc.manager.add_to_definition(dict). Where dict contains info about the layer in question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I get this error:&lt;/P&gt;&lt;P&gt;Exception: Invalid URL&lt;BR /&gt;Invalid URL&lt;BR /&gt;(Error Code: 400)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's wrong here?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Fri, 04 Apr 2025 13:16:21 GMT</pubDate>
    <dc:creator>mikaël</dc:creator>
    <dc:date>2025-04-04T13:16:21Z</dc:date>
    <item>
      <title>Unable to add_to_definition() since 2.4.0. - Invalid URL</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1602737#M11297</link>
      <description>&lt;P&gt;Update arcgis python API to 2.4.0 last week, now I can't seem to make FeatureLayerCollection.manager.add_to_definition() work.&lt;/P&gt;&lt;P&gt;I have this script which ran perfectly fine before where I added a layer or table to a FeatureLayerCollection: flc.manager.add_to_definition(dict). Where dict contains info about the layer in question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I get this error:&lt;/P&gt;&lt;P&gt;Exception: Invalid URL&lt;BR /&gt;Invalid URL&lt;BR /&gt;(Error Code: 400)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's wrong here?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 13:16:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1602737#M11297</guid>
      <dc:creator>mikaël</dc:creator>
      <dc:date>2025-04-04T13:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to add_to_definition() since 2.4.0. - Invalid URL</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1602739#M11298</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/606364"&gt;@mikaël&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Are you able to share more of your code please?&lt;/P&gt;&lt;P&gt;How are you accessing ArcGIS Online (or Portal) and how are you creating the FeatureLayerCollection object.&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 13:19:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1602739#M11298</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-04-04T13:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to add_to_definition() since 2.4.0. - Invalid URL</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1602754#M11299</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;Here goes (to create a view):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.features import FeatureLayerCollection
from arcgis.gis import GIS
gis = GIS("URL", username, password)
service = gis.content.get("itemid")
flc = FeatureLayerCollection.fromitem(service)

dict = {
    "layers": [
        {
            "adminLayerInfo": {
                "viewLayerDefinition": {
                    "sourceServiceName": "nameOfSourceService"
                    "sourceLayerId": 0 # source service layer id
                    "sourceLayerFields": "*"
                }
            },
            "id": 0,
            "name": "name"
            "description": "desc"
        }
    ]
}

result = flc.manager.add_to_definition(dict)

# Exception: Invalid URL
# Invalid URL
# (Error Code: 400)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 14:00:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1602754#M11299</guid>
      <dc:creator>mikaël</dc:creator>
      <dc:date>2025-04-04T14:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to add_to_definition() since 2.4.0. - Invalid URL</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1602858#M11300</link>
      <description>&lt;P&gt;You might want to post details here as an issue since it hasn't been reported and more information will be needed to test to see if it can be replicated&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/arcgis-python-api" target="_blank"&gt;Esri/arcgis-python-api: Documentation and samples for ArcGIS API for Python&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 16:28:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1602858#M11300</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-04-04T16:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to add_to_definition() since 2.4.0. - Invalid URL</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1603034#M11303</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/606364"&gt;@mikaël&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Are you trying to create a view? You will need to use the FeatureLayerCollection &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.features.managers.html#arcgis.features.managers.FeatureLayerCollectionManager.create_view" target="_blank" rel="noopener"&gt;create_view()&lt;/A&gt; method.&lt;/P&gt;&lt;P&gt;You can do some upfront settings with the create_view() method, and you can manipulate the JSON of the view service with the FeatureLayerCollection add_to, update, and delete_from_definition().&lt;/P&gt;&lt;P&gt;You can also use the &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.ViewManager" target="_blank" rel="noopener"&gt;ViewManager&lt;/A&gt; for an Item object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Apr 2025 09:37:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1603034#M11303</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-04-05T09:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to add_to_definition() since 2.4.0. - Invalid URL</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1603302#M11304</link>
      <description>&lt;P&gt;Right. I know I can use create_view() but I prefered using creating an empty service (create_service()) with the correct parameters/definitions and then adding the layers/tables and setting the view.&lt;/P&gt;&lt;P&gt;I'll try create_view() again to see if the problem occurs that way also.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Apr 2025 15:22:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1603302#M11304</guid>
      <dc:creator>mikaël</dc:creator>
      <dc:date>2025-04-07T15:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to add_to_definition() since 2.4.0. - Invalid URL</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1603371#M11306</link>
      <description>&lt;P&gt;Well.... Found the problem, which was my fault &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;To populate the "sourceServiceName" in the "viewLayerDefinition", I was using the variable from the service Item service.title or service.name. But I didn't realize that this could be different from the FeatureLayerCollection name, which I can get from flc.manager.properties.adminServiceInfo.name.&lt;/P&gt;&lt;P&gt;The difference in my case was that there is no underscore in the service name and there is one in the flc name (for example: "this name" vs "this_name"). So the API couldn't find the sourceServiceName when trying to add the view.&lt;/P&gt;&lt;P&gt;To find my error, I created a view from the AGOL interface and tracked network calls in developer mode and compared the requests and responses to what I was sending.&lt;/P&gt;&lt;P&gt;Thanks for your help everybody! Stupid mistake &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Apr 2025 18:26:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-add-to-definition-since-2-4-0-invalid/m-p/1603371#M11306</guid>
      <dc:creator>mikaël</dc:creator>
      <dc:date>2025-04-07T18:26:45Z</dc:date>
    </item>
  </channel>
</rss>

