How to access the ID of a published service on ArcGIS Portal?

412
2
Jump to solution
11-18-2021 02:09 AM
RehanChaudhary
Occasional Contributor

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?

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Honored Contributor

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]

jcarlson_0-1637243151704.png

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.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
2 Replies
DonMorrison1
Occasional Contributor III

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])

 

jcarlson
MVP Honored Contributor

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]

jcarlson_0-1637243151704.png

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.

- Josh Carlson
Kendall County GIS
0 Kudos