Skip to main content

Fetch an item

How to fetch an item and use its data

An item can be a variety of things, depending on the type of data you’re accessing. Within a road network, an item is a length of carriageway. In the Jobs layer, an item is a job. In some cases, an item is a lookup option in a data field.

To fetch an item from the database, you must provide its itemID. For more information, see:

Example JavaScript

This example fetches an item by its itemID and then outputs its attributes to the console like so:

> item "5c6be12894010e6b60b0bff1" found!
> attribute "attributes_streetLightsUnitNumber" = 001
> attribute "attributes_assetNetworkReferences" = [...]

// load a http request library
const axios = require('axios');

// enter your api key here!
const apiKey = 'e0e3a4ef-5ec8-4e05-ac25-a34adadf4a80';

// enter the id of the item to fetch
const itemId = '5c6be12894010e6b60b0bff1';

// fetch an item by its id
axios({
method: 'GET',
url: `https://api.uk.alloyapp.io/api/item/${itemId}`,
headers: { Authorization: `Bearer ${apiKey}` },
})
.then((response) => {
const item = response.data.item;
// output the item's id to the console
console.log(`item "${item.itemId}" found!`);
// output each of the item's attributes to the console
item.attributes.forEach((a) => {
console.log(`attribute "${a.attributeCode}" = ${a.value}`);
});
})
.catch((error) => {
// output any error data to the console
console.log(error.response.data);
});