In this tutorial, you access a hosted feature layer and get its properties such as the id, name, type, supported capabilities, drawing information, extent, and fields.
Learn more about hosted feature layers in Data hosting in the Mapping APIs and location services guide.
Prerequisites
You need an ArcGIS Developer or ArcGIS Online account to access the developer dashboard and create an API key.
Steps
Create a new pen
- If you are using the CDN libraries, to get started.
Get an API Key
To access location services, you need an API key or OAuth 2.0 access token. To learn how to create and scope your key, visit the Create an API key tutorial.
- Go to your dashboard to get an API key. The API key must be scoped to access the services used in this tutorial.
- In CodePen, update
api
to use your key.Key
Add code to get layer metadata
Copy and paste the code below, following the steps to make a request to the feature service.
-
Set the
api
with the API key from your dashboard.Key -
Define the parameters needed for the request.
-
Call the feature service and handle the results.
<!-- require ArcGIS REST JS libraries from https://unpkg.com -->
<script src="https://unpkg.com/@esri/arcgis-rest-request@4.0.0/dist/bundled/request.umd.js"></script>
<script>
/* when including ArcGIS REST JS all exports are available
from the same arcgisRest global */
const apiKey = "YOUR_API_KEY";
const authentication = arcgisRest.ApiKeyManager.fromKey(apiKey);
arcgisRest
.request("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads_Styled/FeatureServer/0", {
authentication
})
.then((response) => {
console.log(response);
document.getElementById("result").textContent = JSON.stringify(response, null, 2);
});
</script>
Result
Below is the response from the service:
{
"currentVersion": 11,
"id": 0,
"name": "Trailheads_Styled",
"type": "Feature Layer",
"serviceItemId": "2e4b3df6ba4b44969a3bc9827de746b3",
"cacheMaxAge": 30,
"displayField": "",
"description": "",
"copyrightText": "",
"defaultVisibility": true,
"editingInfo": {
"lastEditDate": 1556814539714,
"schemaLastEditDate": 1556814539714,
"dataLastEditDate": 1556814539714
},
"relationships": [],
"isDataVersioned": false,
"hasContingentValuesDefinition": false,
"supportsAppend": true,
"supportsCalculate": true,
"supportsASyncCalculate": true,
"supportsTruncate": true,
"supportsAttachmentsByUploadId": true,
"supportsAttachmentsResizing": true,
"supportsRollbackOnFailureParameter": true,
"supportsStatistics": true,
"supportsExceedsLimitStatistics": true,
"supportsAdvancedQueries": true,
"supportsValidateSql": true,
What's next?
Learn how to use additional ArcGIS location services in these tutorials: