Select to view content in your preferred language

Automation to update a vector tile service referenced with feature service

1628
7
Jump to solution
09-26-2023 10:11 PM
CharliePatrier
Occasional Contributor

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:

CharliePatrier_0-1695790237669.png

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:

CharliePatrier_1-1695791002855.png

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!

 

 

1 Solution

Accepted Solutions
A_Wyn_Jones
Esri Contributor

Hi @CharliePatrier,

Have you tried using Postman to create the request for you? This image may help you get this in the right format 🙂

A_Wyn_Jones_0-1695821331125.png

Postman can convert cURL requests to python - you then simply need to create a two-stage script.

getToken() (return Token)

rebuildCache(Token)

"We've boosted the Anti-Mass Spectrometer to 105 percent. Bit of a gamble, but we need the extra resolution."

View solution in original post

7 Replies
A_Wyn_Jones
Esri Contributor

Hi @CharliePatrier,

Have you tried using Postman to create the request for you? This image may help you get this in the right format 🙂

A_Wyn_Jones_0-1695821331125.png

Postman can convert cURL requests to python - you then simply need to create a two-stage script.

getToken() (return Token)

rebuildCache(Token)

"We've boosted the Anti-Mass Spectrometer to 105 percent. Bit of a gamble, but we need the extra resolution."
CharliePatrier
Occasional Contributor

Thanks @A_Wyn_Jones it worked this way, very good outcome!

StaffanstorpsKommun
Occasional Contributor

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

A_Wyn_Jones
Esri Contributor

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!

https://developers.arcgis.com/rest/services-reference/online/vector-tile-rebuild-cache-feature-servi...

 

"We've boosted the Anti-Mass Spectrometer to 105 percent. Bit of a gamble, but we need the extra resolution."
0 Kudos
StaffanstorpsKommun
Occasional Contributor

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?

0 Kudos
A_Wyn_Jones
Esri Contributor

@StaffanstorpsKommun  Yes! My apologies, only for ArcGIS Online!

Got excited reading the WRONG documentation 😄 Mondays!

"We've boosted the Anti-Mass Spectrometer to 105 percent. Bit of a gamble, but we need the extra resolution."
0 Kudos
CharliePatrier
Occasional Contributor

 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')