Interacting with Hosted Feature Layers through the REST API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
first off first I'll just introduce myself my name is Nathan Lu I work in ArcGIS online as a product engineer focused on the hosted feature services backend alright and I'm Rebecca Richmond I work in technical support as a technical trainer for the analysts specifically for ArcGIS online and today we're going to be talking about interacting with a hosted feature layers through the REST API we are going to make an assumption that you guys are at least moderately familiar with ArcGIS online and at least moderately familiar with the API or at least have heard it [Music] we're going to talk a little bit about sort of the theory behind that using the REST API and what you can do with it and then we're going to go into a demo that's going to demonstrate how you can figure out what the UI is doing in the REST API and then apply that in the rest end point and then we're going to go ahead and take that same information that we're grabbing and put it into an automated script so the REST API allows allows users to manage their layers via URL requests and there's two general groups of capabilities one our capabilities on the services and layers so this includes stuff like editing your data creating and managing replicas doing queries and this is something that anybody who has exposure to that layer or has access to that layer can do so anybody you know obviously anybody can open a map can query that the data in the map the second set of capabilities is much more administrative and so this is the admin endpoint of the REST API and it loud allows the data owner or organizational admins to go in and actually modify the service definition you can also do a batch delete using the truncate so if you want to clear out all the data and then maintain that service and add new data to it you can do that through the truncate and it also allows you to refresh so I'm gonna go ahead and dive into the demo that I've got and what I'm gonna be doing so the scenario that I'm demonstrating you're going to be talking about is I've got a bunch of parcel data and you can see the process data here but I don't have information about the owners what I do have as a personal ID in the attribute table of this feature service and I have a CSV with information that links the property ID to the owner name and so what I want to do is I want to basically copy this table into this based on that personal ID so what I'm gonna do is I'm going to basically do this workflow twice and in minutes focus more on the setup to the workflow than to the actual workflow so that because a lot of people were saying are using sort of the yeah more gentle capabilities but this is a little bit more focused on sort of the admin side of things so I have two different parcels and I'm going to use them basically go through the workflow twice once in the user interface so we can actually grab what rest calls the user interface is making and then we can go in ahead and apply those same calls to using the rest endpoint so I'm going to go ahead and open up the parcel user the parcel layer item details and as an admin I would like someone else to actually be doing the appending so this is what we're going towards we're trying to get it so that someone else who does not own the data can do the workflow that I want them to do so the first step that I need to do is actually need to enable editing because unless I'm the data and owner nobody else you know can edit without enabling etiquette so I'm gonna go ahead and pull up fiddler and I'm gonna start capturing and then in the user interface I'm gonna go ahead and enable editing so many settings enable editing save okay sorry it looks like they didn't have feather Quitely sweat right setup refreshing stupid just go back to enable disable all right Ximena quickly unable editing and then enable editing [Music] it's not I think the ball oh sorry all right so this is so we can see the water when you click on that edit enable editing what you're actually sending is an update definition query and specifically you're sending it and saving it make this a little bit larger yeah you're sending it obviously to the organization the rest at point and you're specifically using the admin endpoint so if you're just looking at a feature service you're not only gonna see rest slash services if you're accessing your admin endpoint you're gonna see rest admin services and another thing to note and I have not I've made this mistake before and spent like an hour going why is it's not working you need to make sure whether or not the thing you're applying is being applied to the service or to the layer because if you apply something to the layer that needs to be applied to the service it'll look like it runs but nothing will actually change so it's very important to actually look what you're doing and so then we're also grabbing we're seeing it's the update definition and then additionally what we're seeing we're sending we're seeing the actual value of the update definition request and we can see that it's requesting that to change have static data to false and then is changing capabilities so that query editing create update and delete are all available when you do it through the UI it's also going to add all this information about editor tracking but we didn't actually make any of those changes so I'm just going to grab that I mean we'll we'll edit that out so I'm going to go ahead and I'm gonna switch and do that exact same work throw-up flow but through the REST API so I'm going to go ahead and open up my parcels rest version or Slayer and I'm gonna go to the rest endpoint so now we can see we're at rests left services again going back we won't actually want to be unrest admin so the admin endpoint so you can go there and then we also don't want to be at the layers we want to be at the service level and just to give you sort of an idea of what what this is going to look like we have the JSON here we know that the thing that we're changing is going to be the capabilities and so we can see here that the capabilities currently is just query so people can look at the map and query the data but they can't do anything and we can also say it see that it's currently has static data so I'm gonna go ahead and scroll down to the bottom we can see all the options are all the capabilities that are available to you at this arrest endpoint we're gonna go ahead and update the definition and it will pre-populate the current one and so you can either edit it or if you have something like we the snippet that you have right now you can just go ahead and paste it in as they said we don't need any of this so I'm going to delete it and then you go and go ahead and update the data service definition and we can go ahead and check in the JSON and we can see the capabilities have been added and that the has static data is now false so in theory someone who's doesn't who is not that owner of the data can now come in and edit it and specifically they're going to want to do update data and append data to layer so I'm going to choose my file but here we're running into a problem I wanted to match on parcel ID but parcel ID is not showing up here and what's going on is that ArcGIS online has to recognize parcel ID is having unique field so it's something that you can actually match on so we're going to go ahead and switch back and do that work through through the UI [Music] and so to do that you're gonna actually want to go to the data tab data tap wait for it to load and what you're gonna do is you're gonna actually navigate to the field and to the fields over here hmm I'll try out the other one so you're going to navigate to the fields and you're gonna open the properties of that field up and there's an option to make that field you have unique values so you can say that that's that field has unique values mmm-hmm let me just try to go back once more and see if I can get that in the mood there we go so we have fields we're interested in the property ID fields and so we have this unique we can edit it and dev tools is open we can go ahead and check that on and say save and so that's signal to what's happening we can see that we have is add to definition rest request and look going back to the URL again we're seeing we're at the admin endpoint but unlike the enable editing we are actually doing this at the layer level which makes sense because we're interacting with a layer and not talking about the permissions for the entire surface so again scrolling down we can go ahead and grab the JSON for that and again we're just changing the property of that field it's from to is unique is true I'm going to go ahead and copy that and switch back see the rest and so I'm going to go ahead and go to the rest endpoint again we want to go to the admin we're staying on the lair and we want to add to definition clear this out and then we do need to refresh but now we should be able to go to update data grab the CSV and we see our field so that's just it's it's a way to both get information about what the UI is doing so if you see the UI doing something that helps you figure out what it's doing but it's also a great way to troubleshoot so if you have your own app you can grab that rest URL put it into the rest endpoint and see if it works there um so now I'm going to turn it over to Nathan and he's going to dive into more about how to use this information while automating all right cool great demo so next one I'm going to show you guys about how to kind of like using the make an automated way to instead of going to the UI to do clicking buttons and just using pythons to do this so normally there are two ways you can use in raw Python you know there's a bunch of like libraries you can use in it and also we do also have on they'll have ArcGIS API for Python but I think because of the time is limit I was just trying to show one of the way I using the wall one it's kind of like a roughly updating the the definition things but before I show the demo I just wanted to ask anybody's here so have everyone have using the creative use for any hosting feature service if you do just raise your hand okay okay there are a couple okay so well the reason we wanted to add a view is you know it's good for you to have like let's say you have a multiple audience that you wanted to handle separately right cuz if you have only one source layer and you don't want to be contaminated by this one some others can update or editing you can create multiple views so whenever the update you can do not affect your main one right and then you know you can do some of like administration ways to see all these things I wanted to implement or these things you know I don't want what I have to add in our district we started this regard so this is a one-off away you've seen the Python to kind of jump into the jump into the situations that you can make the workflow you know without a click about multiple you know buttons on the UI so you know the steps I'm showing here so basically you want it to first you know you wanted to grab the existing services and then creating a new services so basically whenever you create a view it actually create another service layer if it that's a easy way to understand and then obviously you need to grab your original service layer info because you want to basically duplicate a new new services right and then you have to parse the JSON that because you have multiple layers maybe you have a multiple tables on that specific data and then you create a new view Jason's and then in the end we will call the admin API to add to the definition of the new cradle ey're and then you know generate a new view so that's pretty much how the workflow looks like so I'm I'm going to jump in the code to kind of show you how to do it from like a wall Python so here I oh okay let me switch back sorry but oh oh it's a different is it different oh okay sorry No yeah okay cool so jump into the code all right I do referencing a bunch of like libraries you know as it is nothing crazy like a some are just trying to avoid the new SSL things but the first part you wanted to to have is like a I would assume you already have a services that you already published the ArcGIS online which is this one that I pointed to and also you want it to be referenced into admin URL that Arabic I show you you know you always want to go to admin because you know obviously an admin API allowing you to do this kind of like a modification and obviously will have the access token and this create parameters this is what I mean that you wanted to have this is whenever you create the view this is pretty much this is you know that the URL I mean this is the service name that you are trying to give it to him and this is the view like its views true means like you know you are creating a view so this part of things you can actually use in the skill that Rebecca just show you whenever you create a services you can basically you know snap that part of Jason's and snap it into this kind of request then the next thing I'm trying to here show you is okay the first step you want to create the you create the of view services so here this one the line I'll highlight is the created view service request so basically you are sending on the request to create services as you can see from here you're appointed to that because I'm using this particular artists online URL and you point it to the create service and then you give the data which is the payload is basically the one that I was just parsing from the other request so if you see check this one this is actually sending the request is the first one you're just trying to get the existing services layered JSON right this is a JSON you got it from there once after that let's let's get next one Oh so now it's sending the request see is creative services it actually create a new services this is a response that you got it will actually just basically URL that the new service is pointing to or insist you see this is view true and this is actually the URL that you are actually creating which you know see based on the URL you will see the name that you are mentioning in the JSON so the next step after we created a view we actually do want to kind of looping through all the layers and tables and you wanted to do add a definition into the by through using the admin API so you will see on line 56 you are actually trying to add a definition about the new viewer new views content so I think I skip this part because this is just just like a for loop that you are trying to parsing out all the layers and you have a tables that existing on your existing services so you see this part is doing a layer and this part is doing the tables so after line 109 we should get a new JSON file and this is basically including every single layers or tables that are existing on your existing services so the next step and we are trying to send a request to add to the definitions to create the new views so if we go check the Fiddler's back here again you will see here we are actually sending a request called attitude definition so and you can see from the from the body here we do have like at the definition and I mean other than that we just have the token you know it just normally access your services and will gather response we create the layers so how do we verify that it's create it so let's go back to the content of ArcGIS online so we gotta see the new layer we just created which is this one right so this is def submit demo Python create view so if we go into here we will see this is a view by saying that is because here we see it's hosted view right so it's it's a view and we do actually want to check if any date data everything is here is it all the data is here so which means we create the views instead of like you go in a normal way like you go here to the back back to the original source you just create a creative view by clicking you know here at the button here there should be like a creative View tab Yesi create a view layer and if you click OK you will see a bunch of requests that I did in my mean Python so in the same way so this is the way I just trying to show how automatically using the Python 2 to create it oh one last thing I think there is a awesome to be neat to mission I don't think too many people know about it so since we already have a bunch of like a you know uh features in this services let's see sometimes you know or the view like oh I wanted to just truncate everything I mean trunk it means like you just delete everything for this services but you keep the metadata right so maybe you have some situations you don't want it to be published everything again but somehow you want to keep the metadata so trunk it might be a good options for you to using this so in order to using that I don't think they have a long you are I think in the future they will definitely but I think on REST API you can do this is if you go to the service the same thing you're just adding the admin to the URL and after the the service service layer level because you only have one layer so this is 0 and after that would put a trunk hit so once we got in here you see there are this is a little little different lick the result so attachment only means let's see if you choose false which means if you trunk it means all the attachment and all the serve of features what we totally disappeared you would truncate or delete everything but if you choose true means okay you only do you only delete the attachment but leave all the features still there so this can give you a little bit options to do that so let's see we just wanna to delete everything right so if we click at rocket and go back to here and I believe we will have off this is another one sorry oh it's good back to you here Anna for refresh and it's not a refreshing no that's nothing yeah yeah so yeah this one will be truncated everything that without any features in there so I think that might be a good you know features that if you wanted to manage the data especially maybe on the views you know if you wanted to have any extra data in there so you can do in this way oh but yeah so let's switch back i think yet so that's pretty much what we have today so we still have like a three minutes remaining for for people's if you have any questions you know feel free to ask but we do recommend it people to using more rest api because you know always the rest api has the more capabilities because sometimes you know UI or any other wrong times they pick up everything off to a rest api so if you are knowing how to use in rest api basically you're seeing any more requests talk with the server server can give you definitely more things than you know than other other like api SDKs could give it to you so yeah that's how I guess the best actually other tap the question is the attachment get update all you're talking about what you track it all of the attachment we do here we do have the attachment for arrest we now actually have a new one in the coming release is actually a pen attachment a lot of you have a tender session that we have yesterday so basically you can you can still use in the normal way like apply edits right you can't find the specific features and you apply edits attachment yeah definitely you can do that and also we do provide a new ways to pend the features Opena attachment sorry so by actually you singing like a zip file so this is the file have multiple like a jpg or you know some other pictures and you can directly upload it to that so a master the question okay of a script that I write oh I can actually later put on my github so you know feel free to go on check out there I can show you later
Info
Channel: Esri Events
Views: 8,214
Rating: 4.6363635 out of 5
Keywords: Esri, ArcGIS, GIS, Esri Events, Geographic Information System
Id: uJvZ8MJA0t4
Channel Id: undefined
Length: 29min 43sec (1783 seconds)
Published: Wed Apr 03 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.