Hi,
We are using ArcGIS Entreprise 11.1 with a federated server and we would like to automate the caching of our vector tile layers.
Our vector tile service has an associated, referenced feature service which allows the rebuild cache Rest operation:
Clicking on the "Rebuild Cache" button is working perfectly, therefore it looks like a great way to automate using this method.
We are aiming to automate the rebuild cache daily by reproducing this rest operation and we tried running the following script:
import urllib
import json
'''Retrieves a token to be used with API requests.'''
data = urllib.parse.urlencode({'username' : 'username',
'password' : 'password',
'client' : 'https://XXX/server/rest/services',
'referer': 'https://YYY/portal/sharing/rest',
'expiration': 60,
'f' : 'json'}).encode('utf-8')
response = urllib.request.urlopen('https://YYY/portal' + '/sharing/rest/generateToken',data).read().decode('utf-8')
rebuildcacheurl = 'https://XXX/server/rest/services/System/CachingControllers/GPServer/Manage%20Vector%20Tile%20Cache/submitJob?serviceName=GX_WGS84_BaseMap&serviceFolder=Hosted&tilingFormat=INDEXED&f=json&token='
token = json.loads(response)['token']
submitjob = urllib.request.urlopen(rebuildcacheurl+token).read().decode('utf-8')
We have been unsuccessful so far and we are receiving this error response:
I have been trying to find documentation but I couldn't get anything which solve our issue.
Any help would be appreciated.
Thanks a lot!
Solved! Go to Solution.
Hi @CharliePatrier,
Have you tried using Postman to create the request for you? This image may help you get this in the right format 🙂
Postman can convert cURL requests to python - you then simply need to create a two-stage script.
getToken() (return Token)
rebuildCache(Token)
Hi @CharliePatrier,
Have you tried using Postman to create the request for you? This image may help you get this in the right format 🙂
Postman can convert cURL requests to python - you then simply need to create a two-stage script.
getToken() (return Token)
rebuildCache(Token)
Thanks @A_Wyn_Jones it worked this way, very good outcome!
We took inspiration from your workflow and made a custom FME transformer using HTTPCallers.
For anyone stumbling upon this thread (like we did) looking for a non coding solution: https://hub.safe.com/publishers/martin-ekstrand/transformers/arcgisenterprisevectortilerebuildcache
Hi @CharliePatrier and @StaffanstorpsKommun
To revisit this one, You can also call for the recreation of a cache via the ArcGIS Server admin endpoint - this should've been my first suggestion!
Only for ArcGIS Online Though @A_Wyn_Jones? That particular endpoint does not exist in Enterprise, and you have to use the System/CachingControllers/GPServer/Manage%20Vector%20Tile%20Cache method?
@StaffanstorpsKommun Yes! My apologies, only for ArcGIS Online!
Got excited reading the WRONG documentation 😄 Mondays!
To help everybody, this is the Python script we came up with:
import urllib
import json
import requests
### data to be sent for token generation on Portal
token_data = urllib.parse.urlencode({'username' : 'XXX',
'password' : 'YYY',
'referer': 'URL ArcGIS Server with webadaptor',
'expiration': 60,
'f' : ''}).encode('utf-8')
### getting token from ArcGIS server
token_response = urllib.request.urlopen('URL ArcGIS Server with webadaptor' + '/tokens/generateToken',
token_data).read().decode('utf-8')
### vector tile url to request in order to submit cache job
rebuildcacheurl = 'URL ArcGIS Server with webadaptor/rest/services/System/CachingControllers/GPServer/Manage%20Vector%20Tile%20Cache/submitJob?serviceName=ServiceName&serviceFolder=Hosted&tilingFormat=INDEXED&f=json&token='
## header required for cache job request
rebuildcache_headers = {
'authority': 'Full Computer name of ArcGIs Server location',
'accept': '*/*',
'origin': 'URL ArcGIS Portal',
'referer': 'URL ArcGIS Portal/'}
### submitting cache job
response = requests.request("GET", rebuildcacheurl+token_response, headers=rebuildcache_headers)
print('Job has been submitted')
print('URL ArcGIS Server with webadaptor/rest/services/System/CachingControllers/GPServer/Manage%20Vector%20Tile%20Cache/jobs/'+response.json()['jobId']+'?f=html')