<?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: Generate Token with VBA in MS Excel in ArcGIS REST APIs and Services Questions</title>
    <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/generate-token-with-vba-in-ms-excel/m-p/380146#M1812</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just venturing a guess...&lt;/P&gt;&lt;P&gt;The &amp;gt; in your where clause probably needs to be escaped with %3E. &lt;SPAN&gt;OBJECTID%3E1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You could omit the where as a test.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://www.w3schools.com/tags/ref_urlencode.asp"&gt;HTML URL Encoding Reference&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Nov 2018 00:47:22 GMT</pubDate>
    <dc:creator>RandyBurton</dc:creator>
    <dc:date>2018-11-08T00:47:22Z</dc:date>
    <item>
      <title>Generate Token with VBA in MS Excel</title>
      <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/generate-token-with-vba-in-ms-excel/m-p/380145#M1811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a current request to&amp;nbsp;download field collected data and pics hosted in ArcGIS Online and format in an Excel table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the back end of Excel (VBA) have managed to connect to ArcGIS online and generate a token with the following code&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;Dim tokenHTTP As Object
Set tokenHTTP &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;CreateObject&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"MSXML2.ServerXMLHTTP"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
Dim tokenJSON As String
Dim tokenURL As String
tokenURL &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fwww.arcgis.com%2Fsharing%2Frest%2FgenerateToken%3Ff%3Djson%26username%3D" target="_blank"&gt;https://www.arcgis.com/sharing/rest/generateToken?f=json&amp;amp;username=&lt;/A&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt; Me&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;userName_Txt&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Value &lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"&amp;amp;password="&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt; Me&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;password_Txt&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Value &lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"&amp;amp;client=requestip&amp;amp;expiration=1"&lt;/SPAN&gt;
tokenHTTP&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Open &lt;SPAN class="string token"&gt;"POST"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; tokenURL&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; False
tokenHTTP&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;setRequestHeader &lt;SPAN class="string token"&gt;"Content-type"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"application/json"&lt;/SPAN&gt;
tokenHTTP&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;send &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;tokenJSON&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
Debug&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Print &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;tokenHTTP&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;responseText&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;the response looks like this.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;{
 "token":"hIBzdwwVbXv9k8iIZtr0LBwZ5ujSwCdTrdS6_P1XngsglCLnB2tpiV8u9W-6oMDA9Ggf6EMMd77SmXH6BPszKSGvf_oz9QTnEyt4YsSZ-nCuUDzhxW8j6oaAKET8Hk-4qBnLiXGEpuz8JifBSLwHFg..",
 "expires":1541634562738,
 "ssl":true
}‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is, when I try to use this token to&amp;nbsp;query&amp;nbsp;a FeatureService like this&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;Dim httpObj As Object
Set httpObj &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;CreateObject&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"MSXML2.ServerXMLHTTP"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

Dim responseJSON As String
Dim featureServiceURL As String
featureServiceURL &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fservices8.arcgis.com%2Fmyagolid%2Farcgis%2Frest%2Fservices%2Ftest_points%2FFeatureServer%2F0%2Fquery%3Fwhere%3DOBJECTID" target="_blank"&gt;https://services8.arcgis.com/myagolid/arcgis/rest/services/test_points/FeatureServer/0/query?where=OBJECTID&lt;/A&gt;&lt;SPAN&gt;&amp;gt;1&amp;amp;outFields=*&amp;amp;returnHiddenFields=true&amp;amp;returnGeometry=true&amp;amp;returnExceededLimitFeatures=true&amp;amp;f=pgeojson&amp;amp;token="&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt; agoToken
Debug&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Print &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Get Data from: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt; featureServiceURL&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

httpObj&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Open &lt;SPAN class="string token"&gt;"POST"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; featureServiceURL&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; False
httpObj&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;setRequestHeader &lt;SPAN class="string token"&gt;"Content-type"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"application/json"&lt;/SPAN&gt;
httpObj&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;send &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;responseJSON&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
Debug&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Print &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;responseJSON&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get this error?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;{
 "error" :
 {
 "code" : 498,
 "message" : "Invalid token.",
 "details" : [
 "Invalid token."
 ]
 }
}&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cant work out what is going on here? Is it not returning the full length of the token? Or do I have to configure something in my ArcGIS Online account to allow access?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be much appreciated &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;James&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:32:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/generate-token-with-vba-in-ms-excel/m-p/380145#M1811</guid>
      <dc:creator>DylanJeffries</dc:creator>
      <dc:date>2021-12-11T17:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Token with VBA in MS Excel</title>
      <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/generate-token-with-vba-in-ms-excel/m-p/380146#M1812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just venturing a guess...&lt;/P&gt;&lt;P&gt;The &amp;gt; in your where clause probably needs to be escaped with %3E. &lt;SPAN&gt;OBJECTID%3E1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You could omit the where as a test.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://www.w3schools.com/tags/ref_urlencode.asp"&gt;HTML URL Encoding Reference&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Nov 2018 00:47:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/generate-token-with-vba-in-ms-excel/m-p/380146#M1812</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2018-11-08T00:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Token with VBA in MS Excel</title>
      <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/generate-token-with-vba-in-ms-excel/m-p/380147#M1813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;did you ever get this to work, i'm having the same issues, i can get a token but it doesn't work, i even tried the generated token directly in Chrome against the feature service and it says its invalid&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Stu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Mar 2019 11:56:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/generate-token-with-vba-in-ms-excel/m-p/380147#M1813</guid>
      <dc:creator>StuartMoore</dc:creator>
      <dc:date>2019-03-07T11:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Token with VBA in MS Excel</title>
      <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/generate-token-with-vba-in-ms-excel/m-p/380148#M1814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry Stuart, I ended up giving up on this approach and developed a NodeJS application that exports the feature service an images to an excel file. Excel VBA doesn't deal well with JSON either which was another reason to move to node&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Mar 2019 06:21:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/generate-token-with-vba-in-ms-excel/m-p/380148#M1814</guid>
      <dc:creator>DylanJeffries</dc:creator>
      <dc:date>2019-03-19T06:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Generate Token with VBA in MS Excel</title>
      <link>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/generate-token-with-vba-in-ms-excel/m-p/1480497#M4757</link>
      <description>&lt;P&gt;I was having the same issue until I changed the referer to the https of my feature service.&lt;/P&gt;&lt;P&gt;I also downloaded the module for parsing the json at:&amp;nbsp;&lt;A href="https://github.com/VBA-tools/VBA-JSON" target="_blank" rel="nofollow noopener noreferrer"&gt;https://github.com/VBA-tools/VBA-JSON&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here is the function that works for me:&lt;/P&gt;&lt;P&gt;Public Function getToken()&lt;BR /&gt;Dim httpReq As Object&lt;BR /&gt;Dim response As String&lt;BR /&gt;Dim USERNAME, PASSWORD&lt;BR /&gt;Dim tkn As Variant&lt;BR /&gt;Dim myFeature&lt;/P&gt;&lt;P&gt;USERNAME = "xxxxx"&lt;BR /&gt;PASSWORD = "xxxxx"&lt;BR /&gt;myFeature = "&lt;A href="https://services.arcgis.com/xxxxxxxx/arcgis/rest/services/xxxxx/FeatureServer" target="_blank" rel="nofollow noopener noreferrer"&gt;https://services.arcgis.com/xxxxxxxx/arcgis/rest/services/xxxxx/FeatureServer&lt;/A&gt;"&lt;BR /&gt;Set httpReq = CreateObject("MSXML2.ServerXMLHTTP")&lt;/P&gt;&lt;P&gt;httpReq.Open "GET", "&lt;A href="https://www.arcgis.com/sharing/generateToken?f=pjson&amp;amp;username=" target="_blank" rel="nofollow noopener noreferrer"&gt;https://www.arcgis.com/sharing/generateToken?f=pjson&amp;amp;username=&lt;/A&gt;" &amp;amp; USERNAME &amp;amp; "&amp;amp;password=" &amp;amp; PASSWORD &amp;amp; "&amp;amp;client=&amp;amp;ip=&amp;amp;referer=" * myFeature &amp;amp; "&amp;amp;expiration=1"&lt;BR /&gt;httpReq.send&lt;BR /&gt;response = httpReq.responseText&lt;BR /&gt;Set JSON = JsonConverter.ParseJson(response)&lt;BR /&gt;'Debug.Print httpReq.responseText&lt;/P&gt;&lt;P&gt;tkn = JSON("token")&lt;/P&gt;&lt;P&gt;getToken = tkn&lt;/P&gt;&lt;P&gt;End Function&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 19:46:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-rest-apis-and-services-questions/generate-token-with-vba-in-ms-excel/m-p/1480497#M4757</guid>
      <dc:creator>ReubenWolff</dc:creator>
      <dc:date>2024-05-29T19:46:54Z</dc:date>
    </item>
  </channel>
</rss>

