GraphQL endpoint
The Urban GraphQL API has a single public endpoint:
The endpoint remains the same for all Urban API GraphQL operations.
Form GraphQL calls
This section explains how to make requests to the GraphQL API. There are a few different ways to do it, namely:
- Send raw GraphQL queries with cURL
- Send raw GraphQL queries with GraphiQL
- Send raw GraphQL queries from JavaScript
- Use client libraries
Each subsection explains how to use the urban
query to list the id
and title
attributes of publicly accessible urban models. The server response should look something like this:
{
"data": {
"urbanModels": [
{
"id": "e57f2982d5e74885979c975a904a6148",
"title": "River Forest Urban Model"
},
{
"id": "9c8bd4c0f6384b1c919c3a65a215713f",
"title": "Utrecht"
},
{
"id": "0f4c1fc028aa43d5b57d20c5fe5bb9c4",
"title": "Grand-Lyon"
}
]
}
}
Note, that up to 10 models are returned by the server due to the default limit
. To return more models, change the limit
argument.
Send raw GraphQL queries with cURL
Use the following cURL command to retrieve a list of the IDs and names of all publicly visible urban models:
curl \
-X POST \
-H "Content-Type: application/json" \
--data '{ "query": "{ urbanModels { id title } }" }' \
https://urban-api.arcgis.com/graphql
Send raw GraphQL queries with GraphiQL
Open GraphiQL by loading the Urban API endpoint in a web browser. You can also explore GraphiQL in the API Reference section, which embeds the same GraphQL endpoint in the ArcGIS for developers webpage.
Use the following query to retrieve a list of the IDs and names of all publicly visible urban models:
query {
urbanModels {
id
title
owner
}
}
Send raw GraphQL queries from JavaScript
Alternatively, embed the following code snippet in a JavaScript code to send the same query to the server as in the examples above:
fetch("/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json"
},
body: JSON.stringify({ query: "{ urbanModels { id title } }" })
})
.then((r) => r.json())
.then((data) => console.log("data returned:", data));
Use client libraries
Client libraries will provide you with the fastest and most comprehensive way to access the API. They assist in formatting your requests and responses and simplify authentication handling. You can use the Urban API with any programming language and framework. See the official GraphQL list of the libraries in all sorts of languages.
Use the following code snippet to retrieve a list of the IDs and names of all publicly visible urban models using Python and the sqglc client library:
from sgqlc.operation import Operation
from sgqlc.endpoint.http import HTTPEndpoint
from urban_api_schema import urban_api_schema as schema
url = 'https://urban-api.arcgis.com/graphql'
op = Operation(schema.Query) # module operation generates Queries and Mutations
urban_models = op.urban_models
urban_models.id()
urban_models.title()
endpoint = HTTPEndpoint(url)
json_data = endpoint(op)
# add the JSON data to the operation to interpret the results and produce convenient objects
obj = op + json_data
urban_models_data = obj.urban_models
for urban_model in urban_models_data:
print(urban_model)
The above code snipet will print information about the urban models returned from the query, and will look similar to:
UrbanModel(id=fd45a15550cf4ea6b361e3c54c8d3ed1, title=Sample Urban Project)
UrbanModel(id=9dd5bed4a5b847c8a9feddeb410a5193, title=Modelo Curso ArcGIS Urban 2.0)
UrbanModel(id=e57f2982d5e74885979c975a904a6148, title=River Forest Urban Model)
See the Get started with Python sgqlc client library guide for more information.