I have created an image service through a python script by first creating the draft and then staging and uploading the service definittion to the portal using these three function from arcpy in the same order "CreateImageSDDraft", "StageService_server", "UploadServiceDefinition_server".
Now i want to access the ID of the service that has been created so i can modify the contents or delete the service. How can i access the ID through python?
Solved! Go to Solution.
Also note that you can access the ID of anything in your portal using the ArcGIS Python API. If you're running it from Pro, it might look like:
from arcgis.gis import GIS
gis = GIS("home")
search = gis.content.search('some service name or search term', max_items=-1)
[f'{i.id} | {i.title[:32]:32} | {i.type}' for i in search]
I think @DonMorrison1 has the proper solution to this, but if you needed to find the ID after the fact, being able to quickly search the portal and return it is useful as well.
You can get that from the "Derived Output" which is described in the documentation. Here is a snippet of my code that gets the item of the published image service
rsp = arcpy.UploadServiceDefinition_server(<sd_output_filename>, "HOSTING_SERVER")
gis_item = gis.content.get(rsp[2])
@DonMorrison1 I arrived at this post after searching for this very solution. Unfortunately you code doesn't seem to work for me
When I use it as it is there for my newly uploaded hosted feature layer it throws:
Exception: Invalid URL
(Error Code: 400)
Has something changed since you posted this? If not, and just as an aside, I'm curious as to why you're accessing the [2] from your rsp item. This implies to me rsp is returning a list and you;re requesting the third item in that list
Scratch that, I inadvertently answered my own question. For anyone else that arrives here:
The derived parameters listed in the help are accessed in the order they're listed. So @DonMorrison1 solution [2] is correct for gaining the out_mapServiceItemID parameter as it's third on the list.
Because I am using this on a hosted feature layer, I needed the fourth item on the list i.e. [3]
Also note that you can access the ID of anything in your portal using the ArcGIS Python API. If you're running it from Pro, it might look like:
from arcgis.gis import GIS
gis = GIS("home")
search = gis.content.search('some service name or search term', max_items=-1)
[f'{i.id} | {i.title[:32]:32} | {i.type}' for i in search]
I think @DonMorrison1 has the proper solution to this, but if you needed to find the ID after the fact, being able to quickly search the portal and return it is useful as well.