<?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 script to replicate hosted feature service on ArcGIS Online including attachments. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109834#M8500</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry &lt;A href="https://community.esri.com/migrated-users/35315" target="_blank"&gt;Khaled Hassen&lt;/A&gt;​I should have read your reply more thoroughly.&amp;nbsp; I tacked the token on the end of my url using:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;replicaUrl = crJson['URL'] + '&amp;amp;token=' + token
urllib.urlretrieve(replicaUrl, 'myLayer.json')&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And again I get html code in myLayer.json, but this time it looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/193366_pastedImage_2.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;Am I not adding the token correctly?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:35:50 GMT</pubDate>
    <dc:creator>JeffWard</dc:creator>
    <dc:date>2021-12-11T06:35:50Z</dc:date>
    <item>
      <title>Python script to replicate hosted feature service on ArcGIS Online including attachments.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109826#M8492</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to get &lt;A href="https://gist.github.com/oevans/6992139" rel="nofollow noopener noreferrer" target="_blank"&gt;this script&lt;/A&gt; to work for an application for one of our departments.&amp;nbsp; If you look at the comment by stuartalexandersanders in the GitHub link - that is the same error I am getting.&amp;nbsp; I'm hoping &lt;A href="https://community.esri.com/migrated-users/15881" target="_blank"&gt;Alex Sanders&lt;/A&gt;​ is the same person and has fixed it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN&gt;gtUrl = '&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" target="_blank"&gt;https://www.arcgis.com/sharing/rest/generateToken&lt;/A&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;
gtValues = {'username' : 'MyUsername',
&amp;nbsp; 'password' : 'MyPassword',
&lt;SPAN&gt;&amp;nbsp; 'referer' : '&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fwww.arcgis.com" target="_blank"&gt;http://www.arcgis.com&lt;/A&gt;&lt;SPAN&gt;',&lt;/SPAN&gt;
&amp;nbsp; 'f' : 'json' }
gtData = urllib.urlencode(gtValues)
gtRequest = urllib2.Request(gtUrl, gtData)
gtResponse = urllib2.urlopen(gtRequest)
gtJson = json.load(gtResponse)
token = gtJson['token']

### Create Replica ###
### Update service url HERE ###
&lt;SPAN&gt;crUrl = '&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fservices2.arcgis.com%2FMyServices%2Farcgis%2Frest%2Fservices%2FMyServicName%2FFeatureServer%2FcreateReplica" target="_blank"&gt;http://services2.arcgis.com/MyServices/arcgis/rest/services/MyServicName/FeatureServer/createReplica&lt;/A&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That code works and I am able to get a token for the feature service.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This next block is where I am having my trouble -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;crValues = {'f' : 'json',
&amp;nbsp; 'layers' : '0',
&amp;nbsp; 'returnAttachments' : 'true',
&amp;nbsp; 'token' : token }
crData = urllib.urlencode(crValues)
crRequest = urllib2.Request(crUrl, crData)
crResponse = urllib2.urlopen(crRequest)
crJson = json.load(crResponse)
replicaUrl = crJson['URL']
urllib.urlretrieve(replicaUrl, 'myLayer.json')&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The error I get is from the urlretrieve call.&amp;nbsp; myLayer.json is not a json file but an html file that says "Token Required".&amp;nbsp; The error text in python is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" height="161" src="https://community.esri.com/legacyfs/online/193234_pastedImage_7.png" style="width: 473px; height: 160.973px;" width="473" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas why this would happen?&amp;nbsp; Apparently it was working for Alex before the update to ArcGIS Online earlier this month.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jeff&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:35:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109826#M8492</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2021-12-11T06:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to replicate hosted feature service on ArcGIS Online including attachments.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109827#M8493</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/9225"&gt;Fred Spataro&lt;/A&gt;​, got any ideas?&amp;nbsp; You asked me in my earlier question if I could just use the Export Item method, but I need the attachments and didn't see any parameters to include attachments with Export Item.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 22:16:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109827#M8493</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2016-03-28T22:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to replicate hosted feature service on ArcGIS Online including attachments.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109828#M8494</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jeff,&lt;/P&gt;&lt;P&gt;The export item method 'should' bring back ALL the data from the entire feature service.&amp;nbsp; I haven't tried it with attachments but did have a service with multiple layers and tables and got back a file geodatabase will all the items... use exportFormat as file geodatabase and leave the layers parameter empty.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 23:22:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109828#M8494</guid>
      <dc:creator>FredSpataro</dc:creator>
      <dc:date>2016-03-28T23:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to replicate hosted feature service on ArcGIS Online including attachments.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109829#M8495</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the last release we have in online, download the json file/sqlite from create replica API will require a token. This is to prevent unauthenticated users from download the create replica output by other users. Pl. when download the output from create or sync replica append a &amp;amp;token={your-token} to the json file url. Pl. let us know if this does not work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Khaled&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 16:14:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109829#M8495</guid>
      <dc:creator>KhaledHassen</dc:creator>
      <dc:date>2016-03-29T16:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to replicate hosted feature service on ArcGIS Online including attachments.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109830#M8496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was actually thinking this as I was driving home last night.&amp;nbsp; So I need to get another token for the url to the json file (replicaUrl in my code)?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 19:25:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109830#M8496</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2016-03-29T19:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to replicate hosted feature service on ArcGIS Online including attachments.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109831#M8497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may want to try the following tool:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/docs/DOC-6496"&gt;Download ArcGIS Online Feature Service or ArcGIS Server Feature/Map Service&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's setup as a GP tool so it's easier to configure.&amp;nbsp; Let me know if you run into any errors.&amp;nbsp; I'm seeing some issues trying to download older services that contain attachments.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 19:32:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109831#M8497</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2016-03-29T19:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to replicate hosted feature service on ArcGIS Online including attachments.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109832#M8498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jake,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the input.&amp;nbsp; It looks like you have done what I am trying to do, but I think the code you use for the attachments is the same code I am trying to use in my script (line 286 in your code is where I hit my problem).&amp;nbsp; So it is running into the same problem I am having.&amp;nbsp; I was able to run your tool successfully but it said there were no attachments when there are.&amp;nbsp; &lt;A href="https://community.esri.com/migrated-users/35315"&gt;Khaled Hassen&lt;/A&gt;​ mentioned above that with the recent ArcGIS Online update there is another token required to get the json that contains the data.&amp;nbsp; I'm not sure how to go about submitting that token to get at the json, I'm a newbie at the REST API and web requests.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any other thoughts?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 22:33:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109832#M8498</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2016-03-29T22:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to replicate hosted feature service on ArcGIS Online including attachments.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109833#M8499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;What I meant in my previous message is that all what you need to do is to append the token to the url returned from create replica. So if the server returns url=&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fservices.arcgis.com%2Fmytenent%2F..%2Fmyreplica.json" rel="nofollow" target="_blank"&gt;http://services.arcgis.com/mytenent/../myreplica.json&lt;/A&gt;&lt;SPAN&gt;, you need to add &amp;amp;token=mytoken to the json url you are downloading. The token can be the same token you used in creating the replica if it is not expired. Otherwise you will need to acquire a new token based on your user identity.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Khaled&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Mar 2016 03:38:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109833#M8499</guid>
      <dc:creator>KhaledHassen</dc:creator>
      <dc:date>2016-03-30T03:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to replicate hosted feature service on ArcGIS Online including attachments.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109834#M8500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry &lt;A href="https://community.esri.com/migrated-users/35315" target="_blank"&gt;Khaled Hassen&lt;/A&gt;​I should have read your reply more thoroughly.&amp;nbsp; I tacked the token on the end of my url using:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;replicaUrl = crJson['URL'] + '&amp;amp;token=' + token
urllib.urlretrieve(replicaUrl, 'myLayer.json')&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And again I get html code in myLayer.json, but this time it looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/193366_pastedImage_2.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;Am I not adding the token correctly?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:35:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109834#M8500</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2021-12-11T06:35:50Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to replicate hosted feature service on ArcGIS Online including attachments.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109835#M8501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jeff,&lt;/P&gt;&lt;P&gt;Not sure what the url looks like but if the token is the first parameter in the url which I think it is, you will have to use:&lt;/P&gt;&lt;P&gt;?token={your-token}. Pl. not the use of ? instead of &amp;amp;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Khaled&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2016 05:18:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109835#M8501</guid>
      <dc:creator>KhaledHassen</dc:creator>
      <dc:date>2016-03-31T05:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to replicate hosted feature service on ArcGIS Online including attachments.</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109836#M8502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ESRI has pointed me to this script that pulls down a fgd from a AGO hosted service.&amp;nbsp; It seems to be working for me &lt;A href="https://github.com/Esri/developer-support/blob/master/python/general-python/create-replica-and-download/createReplicaAndDownload.py" title="https://github.com/Esri/developer-support/blob/master/python/general-python/create-replica-and-download/createReplicaAndDownload.py"&gt;developer-support/createReplicaAndDownload.py at master · Esri/developer-support · GitHub&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Apr 2016 15:40:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to-replicate-hosted-feature-service/m-p/109836#M8502</guid>
      <dc:creator>AlexSanders</dc:creator>
      <dc:date>2016-04-01T15:40:21Z</dc:date>
    </item>
  </channel>
</rss>

