Skip to main content

Editing an item

How to edit an item

You can edit the attributes and properties of an existing item in Alloy, providing its context is Customer and you have permission to do so.

If the item's context isn't Customer, you can still edit the item's color and icon properties, along with the values of any custom attributes that your organisation has added to the item's design. To check a design's attributes, use the Design endpoint (Swagger, ReDoc) and look for attributes with a context of Customer.

You must include the item's current signature in your edit request. This ensures that you're editing the item in its current state.

For more information, see:

Example JavaScript

This example demonstrates editing an item. In summary:

  1. Get the item's details by supplying its itemID.

  2. Store the item's current signature value.

  3. Submit an ItemEditWebRequestModel containing the signature and new values for the attributes/properties you want to edit.

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

// enter your api key here!
const apiKey = '7d781836-f04d-4f44-b68f-38319233d645';

// enter the item id to edit here!
const itemId = '5c6d3f95ff5c130e082402ba';

// first, we want to fetch the existing item to get its signature.
// if you already have a signature from an existing call, you can
// reuse it rather than make another request
axios({
method: 'GET',
url: `https://api.uk.alloyapp.io/api/item/${itemId}`,
headers: { Authorization: `Bearer ${apiKey}` },
})
.then((response) => {
// get the item's signature from the response. this acts as a checksum
// for consistent edits
const signature = response.data.item.signature;

// make a PUT request to edit the data of the item, specifying item id
return axios({
method: 'PUT',
url: `https://api.uk.alloyapp.io/api/item/${itemId}`,
headers: { Authorization: `Bearer ${apiKey}` },
// construct the ItemEditWebRequestModel model, this tells the server
// what we want to edit on the item
data: {
// which collection the item should be in
collection: 'Live',
// a valid GeoJSON geometry object, in this case a point in the UK
geometry: {
type: 'Point',
coordinates: [-2.2412109374999996, 52.66972038368817],
},
// optionally change the item's icon
icon: 'icon-search',
// optionally change the item's colour
colour: '#881100',
// the attributes you want to change
attributes: [
{
// an attribute requires its attribute code to identify it
attributeCode: 'attributes_exampleAttribute1',
// and the value you want to set
value: 'hello',
},
{
attributeCode: 'attributes_exampleAttribute2',
value: 100.1,
},
{
attributeCode: 'attributes_exampleAttribute1',
value: false,
},
],
// use the signature we acquired earlier
signature,
// optionally lock the item to prevent further editing until unlocked
locked: false,
},
});
})
.then((response) => {
// the response contains the updated item
const item = response.data.item;
// output the item's title to the console
console.log(`item "${item.itemId}" edited!`);
// 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);
});