<?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 Difficulty creating a view layer with REST API in ArcGIS REST APIs and Services Questions</title>
    <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/difficulty-creating-a-view-layer-with-rest-api/m-p/1277500#M4456</link>
    <description>&lt;P&gt;I'm attempting to programmatically create a view layer from an existing hosted feature layer in Portal running ArcGIS Enterprise 10.9.&amp;nbsp; I'm following &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/add-to-definition-feature-service-.htm" target="_self"&gt;this documentation.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case I don't need to join any tables.&amp;nbsp; I just need to apply a definition query to the source layer and have a new view layer created off of that.&lt;/P&gt;&lt;P&gt;I'm using Postman to send the request to /addToDefinition.&amp;nbsp; The token is being generated manually first, then added to the request as a parameter in the query string. The token is working.&lt;/P&gt;&lt;P&gt;My request URL for the POST is structured like this:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;https://&amp;lt;myDomain&amp;gt;/server/rest/admin/services/Hosted/Articles_Enriched/FeatureServer/addToDefinition?f=json&amp;amp;token=&amp;lt;myToken&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I'm passing in the addToDefinition parameter as url-encoded form data.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
    "layers": [
        {
            "name": "Test October 2022",
            "description": "",
            "adminLayerInfo": {
                "viewLayerDefinition": {
                    "table": {
                        "name": "target",
                        "sourceServiceName": "Articles_Enriched",
                        "sourceLayerId": 0,
                        "sourceLayerFields": [
                            {
                                "name": "article_title",
                                "source": "article_title"
                            },
                            {
                                "name": "article_text",
                                "source": "article_text"
                            }
                        ]
                    }
                }
            }
        }
    ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The POST is being received by the Portal's REST API, however it returns the following error message:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
    "error": {
        "code": 500,
        "message": "JSONObject[\"fields\"] not found.",
        "details": []
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I'm confused why it requires a "fields" parameter and if so, where I need to include it?&amp;nbsp; In the documentation I linked above a "fields" parameter is only shown in the example where a whole layer definition is added, whereas I'm following the other example where an Advanced View is added instead, and in those examples there's no "fields" parameter in the request JSON.&lt;/P&gt;&lt;P&gt;What am I getting wrong here?&lt;/P&gt;</description>
    <pubDate>Tue, 11 Apr 2023 19:25:12 GMT</pubDate>
    <dc:creator>LNX</dc:creator>
    <dc:date>2023-04-11T19:25:12Z</dc:date>
    <item>
      <title>Difficulty creating a view layer with REST API</title>
      <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/difficulty-creating-a-view-layer-with-rest-api/m-p/1277500#M4456</link>
      <description>&lt;P&gt;I'm attempting to programmatically create a view layer from an existing hosted feature layer in Portal running ArcGIS Enterprise 10.9.&amp;nbsp; I'm following &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/add-to-definition-feature-service-.htm" target="_self"&gt;this documentation.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case I don't need to join any tables.&amp;nbsp; I just need to apply a definition query to the source layer and have a new view layer created off of that.&lt;/P&gt;&lt;P&gt;I'm using Postman to send the request to /addToDefinition.&amp;nbsp; The token is being generated manually first, then added to the request as a parameter in the query string. The token is working.&lt;/P&gt;&lt;P&gt;My request URL for the POST is structured like this:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;https://&amp;lt;myDomain&amp;gt;/server/rest/admin/services/Hosted/Articles_Enriched/FeatureServer/addToDefinition?f=json&amp;amp;token=&amp;lt;myToken&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I'm passing in the addToDefinition parameter as url-encoded form data.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
    "layers": [
        {
            "name": "Test October 2022",
            "description": "",
            "adminLayerInfo": {
                "viewLayerDefinition": {
                    "table": {
                        "name": "target",
                        "sourceServiceName": "Articles_Enriched",
                        "sourceLayerId": 0,
                        "sourceLayerFields": [
                            {
                                "name": "article_title",
                                "source": "article_title"
                            },
                            {
                                "name": "article_text",
                                "source": "article_text"
                            }
                        ]
                    }
                }
            }
        }
    ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The POST is being received by the Portal's REST API, however it returns the following error message:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
    "error": {
        "code": 500,
        "message": "JSONObject[\"fields\"] not found.",
        "details": []
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I'm confused why it requires a "fields" parameter and if so, where I need to include it?&amp;nbsp; In the documentation I linked above a "fields" parameter is only shown in the example where a whole layer definition is added, whereas I'm following the other example where an Advanced View is added instead, and in those examples there's no "fields" parameter in the request JSON.&lt;/P&gt;&lt;P&gt;What am I getting wrong here?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 19:25:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/difficulty-creating-a-view-layer-with-rest-api/m-p/1277500#M4456</guid>
      <dc:creator>LNX</dc:creator>
      <dc:date>2023-04-11T19:25:12Z</dc:date>
    </item>
  </channel>
</rss>

