I found the problem(s). Unfortunately the documentation does not specify which of the ump-teen properties of "addToDefinition" are required. I've been able to figure them out by trial and error. If anyone else runs into this, here's how I fixed it.
1. First, the request URL was indeed wrong. It needs to be https://{mydomain}/server/rest/admin/services/Hosted/Test11/FeatureServer/addToDefinition?f=json&token={token}
2. After fixing the URL and resending, I got this error:
{
"error": {
"code": 500,
"message": "\"objectIdField\" attribute was not passed in the service definition and SDS did not discover a suitable field.",
"details": []
}
}
The above error indicated that my request JSON addToDefinition object was missing the "objectIdField" property which specifies which of the fields is the objectID. Updating the original request JSON to include the missing property resolves this error.
{
"layers": [
{
"id": 0,
"name": "TestLayer01",
"type": "Feature Layer",
"defaultVisibility": true,
"supportedQueryFormats": "JSON",
"capabilities": "Create,Delete,Query,Update,Editing,Extract,Sync",
"objectIdField": "FID",
"fields": [
{
"name": "FID",
"type": "esriFieldTypeInteger",
"actualType": "int",
"alias": "FID",
"sqlType": "sqlTypeInteger",
"length": 4,
"nullable": false,
"editable": false,
"domain": null,
"defaultValue": null
},
{
"name": "CATEGORY",
"type": "esriFieldTypeString",
"actualType": "nvarchar",
"alias": "CATEGORY",
"sqlType": "sqlTypeNVarchar",
"length": 40,
"nullable": true,
"editable": true,
"domain": null,
"defaultValue": null
}
]
}
]
}
3. Next it complained about the "type" property assigned to the object ID field (which in this case is FID).
{
"error": {
"code": 500,
"message": "Wrong type of the ObjectID field.",
"details": []
}
}
ESRI has a typo in their documentation examples. I needed to change the FID field definition from this...
"type": "esriFieldTypeInteger"
to this...
"type": "esriFieldTypeOID"
4. Next it complained about the missing geometryType property.
{
"error": {
"code": 500,
"message": "JSONObject[\"geometryType\"] not found.",
"details": []
}
}
So I added "geometryType": "esriGeometryPoint" to the layer definition and kept going.
5. Now it's mad that I didn't specify and extent....
{
"error": {
"code": 500,
"message": "JSONObject[\"extent\"] not found.",
"details": []
}
}
This one is particularly annoying because I don't necessarily know what my extent will be yet, but since it's a required property I borrowed the extent object from the example in the docs. Moving on...
6. And lastly, it requires the "hasAttachments" property. I set mine to false and resubmitted. Finally some joy.
{
"success": true,
"layers": [
{
"name": "TestLayer01",
"id": 0
}
]
}
The final request JSON that succeeded is below. I think this may be the absolute minimum that's required, although there are many more properties that can be added.
{
"layers": [
{
"id": 0,
"name": "TestLayer01",
"type": "Feature Layer",
"defaultVisibility": true,
"supportedQueryFormats": "JSON",
"capabilities": "Create,Delete,Query,Update,Editing,Extract,Sync",
"geometryType": "esriGeometryPoint",
"hasAttachments": false,
"extent": {
"xmin": -13090714.767112788,
"ymin": 3841739.0914657288,
"xmax": -12922032.654624918,
"ymax": 3962581.2727843975,
"spatialReference": {
"wkid": 102100,
"latestWkid": 3857
}
},
"objectIdField": "FID",
"fields": [
{
"name": "FID",
"type": "esriFieldTypeOID",
"actualType": "int",
"alias": "FID",
"sqlType": "sqlTypeInteger",
"length": 4,
"nullable": false,
"editable": false,
"domain": null,
"defaultValue": null
},
{
"name": "CATEGORY",
"type": "esriFieldTypeString",
"actualType": "nvarchar",
"alias": "CATEGORY",
"sqlType": "sqlTypeNVarchar",
"length": 40,
"nullable": true,
"editable": true,
"domain": null,
"defaultValue": null
}
]
}
]
}