Add a layer to a hosted feature layer

5783
9
Jump to solution
08-30-2023 08:20 AM
IB3
by
Regular Contributor

I am trying to add an extra layer to a hosted feature layer. I dont find any function inside AGOL to do it directly and I have tried some code in Notebook, but it doesnt seem to be possible. Any ideas how I can do this?

 

See screenshot 

 

Thanks!

2 Solutions

Accepted Solutions
MobiusSnake
MVP Regular Contributor

You can add new layers to a hosted feature layer using the "add to definition" function of the REST API and Python API.

I would definitely test this out on a layer you don't care about first though, especially if you're adding any kind of relationships, it's very easy to mess this up and can be difficult to fix.

Another option would be to export your existing HFL to a File GDB, add a new feature class to the GDB in Pro, then republish the modified File GDB as a new HFL.  This option is definitely safer and easier but can be more work if you have web maps and apps hanging off your existing HFL.

View solution in original post

DougGreen
Frequent Contributor

I've been working on this too. There is a real need for it since we can't see the future or anticipate all needs of a layer at initial creation. Even ESRI Solutions need extended and they seem to include even the kitchen sink. Here's the best post I've found that even has info about a github repo with samples and a bug that shows a workaround to getting these newly added items to show in portal after adding them through the REST API.

View solution in original post

9 Replies
MobiusSnake
MVP Regular Contributor

You can add new layers to a hosted feature layer using the "add to definition" function of the REST API and Python API.

I would definitely test this out on a layer you don't care about first though, especially if you're adding any kind of relationships, it's very easy to mess this up and can be difficult to fix.

Another option would be to export your existing HFL to a File GDB, add a new feature class to the GDB in Pro, then republish the modified File GDB as a new HFL.  This option is definitely safer and easier but can be more work if you have web maps and apps hanging off your existing HFL.

IB3
by
Regular Contributor

How can i get a token to access the rest api? Its says token required

0 Kudos
DougGreen
Frequent Contributor

If you go through Portal/ArcGIS Online to the Item Overview page and scroll down to the "URL" link, it will open it up in the rest services directory and then you can click "Admin" in the upper right. This window has the token already applied. Use the links at the bottom to "addToDefinition". Also, if it says that the token is expired, refresh the Overview page and repeat those steps.

0 Kudos
IB3
by
Regular Contributor

Screen Shot 2023-08-30 at 10.58.25 PM.png

0 Kudos
IB3
by
Regular Contributor

this is what i see

0 Kudos
IB3
by
Regular Contributor

Nevermind. I managed. thanks! 🙂

0 Kudos
IB3
by
Regular Contributor

My problem now is that the layer doesnt appear and I can't create a new item. I get an error...do you know a code to add data that works?

0 Kudos
JoabelBarbieri
Frequent Contributor

How a regular user can do this via ArcGIS PRO (no restAPI handling)?

DougGreen
Frequent Contributor

I've been working on this too. There is a real need for it since we can't see the future or anticipate all needs of a layer at initial creation. Even ESRI Solutions need extended and they seem to include even the kitchen sink. Here's the best post I've found that even has info about a github repo with samples and a bug that shows a workaround to getting these newly added items to show in portal after adding them through the REST API.