I have had a py 2.7 script running for years that makes requests to the ESRI route service at https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve
Converting to requests library. It supplies a token and pre-built input params and makes the post request:
{'f': 'json', 'stops': {'features': [{'geometry': {'x': 863532.1692919674, 'y': 1030860.3483306282, 'spatialReference': {'wkid': 2881}}, 'attributes': {'CurbApproach': 'null', 'TimeWindowStart': 'null', 'TimeWindowEnd': 'null', 'Attr_Minutes': 0, 'Attr_TravelTime': 0, 'Attr_Miles': 0, 'Attr_Kilometers': 0, 'Attr_TimeAt1KPH': 0, 'Attr_WalkTime': 0, 'Attr_TruckMinutes': 0, 'Attr_TruckTravelTime': 0, 'Name': 'permitAppBoundary'}}, {'geometry': {'x': 623453.099237, 'y': 136924.166006, 'spatialReference': {'wkid': 2881}}, 'attributes': {'CurbApproach': 'null', 'TimeWindowStart': 'null', 'TimeWindowEnd': 'null', 'Name': 'MARATHON FS'}}]}, 'token': '7a6sZjdk8Xiit1VUsERtOGf4tEHskFAyZky3_LP8J1yggoKtkpp2cvFFDo5WP3bg6imUNra7cLZZ2B9yyKhJTnRl-fe0qxcD73vL_58lLSytF00nfhoXM6K0mbp7Vt2OISbhzTfjLlpa3Y2tI5K2j17Qq5o-JXO16Bcmx7KKlgpyhDlfxnhX34umWPIi2hEr', 'returnDirections': 'false'}
Same request made in Postman successful. I am running into a new error with the input above: {'error': {'code': 400, 'extendedCode': -2147024809, 'message': 'Invalid or missing input parameters.', 'details': ['Invalid input coordinates [features].']}}
Only difference is that now all input coordinates you see above are in WKID 2881 (whereas before all were supplied in 102100
Complete def:
def routeRequest(permitX, permitY, scX, scY, serviceCenter):
routeQueryURL = 'https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve'
params = {'f':'json',
'stops':{'features':[{
'geometry':{
'x':permitX,
'y':permitY,
'spatialReference':{
'wkid':2881
}
},
'attributes':{
'CurbApproach':'null',
'TimeWindowStart':'null',
'TimeWindowEnd':'null',
'Attr_Minutes':0,
'Attr_TravelTime':0,
'Attr_Miles':0,
'Attr_Kilometers':0,
'Attr_TimeAt1KPH':0,
'Attr_WalkTime':0,
'Attr_TruckMinutes':0,
'Attr_TruckTravelTime':0,
'Name':'permitAppBoundary'
}
},
{
'geometry':{
'x':scX,
'y':scY,
'spatialReference':{
'wkid':2881
}
},
'attributes':{
'CurbApproach':'null',
'TimeWindowStart':'null',
'TimeWindowEnd':'null',
'Name':serviceCenter
}
}
]},
'token':tokAGO,
'returnDirections':'false'}
r = requests.post(routeQueryURL, data = params, verify=False)
dataM = json.loads(r.content)
print (dataM)
stopName = dataM['routes']['features'][0]['attributes']['Name']
miles = dataM['routes']['features'][0]['attributes']['Total_Miles']
driveTime = dataM['routes']['features'][0]['attributes']['Total_TravelTime']
return miles, driveTime, stopName
Printing params value and sending same exact request/post using Postman succeeds.