<?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 Trouble Generating Token Using Portal Rest API in ArcGIS Enterprise Portal Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1179590#M12359</link>
    <description>&lt;P&gt;I am attempting to generate a token from REST using Python for portal admin but only receiving the generateToken page in HTML as a response.&amp;nbsp; We are running Enterprise version 10.8.1.&amp;nbsp; This is my code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# A function to generate a token given username, password and the adminURL.
def getToken(username, password, baseURL):
    # Token URL is typically http://server[:port]/arcgis/admin/generateToken
    tokenURL = "{}arcgis/sharing/rest/generateToken".format(baseURL)
    
    params = urllib.parse.urlencode({'username' : username,
                                   'password' : password,
                                   'client' : 'referer',
                                   'referer': baseURL,
                                   'expiration': 60,
                                   'f' : 'json'})
    
    headers = {"Content-Type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    
    # Read response
    response = requests.post(tokenURL, data=params, headers=headers)
    return response.text&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used similar syntax before to generate a token with ArcGIS Server admin version 10.8.1, and that code still works.&amp;nbsp; Any reason why the Portal generateToken would be more finicky, or what the problem might be here?&amp;nbsp; It seems like something with the request must be off to not return the token in response.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jun 2022 18:56:03 GMT</pubDate>
    <dc:creator>JasonBartling1</dc:creator>
    <dc:date>2022-06-02T18:56:03Z</dc:date>
    <item>
      <title>Trouble Generating Token Using Portal Rest API</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1179590#M12359</link>
      <description>&lt;P&gt;I am attempting to generate a token from REST using Python for portal admin but only receiving the generateToken page in HTML as a response.&amp;nbsp; We are running Enterprise version 10.8.1.&amp;nbsp; This is my code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# A function to generate a token given username, password and the adminURL.
def getToken(username, password, baseURL):
    # Token URL is typically http://server[:port]/arcgis/admin/generateToken
    tokenURL = "{}arcgis/sharing/rest/generateToken".format(baseURL)
    
    params = urllib.parse.urlencode({'username' : username,
                                   'password' : password,
                                   'client' : 'referer',
                                   'referer': baseURL,
                                   'expiration': 60,
                                   'f' : 'json'})
    
    headers = {"Content-Type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    
    # Read response
    response = requests.post(tokenURL, data=params, headers=headers)
    return response.text&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used similar syntax before to generate a token with ArcGIS Server admin version 10.8.1, and that code still works.&amp;nbsp; Any reason why the Portal generateToken would be more finicky, or what the problem might be here?&amp;nbsp; It seems like something with the request must be off to not return the token in response.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 18:56:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1179590#M12359</guid>
      <dc:creator>JasonBartling1</dc:creator>
      <dc:date>2022-06-02T18:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Generating Token Using Portal Rest API</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1179882#M12366</link>
      <description>&lt;P&gt;Can you try without encoding the parameters? Since the values are sent in the body of the request there shouldn't be a need to encode the referer URL.&lt;/P&gt;&lt;P&gt;That's the only difference I can see between my working version and yours. I also leave off the headers for the token request but I don't expect that to make a difference.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2022 18:05:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1179882#M12366</guid>
      <dc:creator>ChristopherPawlyszyn</dc:creator>
      <dc:date>2022-06-03T18:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Generating Token Using Portal Rest API</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1180206#M12371</link>
      <description>&lt;P&gt;I get the same HTML page response as before using:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;tokenURL = "{}arcgis/sharing/rest/generateToken".format(baseURL)
    
params = {'username' : username,
          'password' : password,
          'client' : 'requestip',
          'referer': baseURL,
          'expiration': 60,
          'f' : 'json'}
    
 
# Read response
response = requests.post(tokenURL, data=params)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 06 Jun 2022 14:11:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1180206#M12371</guid>
      <dc:creator>JasonBartling1</dc:creator>
      <dc:date>2022-06-06T14:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Generating Token Using Portal Rest API</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1180221#M12372</link>
      <description>&lt;P&gt;Using this code I successfully generated a token on 10.8.1, 10.9, and 10.9.1 Portal sites. The big difference I see is that you're using 'requestip' for the client as opposed to 'referer'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests

baseURL = 'https://&amp;lt;FQDN&amp;gt;:7443/arcgis'
tokenURL = "{}/sharing/rest/generateToken".format(baseURL)
username = &amp;lt;IAA_account&amp;gt;
password = &amp;lt;IAA_password&amp;gt;
expiration = 60

params = {'username': username, 'password': password, 'client': 'referer', 'referer': baseURL, 'expiration': expiration, 'f': 'json'}

response = requests.post(tokenURL, data=params, verify=False)
token = response.json()['token']
print(token)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 15:22:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1180221#M12372</guid>
      <dc:creator>ChristopherPawlyszyn</dc:creator>
      <dc:date>2022-06-06T15:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Generating Token Using Portal Rest API</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1180228#M12373</link>
      <description>&lt;P&gt;Sorry about leaving the requesip in there.&amp;nbsp; That was from a previous attempt.&amp;nbsp; I copy and pasted your code into a jupyter notebook I have going, and I am still not getting a token back.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 14:55:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1180228#M12373</guid>
      <dc:creator>JasonBartling1</dc:creator>
      <dc:date>2022-06-06T14:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Generating Token Using Portal Rest API</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1182338#M12408</link>
      <description>&lt;P&gt;It turns out the solution for me was to use the portal web adapter URL instead of the FQDN with the port number.&amp;nbsp; This is the update to the baseURL parameter I had to make:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;baseURL = "https://webserverDNSentry/webAdapterName/"&lt;/LI-CODE&gt;&lt;P&gt;Thanks to Vysakh, the ESRI support services analyst I was working with, that helped me figure this out.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2022 15:18:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-portal-questions/trouble-generating-token-using-portal-rest-api/m-p/1182338#M12408</guid>
      <dc:creator>JasonBartling1</dc:creator>
      <dc:date>2022-06-13T15:18:26Z</dc:date>
    </item>
  </channel>
</rss>

