<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python Add Service to AGOL with Stored Credentials? in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/python-add-service-to-agol-with-stored-credentials/m-p/743195#M36598</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just follow&amp;nbsp;up on this post in case someone else stumbles upon it with the same question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;We opened an Esri case and&amp;nbsp;determined this solution:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;from arcgis.gis import GIS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gis = GIS('https://www.arcgis.com','arch0000')&lt;/P&gt;&lt;P&gt;token = gis._con.token&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;item_properties = {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"title":"TestAdd2",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"tags":"test",&lt;/P&gt;&lt;P&gt;"url":"&lt;A href="https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer"&gt;https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer&lt;/A&gt;",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"type":"Feature Service",&lt;/P&gt;&lt;P&gt;"description":"Test Me",&lt;/P&gt;&lt;P&gt;"serviceUsername":"user1",&lt;/P&gt;&lt;P&gt;"servicePassword":"user1",&lt;/P&gt;&lt;P&gt;"token":token&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gis.content.add(data="&lt;A href="https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer"&gt;https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer&lt;/A&gt;",owner="arch0000",item_properties=item_properties)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Amanda&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Dec 2019 14:48:23 GMT</pubDate>
    <dc:creator>Amanda__Huber</dc:creator>
    <dc:date>2019-12-11T14:48:23Z</dc:date>
    <item>
      <title>Python Add Service to AGOL with Stored Credentials?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-add-service-to-agol-with-stored-credentials/m-p/743194#M36597</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How can we add a&amp;nbsp;service to&amp;nbsp;AGOL with stored credentials using the python api?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ideally we would like to add an item from our Portal ArcGIS Server to AGOL though python.&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;&lt;/P&gt;We've looked through the documentation found publish(), add(), and register(), but did not see anything about&amp;nbsp;storing credentials?&lt;/DIV&gt;&lt;DIV class=""&gt;Thanks!&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Dec 2019 22:22:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-add-service-to-agol-with-stored-credentials/m-p/743194#M36597</guid>
      <dc:creator>Amanda__Huber</dc:creator>
      <dc:date>2019-12-09T22:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: Python Add Service to AGOL with Stored Credentials?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-add-service-to-agol-with-stored-credentials/m-p/743195#M36598</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just follow&amp;nbsp;up on this post in case someone else stumbles upon it with the same question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;We opened an Esri case and&amp;nbsp;determined this solution:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;from arcgis.gis import GIS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gis = GIS('https://www.arcgis.com','arch0000')&lt;/P&gt;&lt;P&gt;token = gis._con.token&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;item_properties = {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"title":"TestAdd2",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"tags":"test",&lt;/P&gt;&lt;P&gt;"url":"&lt;A href="https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer"&gt;https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer&lt;/A&gt;",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"type":"Feature Service",&lt;/P&gt;&lt;P&gt;"description":"Test Me",&lt;/P&gt;&lt;P&gt;"serviceUsername":"user1",&lt;/P&gt;&lt;P&gt;"servicePassword":"user1",&lt;/P&gt;&lt;P&gt;"token":token&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gis.content.add(data="&lt;A href="https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer"&gt;https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer&lt;/A&gt;",owner="arch0000",item_properties=item_properties)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Amanda&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Dec 2019 14:48:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-add-service-to-agol-with-stored-credentials/m-p/743195#M36598</guid>
      <dc:creator>Amanda__Huber</dc:creator>
      <dc:date>2019-12-11T14:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Python Add Service to AGOL with Stored Credentials?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/python-add-service-to-agol-with-stored-credentials/m-p/1015831#M37973</link>
      <description>&lt;P&gt;Amanda's Post Helped me out a lot.&amp;nbsp; For anyone looking for another working example for Adding Portal Items to ArcGIS Online with Stored Creds...&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Import the GIS
from arcgis.gis import GIS

# Login to AGOL
username="username"
password="password"
agol = GIS("https://www.arcgis.com", username, password)

agol_user = agol.properties.user.username
agol_token = agol._con.token
print("---&amp;gt;Logged into AGOL as {}".format(agol_user))

# Login to Enterprise Portal

# Using Pro Instance for Example
portal = GIS("pro")
portal_user = portal.properties.user.username
print("---&amp;gt;Logged into Portal as {}".format(portal_user))

# Generate a List of Items to Add to AGOL from Portal
# --&amp;gt; Search your Portal for whatever content you want

# Example Search
item_types = []
project_number = "12345"
# Return only the item types of interest in the search
item_types = ['Feature Service', 'Vector Tile Service', 'Tile Servie']

# A search using list comprehension to fine tune the search
items_to_add = [item for item in portal.content.search(query=""+ 
                project_number + "* AND owner:" + portal_user, max_items=100)
               if item.type in item_types]

# Add the Portal Items to AGOL
for item in items_to_add:
    # Check if item already exists
    if agol.content.search(item.title):
        print("{} is already an item in AGOL.".format(item.title))
        continue
    
    item_properties = {"title": item.title,
                       "tags": "tag1, tag2",
                       "url": item.url,
                       "type": item.type,
                       "description": "This is a Portal Item",
                       "serviceUsername": "a_portal_user",
                       "servicePassword": "the_portal_users_password",
                       "token": agol_token
                       }
    data = item.url
    owner = agol_user
    item_properties=item_properties

    new_item = agol.content.add(data=data, owner=owner, 
                                item_properties=item_properties)
    print(new_item)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 03:43:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/python-add-service-to-agol-with-stored-credentials/m-p/1015831#M37973</guid>
      <dc:creator>JustinReynolds</dc:creator>
      <dc:date>2021-01-12T03:43:10Z</dc:date>
    </item>
  </channel>
</rss>

