Select to view content in your preferred language

how to create advanced view with arcgis api for python

Jump to solution
06-06-2024 08:24 AM
New Contributor II

Hello everyone,

I've had a problem for several days that I can't solve. I want to create an advanced view from 2 hosted views.
Let me explain:
I have a hosted feature layer for which I'm creating a view (I'm only interested in certain fields). No problem to create this view.
I have a hosted table for which I'm creating a view (I'm only interested in certain fields). No problem to create this view.
 For each of these views I use the manager.create_view method

My problem is that I can't create a new view from the 2 previous views, whereas I can do it perfectly well from the graphical interface of map viewer classic.

The join_features method doesn't seem to be what I'm looking for because it creates a new independent hosted feature layer (which I don't want).

So I used the method gis.content.create_service(name='xxx', service_type='featureService', is_view=True)

It seems to work, but I still have to update the layer definition using the fl.manager.update_definition(definition) method to modify the [layers] tag in the properties, and that's where I run into my problem, because I don't know how to make sure my json is properly parameterized.

If you have an idea, I'd love to hear from you.

many thanks in advance.

Translated with (free version)

0 Kudos
1 Solution

Accepted Solutions
Esri Regular Contributor
0 Kudos
3 Replies
Esri Regular Contributor
0 Kudos
New Contributor II

unfortunately I get the following error message when calling the add_to_definition method.

Exception                                 Traceback (most recent call last)
/tmp/ipykernel_51/ in <cell line: 120>()
    118 }
--> 120 view_flc.manager.add_to_definition(definition_to_add)

/opt/conda/lib/python3.9/site-packages/arcgis/features/ in add_to_definition(self, json_dict, future)
   2546         }
   2547         adddefn_url = self._url + "/addToDefinition"
-> 2548         res =, params)
   2549         if future and "statusURL" in res:
   2550             executor = _cf.ThreadPoolExecutor(1)

/opt/conda/lib/python3.9/site-packages/arcgis/gis/_impl/_con/ in post(self, path, params, files, **kwargs)
   1522         if return_raw_response:
   1523             return resp
-> 1524         return self._handle_response(   1525             resp=resp,
   1526             out_path=out_path,

/opt/conda/lib/python3.9/site-packages/arcgis/gis/_impl/_con/ in _handle_response(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key)
    998                     return data
    999                 errorcode = data["error"]["code"] if "code" in data["error"] else 0
-> 1000                 self._handle_json_error(data["error"], errorcode)
   1001             return data
   1002         else:

/opt/conda/lib/python3.9/site-packages/arcgis/gis/_impl/_con/ in _handle_json_error(self, error, errorcode)
   1022         errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")"
-> 1023         raise Exception(errormessage)
   1025     def post_multipart(

Exception: Unable to add feature service definition.
Invalid argument. Source service infos_UD_v2 does not exist.
(Error Code: 400)

what's strange is that the infos_UD_v2 table does exist

0 Kudos
New Contributor II

it works, I had to adapt some things I hadn't thought of.
many thanks

0 Kudos