<?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: Running a scripting tool on my Portal providing a token in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/running-a-scripting-tool-on-my-portal-providing-a/m-p/1219795#M78933</link>
    <description>&lt;P&gt;Michael, can you share the section of code being used to generate the token?&lt;/P&gt;</description>
    <pubDate>Fri, 07 Oct 2022 13:13:56 GMT</pubDate>
    <dc:creator>GeoJosh</dc:creator>
    <dc:date>2022-10-07T13:13:56Z</dc:date>
    <item>
      <title>Running a scripting tool on my Portal providing a token</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/running-a-scripting-tool-on-my-portal-providing-a/m-p/1219717#M78928</link>
      <description>&lt;P&gt;I have a scripting tool on my Portal which works fine if the user is signed in. However, if the user is not signed in, the scripting tool obviously doesn't work.&lt;/P&gt;&lt;P&gt;I also have a token, which has been generated earlier (though not much earlier - the token is still current).&lt;/P&gt;&lt;P&gt;Is it possible to use this token to run my scripting tool, and if so, how should it be passed into the URL? This is a very basic version of how it works:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;window.open("https://myserver.com/server/rest/services/MyPrintLayouts/ScriptX01_AGP2_9/GPServer/ScriptX01/submitJob?Id=" + vId + "&amp;amp;FileDestination=" + vDestination + "&amp;amp;env%3AoutSR=&amp;amp;env%3AprocessSR=&amp;amp;returnZ=false&amp;amp;returnM=false&amp;amp;returnTrueCurves=false&amp;amp;context=&amp;amp;f=html", '_blank');&lt;/LI-CODE&gt;&lt;P&gt;I've tried adding a&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;amp;token=" + token&lt;/LI-CODE&gt;&lt;P&gt;Extra token parameter in there but that's not working. Each time it gets called, if the user isn't signed in, it will go to the sign in screen.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 05:08:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/running-a-scripting-tool-on-my-portal-providing-a/m-p/1219717#M78928</guid>
      <dc:creator>MichaelBell</dc:creator>
      <dc:date>2022-10-07T05:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Running a scripting tool on my Portal providing a token</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/running-a-scripting-tool-on-my-portal-providing-a/m-p/1219795#M78933</link>
      <description>&lt;P&gt;Michael, can you share the section of code being used to generate the token?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 13:13:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/running-a-scripting-tool-on-my-portal-providing-a/m-p/1219795#M78933</guid>
      <dc:creator>GeoJosh</dc:creator>
      <dc:date>2022-10-07T13:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Running a scripting tool on my Portal providing a token</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/running-a-scripting-tool-on-my-portal-providing-a/m-p/1222693#M79050</link>
      <description>&lt;P&gt;Sure. Sorry I've only just gotten round to this now, been in the field a bit. See below for the edited version:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var tokenUrl = "https://myserver.com/portal/sharing/rest/generateToken";
			
			var requestParams = {
				method: "post",
				query: {
					f: 'json',
					username: 'MyUsername',
					password: 'MyPassword',
					referer: window.location.origin
				}
			};
			
			var myRequest = esriRequest(tokenUrl, requestParams);
			
			myRequest.then(function(response){
				var token = response.data.token;
				esriId.registerToken({
					server: "https://myserver.com/portal/sharing/rest",
					token: token
				});
				initMap();
			});&lt;/LI-CODE&gt;&lt;P&gt;As I say, I have a tool which I can call using the following:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;https://myserver.com/server/rest/services/MyPrintLayouts/ScriptX01_AGP2_9/GPServer/ScriptX01/submitJob?&amp;amp;MyId=%7B&amp;lt;MyIdAsGUID&amp;gt;%7D&amp;amp;FileDestination=C%3A%5Ctemp%5C%7B&amp;lt;MyFilename&amp;gt;%7D.pdf&amp;amp;env%3AoutSR=&amp;amp;env%3AprocessSR=&amp;amp;returnZ=false&amp;amp;returnM=false&amp;amp;returnTrueCurves=false&amp;amp;context=&amp;amp;f=html&lt;/LI-CODE&gt;&lt;P&gt;If I'm logged into the server already, then it works fine. If I'm not however, I get presented with a login screen. I'd like to be able to use the token to access it, which doesn't seem to work if I include it in the URL (which I assume I'm doing wrong).&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 03:37:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/running-a-scripting-tool-on-my-portal-providing-a/m-p/1222693#M79050</guid>
      <dc:creator>MichaelBell</dc:creator>
      <dc:date>2022-10-18T03:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Running a scripting tool on my Portal providing a token</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/running-a-scripting-tool-on-my-portal-providing-a/m-p/1222699#M79051</link>
      <description>&lt;P&gt;Huh, go figure. It may have been running all along, I'm unsure.&lt;/P&gt;&lt;P&gt;In my latest code, I made a couple of little tweaks to my requestparams. It is instead:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;			var requestParams = {
				method: "post",
				query: {
					f: 'json',
					username: 'MyUsername',
					password: 'MyPassword',
					client: 'requestip'
				}
			};&lt;/LI-CODE&gt;&lt;P&gt;And added the token to my url, at the end.&lt;/P&gt;&lt;P&gt;In any case, I'm still getting the signin screen, which I believe is because I'm calling the job wrong (at the moment I'm just using a window.open to call the url), but the job still calls and executes. I just assumed it wasn't because of the login screen.&lt;/P&gt;&lt;P&gt;Now to find a better way to call the job... (eventually, because now other tasks have popped up)&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 04:12:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/running-a-scripting-tool-on-my-portal-providing-a/m-p/1222699#M79051</guid>
      <dc:creator>MichaelBell</dc:creator>
      <dc:date>2022-10-18T04:12:49Z</dc:date>
    </item>
  </channel>
</rss>

