Select to view content in your preferred language

ArcGIS Enterprise REST API to GenerateToken (require login Error)

285
0
2 weeks ago
DavidLovesArcGIS
Occasional Contributor

Hi ArcGIS community,

We are using GenerateToken REST API to authenticate for append REST API. 90% of the time the token works to authenticate to append REST API, but 10% of the time it fails with this text when calling append API:

'<!DOCTYPE html>\n<html>\n<head>\n  <script src="login/config/dojo.js"></script>\n  <script src="jsapi/dojo/dojo.js"></script>\n  <script>\n    require(["login", "dojo/domReady!"], function(login) {\n      login.run();\n    });\n  </script>\n</head>\n<body>\n</body>\n</html>\n'

We are not 100% sure what this text means, but we think it means that authentication does no longer work to FeatureServer append API. 

 Current setup (ArcGIS Enterprise 11.3):

1. GenerateToken API

response = requests.post(
    url="https://arcgis.{company}.com/portal/sharing/rest/generateToken",
    data={
        "username": self.service_account_name,
        "password": self.service_account_password,
        "f": "json",
        "client": "referer",
        "expiration": 1000,
        "referer": "https://arcgis.{company}.com/portal"
    }
)
token=json.loads(response.text)["token"]

We tried to use ip and requestip as client, but they did not work at all. Referer atleast works in 90% of calls. So for now we use referer as client. 

2. FeatureServer append API

url = 'https://arcgis.{company}.com/hosting/rest/services/Hosted/{table_name}/FeatureServer/0/append
data = {'f': 'json', 'edits': '{"layers": [{"featureSet": {"spatialReference": {"latestWkid": 4326}, "features": [{}]}', 'upsert': True, 'upsertMatchingField': 'mgt_key', 'fieldMappings': "[]", 'appendFields': "[]", 'token': token}
response = requests.post(url, data=data)

We setup mechanism to get new token when FeatureServer append API fails, but this does not help. It would still give same html text as response where login is required. We want to access these APIs both from Windows and Linux systems for integration with other systems.

Does anyone have better way to provide token to FeatureServer Append API on ArcGIS Enterprise, which is more stable?

 

0 Replies