Select to view content in your preferred language

Changing the embedded the credential in ArcGIS Online item page

262
2
09-11-2024 12:42 PM
CaitBoyer
Emerging Contributor

Hi everyone! 

Our organization would like to change the Username and Password embedded in 400+ services added as items in ArcGIS Online. This is possible through an item's Settings page under the "Credentials" heading, "To change the stored credentials, enter updated credentials.

However, it will be quite tedious to update each of the 400+ layers individually. Is there a way to change these with the API?

Thank you kindly! 

2 Replies
JakeSkinner
Esri Esteemed Contributor

@CaitBoyer below is an example that I believe will do this.  You will just need to iterate through the items that need to be updated, for example, those layers whose URL's contain utility.arcgis.com or typeKeywords contain 'Service Proxy'.

from arcgis.gis import GIS

# Variables
username = 'jskinner_rats'
password = '*******'
itemId = '5bad6ca9233e42e396146f887cefb5e6'
embeddedUsername = 'portaladmin'
embeddedPassword = '********'

# Connect to AGOL
gis = GIS("https://www.arcgis.com", username=username, password=password)

# Reference layer
item = gis.content.get(itemId)

# Specify username/password
item_properties={
 'serviceUsername': embeddedUsername,
 'servicePassword': embeddedPassword
 }

# Update item
gis_content_item = item.update(item_properties=item_properties)

 

0 Kudos
JACooper
Regular Contributor

I have the same exact issue, and while I can't comment on whether updating service username and password properties worked for me, I found another way that may accomplish this as well.

 

 

from arcgis.gis import GIS
import requests

# Get the GIS object
gis = GIS("https://www.arcgis.com", "your_username", "your_password")

# Get a valid token from the GIS object
token = gis._con.token

# Include the token in the request parameters
update_url = f"{og_delaware_fl.url}/admin"
payload = {
    'username': 'your_username',
    'password': 'your_password',
    'f': 'json',
    'token': token  # Add the token here
}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}

# Send the request
response = requests.post(update_url, data=payload, headers=headers)
print(response.json())

 

 

0 Kudos