Skip to main content

Creating an inspection

How to create an inspection

Inspections help you to schedule and record checks on the condition of your assets. Using the Alloy API, you can create an inspection against any asset that implements designInterfaces_tasksAssignable.

For more information, see:

Special logic

When an inspection is created using the Item endpoint, special logic is applied:

  • An inspection can only have one parent asset.

  • Typically, attributes_itemsGeometry is optional for an inspection. If you don't specify a value during creation, it will automatically be copied from the parent asset's attributes_itemsGeometry.

  • However, if attributes_itemsGeometry is required by the inspection's design, it must be specified during creation. It will not be copied from the parent asset.

  • If you don't specify a value for attributes_tasksRaisedTime during creation, it will automatically be set to the current date and time.

  • If you don't specify a value for attributes_tasksTeam, it will automatically be set to the same value as the parent asset's attributes_tasksTeam.

Example JavaScript

This example demonstrates how to create an inspection against an asset.

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

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

// the id of the asset you wish to create the inspection against
const parentID = '5dda8584ca315005f4be5061';

// request to create an item
axios({
method: 'POST',
url: `https://api.uk.alloyapp.io/api/item`,
headers: { Authorization: `Bearer ${apiKey}` },
data: {
// the design that you wish to create an inspection item from
// the design must implement designInterfaces_inspections
designCode: 'designs_exampleInspections',
// the collection that the new inspection will belong to
collection: 'Live',
// specify attributes for the new inspection item
attributes: [
// example check is a required attribute that's only present on
// the Example Inspections design used in this example
{
attributeCode: 'attributes_exampleInspectionsExampleCheck',
value: false,
},
// status is a required attribute
// IDs for Task Status items can be looked up in designs_taskStatuses
{
attributeCode: 'attributes_tasksStatus',
value: ['5bc5bdd281d088d177342c72'],
},
// inspection geometry is usually an optional attribute
// if not set then the parent asset's geometry will be used
// geometry must be provided in GeoJSON format
{
attributeCode: 'attributes_itemsGeometry',
value: {
type: 'Point',
coordinates: [-0.450338, 51.391263],
},
},
// related inspections is an optional attribute, so the value can be an empty array
// if required, link to related inspections by providing an array of item ids
{
attributeCode: 'attributes_inspectionsRelatedInspections',
value: [],
},
// attachments is an optional attribute, so the value can be an empty array
// if required, link to any File items by providing an array of item ids
{
attributeCode: 'attributes_filesAttachableAttachments',
value: [],
},
// description is an optional string attribute, so the value can be null
// if required, provide a description of the inspection
{
attributeCode: 'attributes_tasksDescription',
value: null,
},
// priority is an optional attribute, so the value can be an empty array
// IDs for task priority can be looked up in designs_taskPriorities
{
attributeCode: 'attributes_tasksPriority',
value: [],
},
// raised time is an optional string attribute, so the value can be null
// the value must be written in ISO 8601 format
{
attributeCode: 'attributes_tasksRaisedTime',
value: '2020-11-18T00:00:00.000Z',
},
// estimated start time is an optional string attribute, so the value can be null
// the value must be written in ISO 8601 format
{
attributeCode: 'attributes_tasksEstimatedStartTime',
value: null,
},
// estimated end time is an optional string attribute, so the value can be null
// the value must be written in ISO 8601 format
{
attributeCode: 'attributes_tasksEstimatedEndTime',
value: null,
},
// start time is an optional string attribute, so the value can be null
// the value must be written in ISO 8601 format
{
attributeCode: 'attributes_tasksStartTime',
value: null,
},
// completion time is an optional string attribute, so the value can be null
// the value must be written in ISO 8601 format
{
attributeCode: 'attributes_tasksCompletionTime',
value: null,
},
// target time is an optional string attribute, so the value can be null
// the value must be written in ISO 8601 format
{
attributeCode: 'attributes_tasksTargetTime',
value: null,
},
// cancelled time is an optional string attribute, so the value can be null
// the value must be written in ISO 8601 format
{
attributeCode: 'attributes_tasksCancelledTime',
value: null,
},
// raised jobs is an optional attribute, so the value can be an empty array
// if required, link to related jobs by providing an array of item ids
{
attributeCode: 'attributes_inspectionsRaisingJobsRaisedJobs',
value: [],
},
// raised defects is an optional attribute, so the value can be an empty array
// if required, link to related defects by providing an array of item ids
{
attributeCode: 'attributes_inspectionsRaisingDefectsRaisedDefects',
value: [],
},
// team is an optional attribute, so the value can be an empty array
// if required, provide the ID of a Teams item to assign the inspection to them.
// can't have multiple values
{
attributeCode: 'attributes_tasksTeam',
value: ['5df77624ca3150031446ba23'],
},
// team member is an optional attribute, so the value can be an empty array
// if required, provide the ID of a Team Members item to assign the inspection to them.
// can't have multiple values. can't be set if the team attribute is not set
{
attributeCode: 'attributes_tasksTeamMember',
value: ['5df7763dca3150031446ba29'],
},
],
parents: {
// set the parent asset that you're creating the inspection for
attributes_tasksAssignableTasks: [parentID],
// optionally add the inspection to a project by providing the project ID
attributes_projectsTasks: ['5fb7cac9253fd00065b3937a'],
},
// optional property, so the value can be null
// set to true to prevent the new inspection from being editable
locked: null,
},
})
.then((response) => {
// output the id of the new inspection item to the console
console.log(response.data.item.itemId);
})
.catch((error) => {
// output any error data to the console
console.log(error.response.data);
});