Here are some resources I found helpful
ArcGIS REST API
Quick Tips: Consuming Feature Services with Geoprocessing | ArcGIS Blog
Here's the code I put together to do a simple data download. Note, this was tested with 10.2.2, which does not support resultOffset and resultRecordCount request parameters for pagination so you will be limited to 1000 records at a time.
import arcpy
import urllib
def main():
svc_lyr_url = "http://somedomain.com/arcgis/rest/services/MapServiceName/MapServer/0"
where_clause = "objectid<100"
field_names = ""
try:
svc_lyr_response = urllib.urlopen(svc_lyr_url)
print svc_lyr_response
if svc_lyr_response.getcode() == 200:
query_url = "{}/query?where={}&outFields={}&returnGeometry=true&f=json".format(
svc_lyr_url,
where_clause,
field_names,
)
try:
query_response = urllib.urlopen(query_url)
print query_response
if query_response.getcode() == 200:
print "http code {} from {}".format(svc_lyr_response.getcode(), query_response.geturl())
fs = arcpy.FeatureSet()
fs.load(query_url)
arcpy.env.overwriteOutput = True
arcpy.CopyFeatures_management(fs, r"C:\temp\TEMP.gdb\SampleDownload")
print arcpy.GetMessages()
else:
response_msg = "http code {} from {}".format(
query_response.getcode(),
query_response.geturl()
)
raise Exception(response_msg)
finally:
query_response.close()
else:
response_msg = "http code {} from {}".format(
svc_lyr_response.getcode(),
svc_lyr_response.geturl()
)
raise Exception(response_msg)
finally:
svc_lyr_response.close()
if __name__ == '__main__':
main()