Find items on a street
How to find all items on a street
The Alloy API includes endpoints for performing AQS queries. This lets you search for items of a particular design/interface that match specific criteria. A list of qualifying items is returned, containing the full details of each item.
For more information, see the Aqs endpoints on Swagger and ReDoc.
Example JavaScript
This example uses the Aqs Query endpoint to find assets located on either of two streets. In summary, the query says:
Find items that implement the Asset Heads interface, and where their networkReferenceableNetworkReferences
attribute links to a Network Reference item with an itemsTitle
attribute that contains either "Grendon Drive" or "Staveley Way".
// load a http request library
import axios from 'axios';
// enter your api key here!
const apiKey = 'e0e3a4ef-5ec8-4e05-ac25-a34adadf4a80';
// run the AQS (alloy query syntax) search
axios({
method: 'POST',
url: `https://api.uk.alloyapp.io/api/query`,
headers: { Authorization: `Bearer ${apiKey}` },
// specify the AQS model
data: {
// perform a query type search
type: 'Query',
properties: {
// search within the asset heads interface (root objects of an asset)
dodiCode: 'designInterfaces_assetHeads',
// get all the attributes for each qualifying item
attributes: ['All'],
},
children: [
{
// the query performs a keyword check - does the left child contain the right child?
type: 'WordSearch',
children: [
// the left side of the keyword check is the itemsTitle attribute, but
// not on the Asset Head items themselves. instead, the attribute is on
// the Network items that the Asset Head items link to, like so:
// Asset -> Network Reference -> Network
// to search an attribute on linked items, we have to use a path
{
type: 'Attribute',
properties: {
// specify the attribute code of the attribute to search on
// the attribute below is on the Network interface, as we want
// to search for a linked Network item with a certain title
attributeCode: 'attributes_itemsTitle',
// to search in a different context than the root, we need to
// use AQS path syntax. A path is already defined below. A path always
// starts with "root" and navigation is made by using "." to go down
// a linked attribute path or "^" to go up an attribute path (to its parents)
// in our example, networkReferenceableNetworkReferences is an
// attribute on the Asset Heads design, so it's a child hop. We then do
// a parent hop to travel up the networksNetworkReferences attribute
// to any referenced Network items.
// a Network References item has parent links to 1 Network Referenceable item
// and one network item. A network referenceable item can have 0-many network
// references. Likewise a network can have 0-many network references
path: 'root.attributes_networkReferenceableNetworkReferences^attributes_networksNetworkReferences',
},
},
// the right side of the keyword check is a string.
// this is the keyword(s) you want to search for on the Title of the Network items
// linked from the Asset Heads items being queried.
{
type: 'String',
properties: {
// an array of string values to match on, passing multiple
// values return any that match
values: ['Grendon Drive', 'Staveley Way'],
},
},
],
},
],
},
})
.then((response) => {
// output the results to the console (the data of each qualifying Asset Heads item)
response.data.results.forEach((item) => {
console.log(`item "${item.itemId}" found`);
});
})
.catch((error) => {
// output any error data to the console
console.log(error.response.data);
});