I'm trying to create a new hosted feature layer in Portal (ArcGIS Enterprise 10.9) by making a series of calls to the REST API.
What I've tried:
1. POST to https://{mydomain}/portal/generateToken
This is working. I send valid credentials and get a token in return. I use the received token in the following requests.
2. POST to https://{mydomain}/portal/sharing/rest/content/users/{username}/createService?token={token}
This is working. I see the new empty service in the user's content in Portal.
The createService parameter contains the following JSON
{
"name": "Test11",
"serviceDescription": "this is a test",
"hasStaticData": false,
"maxRecordCount": 10000,
"supportedQueryFormats": "JSON",
"capabilities": "Create,Delete,Query,Update,Editing",
"description": "this is a test",
"copyrightText": null,
"spatialReference": {
"wkid": 102100
},
"initialExtent": null,
"allowedGeometryUpdate": true,
"units": "esriMeters",
"xssPreventionInfo": {
"xssPreventionEnabled": true,
"xssPreventionRule": "input",
"xssInputRule": "rejectInvalid"
}
}
After visiting the new service's Overview page in Portal, I use it's URL to build the next request....
3. POST to https://{mydomain}/server/rest/services/Hosted/Test11/FeatureServer/addToDefinition?f=json&token={token}
I add a url encoded key/value pair to the above request body named "addToDefinition" as described in this documentation.
{
"layers": [
{
"id": 0,
"name": "TestLayer01",
"type": "Feature Layer",
"defaultVisibility": true,
"supportedQueryFormats": "JSON",
"capabilities": "Create,Delete,Query,Update,Editing,Extract,Sync",
"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
}
]
}
]
}This is not working. Although I get a 200 response, the response body simply contains the empty service's info. No new feature layer has been added to the empty service in portal.
Do I have the request URL wrong, or do I need to include some additional properties in the JSON structure?