A feature layer can contain a large number of features. To access a subset of the features, you can execute a SQL or spatial query, or both at the same time. You can also return the attributes, geometry, or both attributes and geometry for each record. SQL and spatial queries are useful when a feature layer is very large and you just want to access a subset of the data.
In this tutorial, you access and query a hosted feature layer with a SQL where clause and only return the first record.
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 apiKey to use your key.
Make the request
Copy and paste the code below, following the steps to make a request to the feature service.
Reference the ArcGIS REST JS libraries either through CDN, ES Modules, or Node JS.
Set the apiKey with the API key from your dashboard.