Hello everyone,
We recently faced a problem with a coworker. We would like to add tags on existing services so we used the classic method :
tags = item.tags
tags.append("test_tag")
item.update(item_properties={'test_tag': tags})
And it worked perfectly, we can see the new tag in the portal :
But when we checked in the AGS Manager Tool or in the API REST, we cannot see the new tag we added :
API REST :
ArcGIS Manager :
We had the idea to connect to the AGS and not to the portal and change the item's properties with this code :
new_tag = "test_tag"
admin_username = "username"
admin_password = "password"
server_url = 'https://domain/rest/services/unit_test/unit_test_service.MapServer'
properties_url = f"{server_url}/info/iteminfo?f=json"
response = requests.get(properties_url, auth=(
admin_username,
admin_password
))
service_info = response.json()
current_tags = service_info.get("tags", "")
update_tags = f"{current_tags}, {new_tag}" if current_tags else new_tag
update_url = f"{server_url}/edit?f=json"
update_payload = {"tags": update_tags}
response = requests.post(update_url, data=update_payload,
auth=(admin_username,
admin_password))
but it does not worker either.
We also thought about changing item properties via the following method :
gis.admin.servers.list()
so we can get server properties, services, item etc, but as you can probably imagine, it did not work either.
We don't konw if it is a bug or if there is something we missed.
Hope you can help us.
Best regards
Solved! Go to Solution.
When you say "AGS Manager Tool", what are you referring to? Server Manager?
Note that the first operation you're doing applies to the item in your portal's content directory. Server Manager, on the other hand, is specifically for managing services and other server resources.
While a service can be an item in your portal, they are not the same. The portal has its own database of content items with the attributes of each (like tags), which can be configured separately from the actual data source of the item. For instance, I can take a public feature service URL from another org and add it to my portal as an item, then add metadata, tags, and other details for my own convenience, but it does not alter the information on the source itself.
If you want to check the API for your updated tags, you'll probably want to go into the portal's sharing endpoint, something like /portal/sharing/rest. That's what you updated in your first code snippet.
@ValGaj concurring with @jcarlson , but would also add that if you're looking to edit the iteminfo on the service endpoint, this can be done either manually through the ArcGIS Server Admin Directory:
https://your.domain/ADAPTOR/admin/services/MAP_SERVICE/iteminfo/edit
or you can edit this programatically with a python post request along the lines of the below:
import requests
import json
# Configuration
server_name = "<server-name>"
service_folder = "<folder>"
service_name = "<service-name>"
username = "<your-username>"
password = "<your-password>"
new_tags = "tag1, tag2, tag3"
# Construct the URL
url = f"https://{server_name}:6443/arcgis/admin/services/{service_folder}/{service_name}.MapServer/iteminfo/edit"
# Data payload
payload = {
"tags": new_tags,
"f": "json"
}
# Headers
headers = {
"Content-Type": "application/json"
}
# Authentication
auth = (username, password)
# Make the POST request
response = requests.post(url, data=json.dumps(payload), headers=headers, auth=auth)
# Check the response
if response.status_code == 200:
print("Tags updated successfully")
print("Response:", response.json())
else:
print("Failed to update tags")
print("Status Code:", response.status_code)
print("Response:", response.text)
When you say "AGS Manager Tool", what are you referring to? Server Manager?
Note that the first operation you're doing applies to the item in your portal's content directory. Server Manager, on the other hand, is specifically for managing services and other server resources.
While a service can be an item in your portal, they are not the same. The portal has its own database of content items with the attributes of each (like tags), which can be configured separately from the actual data source of the item. For instance, I can take a public feature service URL from another org and add it to my portal as an item, then add metadata, tags, and other details for my own convenience, but it does not alter the information on the source itself.
If you want to check the API for your updated tags, you'll probably want to go into the portal's sharing endpoint, something like /portal/sharing/rest. That's what you updated in your first code snippet.
@ValGaj concurring with @jcarlson , but would also add that if you're looking to edit the iteminfo on the service endpoint, this can be done either manually through the ArcGIS Server Admin Directory:
https://your.domain/ADAPTOR/admin/services/MAP_SERVICE/iteminfo/edit
or you can edit this programatically with a python post request along the lines of the below:
import requests
import json
# Configuration
server_name = "<server-name>"
service_folder = "<folder>"
service_name = "<service-name>"
username = "<your-username>"
password = "<your-password>"
new_tags = "tag1, tag2, tag3"
# Construct the URL
url = f"https://{server_name}:6443/arcgis/admin/services/{service_folder}/{service_name}.MapServer/iteminfo/edit"
# Data payload
payload = {
"tags": new_tags,
"f": "json"
}
# Headers
headers = {
"Content-Type": "application/json"
}
# Authentication
auth = (username, password)
# Make the POST request
response = requests.post(url, data=json.dumps(payload), headers=headers, auth=auth)
# Check the response
if response.status_code == 200:
print("Tags updated successfully")
print("Response:", response.json())
else:
print("Failed to update tags")
print("Status Code:", response.status_code)
print("Response:", response.text)
@jcarlson and @David_Brooks thanks for your answers.
Yes i was referring to the ArcGIS Server Manager.
And we managed with your suggestions to add tags via adding iteminfo
url = f"https://{server_name}:6443/arcgis/admin/services/{service_folder}/{service_name}.MapServer/iteminfo"
We had some certificates issues but that is common accross our organization thus we managed to fix this.
Note that the first operation you're doing applies to the item in your portal's content directory. Server Manager, on the other hand, is specifically for managing services and other server resources.
I did not know this part. That is weird but logical at the same time. Why is that by the way ? Why there are 2 differents types of ressources across a same organization ?
Thanks you very much