Hi Zeno Team, you can do that doing something like this (for a Point Layer Type):
const YOUR_TOKEN = "<place your token here>";
const SERVICE_NAME = "<your service name>";
const HOST = "<the subdomain of your service>";
const INSTANCE = "<your instance id>";
const LAYER_NAME = "<your layer name>";
const layerDefinition = {
"layers": [
{
"currentVersion": 10.51,
"id": 0,
"name": LAYER_NAME,
"type": "Feature Layer",
"displayField": "",
"description": "",
"copyrightText": "",
"defaultVisibility": true,
"editingInfo": {
"lastEditDate": null
},
"relationships": [],
"isDataVersioned": false,
"supportsAppend": true,
"supportsCalculate": true,
"supportsTruncate": true,
"supportsAttachmentsByUploadId": true,
"supportsAttachmentsResizing": true,
"supportsRollbackOnFailureParameter": true,
"supportsStatistics": true,
"supportsAdvancedQueries": true,
"supportsValidateSql": true,
"supportsCoordinatesQuantization": true,
"supportsApplyEditsWithGlobalIds": false,
"advancedQueryCapabilities": {
"supportsPagination": true,
"supportsPaginationOnAggregatedQueries": true,
"supportsQueryRelatedPagination": true,
"supportsQueryWithDistance": true,
"supportsReturningQueryExtent": true,
"supportsStatistics": true,
"supportsOrderBy": true,
"supportsDistinct": true,
"supportsQueryWithResultType": true,
"supportsSqlExpression": true,
"supportsAdvancedQueryRelated": true,
"supportsCountDistinct": true,
"supportsLod": true,
"supportsReturningGeometryCentroid": false,
"supportsQueryWithDatumTransformation": true,
"supportsHavingClause": true,
"supportsOutFieldSQLExpression": true
},
"useStandardizedQueries": true,
"geometryType": "esriGeometryPoint",
"minScale": 0,
"maxScale": 0,
"extent": {
"xmin": -0.000004988163709640503,
"ymin": 2504688.542852979,
"xmax": 2504688.542843003,
"ymax": 5009377.085700966,
"spatialReference": {
"wkid": 102100
}
},
"allowGeometryUpdates": true,
"hasAttachments": false,
"htmlPopupType": "esriServerHTMLPopupTypeNone",
"hasM": false,
"hasZ": false,
"objectIdField": "OBJECTID",
"uniqueIdField": {
"name": "OBJECTID",
"isSystemMaintained": true
},
"globalIdField": "",
"typeIdField": "",
"fields": [
{
"name": "OBJECTID",
"type": "esriFieldTypeOID",
"alias": "OBJECTID",
"sqlType": "sqlTypeOther",
"nullable": false,
"editable": false,
"domain": null,
"defaultValue": null
},
{
"name": "Name",
"type": "esriFieldTypeString",
"actualType": "nvarchar",
"alias": "Name",
"sqlType": "sqlTypeNVarchar",
"length": 256,
"nullable": true,
"editable": true,
"visible": true,
"domain": null,
"defaultValue": null
}
],
"indexes": [],
"types": [],
"supportedQueryFormats": "JSON, geoJSON",
"hasStaticData": false,
"maxRecordCount": 2000,
"standardMaxRecordCount": 32000,
"tileMaxRecordCount": 8000,
"maxRecordCountFactor": 1,
"capabilities": "Query,Editing,Create,Update,Delete,Sync",
"syncEnabled": true,
"adminLayerInfo": {
"geometryField": {
"name": "Shape",
"srid": 102100
}
}
}
],
"tables": []
}
const settings = {
"url": `https://${HOST}.arcgis.com/${INSTANCE}/arcgis/rest/admin/services/${SERVICE_NAME}/FeatureServer/addToDefinition`,
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": {
"addToDefinition": JSON.stringify(layerDefinition),
"f": "json",
"token": YOUR_TOKEN
}
};
$.ajax(settings).done(function (response) {
console.log(response);
});
In November I wrote some documentation about how to work with hosted feature services through the REST API.
Best regards,
Raul