Skip to main content
Version: v4.5

IafItemSvc

Use the IafItemSvc API to create and manage item service resources in the Item Service.

addRelatedToItem#

Adds RelatedCollection class objects to a NamedCompositeItem, which is a collection of varied NamedUserItem classes, including collection classes.

ParameterRequiredTypeDescription
compIdYesStringThe NamedCompositeItem's id. Pass either the _userItemId or the MongoDB ObjectId.
userItemsYesRelatedCollectionPass the array of RelatedCollection objects you want to add
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo add RelatedItem objects to a specific NamedCompositeItem version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value.
Returns

Promise<Page<RelatedCollection>> - A Page object with RelatedCollection objects

Examples
//Add tipversions of related collections to tip version of composite itemlet relatedCollections = [  { _userItemId: '5dcab6acfa877736bb1c5311' },  { _userItemId: '5dcab6acfa877736bb1c5313' },  { _userItemId: '5dcab6adfa877736bb1c5317' } ];
let res = await IafItemSvc.addRelatedToItem(compositeItems._id, relatedCollections, ctx);
// Add particular versions of related collections to tip version of composite itemlet relatedCollections = [ {   _userItemId: '5dcbbd24f16c872134947df2',   _userItemVersionId: '5dcbbd28f16c872134947dfb' }, {   _userItemId: '5dcbbd24f16c872134947df4',   _userItemVersionId: '5dcbbd28f16c872134947dfa' }];
let res = await IafItemSvc.addRelatedToItem(compositeItems._id, relatedCollections, ctx);
// Add related collections to particular version of composite itemlet relatedCollections = [  {    _userItemId: '5dcbbd24f16c872134947df2',    _userItemVersionId: '5dcbbd28f16c872134947dfb'  },  {    _userItemId: '5dcbbd24f16c872134947df4', // considers tip version  }];
let res = await IafItemSvc.addRelatedToItem(compositeItems._id, relatedCollections, ctx, {userItemVersionId: "45cab6acfa877736bb1c5323"});

addRelations#

Creates a new relationship between an item in one NamedUserCollection that you define as a parent with one or more items in another NamedUserCollection that you define as the child item or items.

ParameterRequiredTypeDescription
cidYesStringThe parent NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
relationshipsYesArray<Relationship>Pass a Relationship object that defines the relationship
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo create a relationship between related items in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To create a relationship in the tip version, do not pass an options parameter.
Returns

Promise<String> - Ok: 204 response

Examples
// Add children to tip version of parentlet relationShips = [  {    _relatedFromId: container._id, // The parent item's id    _relatedToIds: relatedToIds, // The child item ids    _relatedUserItemDbId: childUserCollection._id  // The child item collection id  }];
let relations = await IafItemSvc.addRelations(parentCollection._id, relationShip);
// Add children to specific version of parent
let relationShips = [  {    _relatedFromId: container._id, // The parent id    _relatedToIds: relatedToIds, // The child item ids    _relatedUserItemVersionId: childUserCollection._versions[2]._id, //The particular version of the collection that contains the new child item or items.     _relatedUserItemDbId: userCollection._id  // The child item collection id  }];
let relations = await IafItemSvc.addRelations(parentCollection._id, relationShips, {"userItemVersionId":"5dafd77d6f2d3a4dcc55f90a"});

addRelationsBulk#

Bulk creates new relationships between RelatedItems in one NamedUserCollection that you want to define as a parent with one or more RelatedItems in another NamedUserCollection that you want to define as the child item or items. To do this, pass an array of Relationship objects.

ParameterRequiredTypeDescription
cidYesStringThe named user collection id of the item you want to define as the parent. Pass either the _userItemId or the MongoDB ObjectId.
bodyYesArray<Relationship>The array of relationship objects. Do not pass an array that totals more than 10 MB in memory.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoUserCollectionBulkOperationOptionsTo relate a specific version of items, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To relate items in the tip version, do not pass an options parameter.
Returns

Promise<String> - Ok: 204 response

Examples
let parentCollection = "6336c490017d84b0a506e45d";
let relationShips = [  {    “_relatedUserItemDbId”: "6336c490017d84b0a506e438",    “_relatedFromId”: “6336c490017d84b0a506e439”    “_relatedToIds”: [“6336c490017d84b0a506e43a”],     “_relatedUserType”: “example_col”,    “_userType”: “example_rel”,  },  {    “_relatedUserItemDbId”: "6336c490017d84b0a506e43b",    “_relatedFromId”: “6336c490017d84b0a506e43c”    “_relatedToIds”: ["65afd19364353a4dcc55f53c", "5dafd1936f2d3a4dcc55f8fa"],     “_relatedUserType”: “example_col”,    “_userType”: “example_rel_2”,  }];
await IafItemSvc.addRelationsBulk(parentCollection, relationShips);

aggregateReadings#

Execute an aggregation query on Reading objects.

ParameterRequiredTypeDescription
cidYesStringPass either a NamedTelemetryCollection's ObjectId or _userItemId.
aggregationsYesArrayArray of aggregation stages
ctxYesCtxContext, such as authorization token requirements, namespaces, or session storage
optionsYesItemsvcOptionsIf you want to lookup in a specific collection version rather than the tip version, pass a ItemsvcOptions object with a "userItemVersionId" property and value. To create items in the tip version, do not pass an options parameter.
Returns

Promise<Object> - Aggregation results

Examples
let aggs = [  {    "$match": {      "$and": [        {          "_tsMetadata.type": {            "$exists": true          }        }      ]    }  },  {    "$setWindowFields": {      "partitionBy": "$_tsMetadata.type",        "sortBy": {          "_ts": 1        },        "output": {          "averageValWitinMins": {            "$avg": "$val",              "window": {                "range": [                  -30,                  30                ],              "unit": "second"            }          }        }      }   }  ];
const readingAgg = await IafItemSvc.aggregateReadings(container._id, aggs, ctx, options);
//Sample response{  "_list": [    {      "val": 871,      "_tsMetadata": {        "_sourceId": "7939bdd1-de6e-4247-93f7-9e0c9c09537a",        "type": "37e51a11-ac60-424f-8f51-4a9e4bcad0fd"      },      "_id": "645bca63f8b8a87c0f075cea",      "averageValWitinMins": 696,      "_ts": "Wed May 10 22:16:26 IST 2023"    }  ]}

createIndex#

Creates indexes for a NamedUserCollection.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
bodyYesArray<Index>Pass an array of Index objects you define
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo create indexes for a specific collection version rather than the tip version, pass a UserCollectionOptions object with a userItemVersionId property and value. To create indexes in the tip version, do not pass an options parameter.
Returns

Promise<Page<JSON>> - The NamedUserCollection's database indexes you create

Examples
let indexes = [  {    "key": {      "dtCategory": "text",      "dtType": "text"    },    "options": {      "name": "dtCategory_dtType_full_text",      "default_language": "english"      }  }];
let res = await IafItemSvc.createIndex(userCollection._id, indexes, ctx);

createNamedUserItems#

Creates a NamedUserItem class object in the Item Service from the NamedUserItem you define.

ParameterRequiredTypeDescription
namedUserItemsYesArray<NamedUserItem>Pass an array of JSON objects with the NamedUserItem properties and values you want to define the named user item.
itemClassNameYesItemClassEnter one of the following item classes as a string: NamedUserCollection, NamedFileCollection, NamedTelemetryCollection, UserConfig, Script, NamedCompositeItem.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoItemSvcOptionsTo make the action transactional, pass a ItemSvcOptions object with a "transactional" property and set its value to true.
Returns

Promise<Page<NamedUserItem>> - Created NamedUserItem objects in a Page object

Examples
const telementaryCollection =  await IafItemSvc.createNamedUserItems(    [      {        _name: "Named Telemetry Collection",        _shortName: "telementary_coll",        _description: "Named Telemetry Collection to store sensor and points data",        _namespaces: project._namespaces,        _userType: "ref_app_telementary_collection",      },    ],    "NamedTelemetryCollection",    ctx  );

createNamedUserItemVersion#

Creates a NamedUserItemVersion class object.

ParameterRequiredTypeDescription
userItemIdYesStringThe NamedUserItem's id. Pass either the _userItemId or the MongoDB ObjectId.
versionYesNamedUserItemVersionPass a NamedUserItemVersion object with properties and values you define
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoItemsvcOptionsTo make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true.
Returns

Promise<NamedUserItemVersion> - The creted NamedUserItemVersion object

Examples
const version = {   _userAttributes: {     folderName: "Warranty Docs"   }};
const newVersion = await IafItemSvc.createNamedUserItemVersion(item._id, version);

createPermissions#

Creates an array of Permission class objects for NamedUserItem class objects.

ParameterRequiredTypeDescription
permissionsYesArray<Permission>Pass an array of Permission objects you define
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
Returns

Promise<CreatePermissionsResponse> - A CreatePermissionsResponse object with an array of successful permissions and an array of failed permissions

Examples
// Permissions with mandatory fieldslet permissions = [{  _actions: [  IafPermission.PermConst.Action.Read, IafPermission.PermConst.Action.Share, IafPermission.PermConst.Action.Delete],  _namespace: "ProjA_HEpftR8X",  _resourceDesc:{    _irn: IafPermission.NamedUserItemIrnAll  },  _user:{    _id: "75b2a3d6-a3e8-498d-99dc-23538bc9a389", // Either user or usergroup id, specify respective _type    _type: IafPermission.PermConst.UserType.User // Either user or usergroup, specify respective _id  }}];
let result = IafItemSvc.createPermissions(permissions, ctx);
// Permissions with criteria.let permissions = [{  _actions: [IafPermission.PermConst.Action.Read, IafPermission.PermConst.Action.Share, IafPermission.PermConst.Action.Delete],  _namespace: "ProjA_HEpftR8X",  _resourceDesc:{    _irn": IafPermission.NamedUserItemIrnAll,    _criteria: {       _userType: "Project_Setup_Config"    }  },  _user:{    _id: "6336c490017d84b0a506e44d", // Either user or usergroup id, specify respective _type    _type: IafItemSvc.PermConst.UserType.User // Either user or usergroup, specify respective _id  }}];
let result = IafItemSvc.createPermissions(permissions, ctx);

createRelatedItems#

Creates RelatedItem class objects in a NamedUserCollection. RelatedItems are items in NamedUserCollections that have the potential to relate to other items. If the total memory of the items you want to relate exeeds 1 MB or you want to relate more that 100 items, use the createRelatedItemsBulk method.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the MongoDB ObjectId or _userItemId.
bodyYesArray<RelatedItem>Pass an array RelatedItem objects you want to create.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoUserCollectionOptionsIf you want to create RelatedItems in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To create items in the tip version, do not pass an options parameter.
Returns

Promise<Array<RelatedItem>> - An array of RelatedItem objects that each contain an _id property

Examples
// Create RelatedItems with the current version of NamedUserCollectionlet relatedItems = [ {   "source_index": "accounts-4",   "source_id": 2038 }, {   "source_index": "accounts-2",   "source_id": 2036 }];
let res = await IafItemSvc.createRelatedItems('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx);
// Create RelatedItems as a specific version of NamedUserCollectionlet options = {userItemVersionId: "5dafd1936f2d3a4dcc55f8fb"}let res = await IafItemSvc.createRelatedItems('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx, options);
//Create related items with relationshiplet relatedItems = [ {   "source_index": "accounts-4",   "source_id": 2038,   "_relationships":{     "_relatedUserItemDbId": "5cee7fee6505d6286dbca469",     "_relatedUserItemVersionId": "5cee80c1fa298d0d3e34e23b", // Optional, if its not given tip version of _relatedUserItemDbId would be taken     "_relatedToIds": [       "5cee7fe8c27e69cd0209ef46",       "5cee7fe8c27e69cd0209ef47",       "5cee7fe8c27e69cd0209ef48"     ]   } }];
let res = await IafItemSvc.createRelatedItems('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx);

createRelatedItemsBulk#

Bulk creates RelatedItems in a NamedUserCollection. RelatedItems are items in NamedUserCollection that have the potential to relate to other items. Use this method instead of the createRelatedItems() method if the total memory of the items you want to create exeeds 1 MB or you want to create more that 100 items, use the createRelatedItemsBulk method.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
bodyYesArray<RelatedItem>Pass an array RelatedItem objects you want to create.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoUserCollectionBulkOperationOptionsIf you want create related items in a specific collection version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To create items in the tip version, do not pass an options parameter.
Returns

JSON - A JSON object with "_createdCount" and "_uris" properties for each related item

Examples
// Bulk create related items with the current version of named user collectionlet relatedItems = [ {   "source_index": "accounts-4",   "source_id": 2038 }, {   "source_index": "accounts-2",   "source_id": 2036 }];
let res = await IafItemSvc.createRelatedItemsBulk('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx);
// Bulk create related items to a specific version of named user collectionlet options = {userItemVersionId: "5dafd1936f2d3a4dcc55f8fb"}let res = await IafItemSvc.createRelatedItemsBulk('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx, options);
//Create related items with relationshiplet relatedItems = [ {   "source_index": "accounts-4",   "source_id": 2038,   "_relationships":{     "_relatedUserItemDbId": "5cee7fee6505d6286dbca469",     "_relatedUserItemVersionId": "5cee80c1fa298d0d3e34e23b", // Optional, if its not given tip version of _relatedUserItemDbId would be taken     "_relatedToIds": [       "5cee7fe8c27e69cd0209ef46",       "5cee7fe8c27e69cd0209ef47",       "5cee7fe8c27e69cd0209ef48"     ]   } }];
let res = await IafItemSvc.createRelatedItemsBulk('5dafd1936f2d3a4dcc55f8fb', relatedItems, ctx);

createRelatedReadingItems#

Creates Reading class objects as related Readings.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id, which can be either a MongoDB ObjectId or _userItemId.
readingsYesArray<Readings>Array of Reading objects
ctxYesCtxContext, such as authorization token requirements, namespaces, or session storage
optionsYesItemsvcOptionsIf you want to lookup in a specific NamedUserCollection version rather than the tip version, pass a ItemsvcOptions object with a "userItemVersionId" property and value. To create items in the tip version, do not pass an options parameter.
Returns

Promise<Page<Readings>> - A promise with a page of created Readings

Examples
await IafItemSvc.createRelatedReadingItems(collection._id, readingsArray, ctx, undefined);

createTelemetryConfig#

Posts a TelemetryConfig to the Item Service when you pass your TelemetryConfig definition.

ParameterRequiredTypeDescription
telemetryConfigYesundefined
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoItemSvcOptionsTo make the action transactional, pass a ItemSvcOptions object with a "transactional" property and set its value to true.
TelemetryConfigYesTelemetryConfigPass a TelemetryConfig object with your bindings criteria.
Returns

Promise<Page<TelemetryConfig>> - Returns the created TelemetryConfig objects in a Page object

Examples
const telemConfig = await IafItemSvc.createTelemetryConfig({    _namespaces: [      "lnt_bkJUK1W3"    ],    _shortName: "telconfig",    _name: "Project A Telemetry Config",    _userType: "telemetry_config",    _configData: {      _normalizationScript: {        _userType: "telemetry_parser_script"      },      _bindings: {        collectionDesc: {          _userItemId: "lnt_sensors__MogUhzsHhY"        },        query: {          "sensor_type": "co2"        }      }    }  },  ctx,  undefined);

deleteNamedUserItem#

Deletes a NamedUserItem by when you pass its id

ParameterRequiredTypeDescription
idYesStringThe NamedUserItem's id
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoItemsvcOptionsTo make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true.
Returns

Promise<String> - Ok: 204 response

Examples
const deletedItem = IafItemSvc.deleteNamedUserItem(item._id, ctx, undefined);

deleteNamedUserItemVersion#

Deletes a NamedUserItemVersion.

ParameterRequiredTypeDescription
userItemIdYesStringThe NamedUserItem's id. Pass either the _userItemId or the MongoDB ObjectId.
versionIdYesStringThe NamedUserItem's _version property value
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoItemsvcOptionsTo make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true.
Returns

Promise<String> - 204 response {ok:204}

Examples
await IafItemSvc.deleteNamedUserItemVersion(item._id, item.versions[3]._id);

deletePermission#

Deletes a Permission class object.

ParameterRequiredTypeDescription
idYesStringThe Permission object's id
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
Returns

Promise<String> - Ok:204

Examples
const res = await IafItemSvc.deletePermission(permisssion._id, ctx);

deleteRelatedItem#

Deletes a RelatedItem when you pass its id and the id of its related NamedUserCollection.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
itemIdYesStringThe RelatedItem's id
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo delete a related item from a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To delete items in the tip version, do not pass an options parameter.
Returns

Promise<String> - Ok: 204 response

Examples
await IafItemSvc.deleteRelatedItem(collection._id, item._id, ctx, undefined);

deleteRelatedItems#

Deletes more than one RelatedItem in a NamedUserCollection.

ParameterRequiredTypeDescription
cidYesStringThe named user collection's id. Pass either the _userItemId or the MongoDB ObjectId.
relatedItemIdsYesArray<String>Pass an array of the RelatedItems' ids.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoUserCollectionOptionsTo delete related items in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To delete items in the tip version, do not pass an options parameter.
Returns

Promise<String> - Ok: 204 response

Examples
await IafItemSvc.deleteRelatedItems(collection._id, relatedItemIdsToDel, ctx);

deleteRelatedItemsBulk#

Bulk deletes RelatedItems in an NamedUserCollection that match a query you pass. Lookup related items by userItemVersionId or tip version id.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
criteriaYesRelatedItemCriteriaFilter criteria
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsYesUserCollectionBulkOperationOptionsIt contains options such as userItemVersionId
Returns

Promise<String> - ok: 204 response

Examples
// Delete RelatedItems by criteria from tip versionawait IafItemSvc.deleteRelatedItemsBulk(userCollectionId, {query:{"assetType": "door", "floor": 2}}, ctx, options);
// Delete RelatedItems by criteria from specific versionlet options = {userItemVersionId:"5dafd1936f2d3a4dcc55f8fa"};let relatedItems = await IafItemSvc.deleteRelatedItemsBulk(userCollectionId, {query:{"assetType": "door", "floor": 2}}, ctx, options);

deleteRelationInItem#

Deletes a RelatedCollection relationship between a NamedCompositeItem and a NamedUserItem.

ParameterRequiredTypeDescription
compIdYesStringThe NamedCompositeItem's id. Pass either the _userItemId or the MongoDB ObjectId.
relatedCollectionIdYesStringThe RelatedCollection's id
ctxYesCtsContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo delete a specific RelatedCollection version rather than the tip version, pass a UserCollectionOptions object with a userItemVersionId property and value.
Returns

Promise<String> - ok: 204 response

deleteRelations#

Deletes relationships for multiple parent RelatedItems in the same NamedUserCollection.

ParameterRequiredTypeDescription
cidYesStringThe id or _userItemId of the NamedUserCollection that contains the parent RelatedItem.
bodyYesArray<RelationShip>An array of the Relationship objects you want to delete. Each relationship object must contain the following properties: "_relatedFromId", "_relatedToIds", and "_relatedUserItemDbId" or "_relatedUserItemId".
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo delete a specific version of relationship rather than the tip version, pass a UserCollectionOptions object with a userItemVersionId property and value.
Returns

Promise<String> - ok: 204 response

Examples
let body = [  {    "_relatedFromId": "4553e105026300398e2d6533",    "_relatedToIds": ["5323e106786312398e2d653e"],    "_relatedUserItemDbId": "6333e105026300398e2d653e",    "_relatedUserItemVersionId": "8763e109456300398e2d623a"  },  {    "_relatedFromId": "6854e1657842596e2d6647",    "_relatedToIds": ["9468e3645825555e9d693e"],    "_relatedUserItemDbId": "6478e986545723548e2d687e",    "_relatedUserItemVersionId": "3212e325415654879e2d973a"   }];
await IafItemSvc.deleteRelations("6336c490017d84b0a506e43f", body);

deleteTelemetryConfig#

Deletes a TelemetryConfig in the Item Service when you pass its id.

ParameterRequiredTypeDescription
idYesStringThe TelemetryConfig's id
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoItemsvcOptionsTo make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true.
Returns

Promise<String> - Ok: 204 response

Examples
await IafItemSvc.deleteTelemetryConfig(id);

dropIndex#

Removes a text Index by the name property.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
bodyYesObjectAn object with the name as the property and the index name as the value
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo remove a text Index for a specific version rather than the tip version, pass a UserCollectionOptions object with a userItemVersionId property and value.
Returns

Promise<String> - Ok:204 response

Examples
//Drop index for tip versionlet body = { name: "dtCategory_dtType_full_text" };await IafItemSvc.dropIndex(userCollection._id, body, ctx );
//Drop index for specific version versionlet options = { userItemVersionId: "5dafd1936f2d3a4dcc55f8fa" };let body = {name: "dtCategory_dtType_full_text"};await IafItemSvc.dropIndex(userCollection._id, body, ctx, options);

getAllNamedUserItems#

Gets all NamedUserItem class objects.

ParameterRequiredTypeDescription
criteriaYesNamedUserItemCriteriaPass an object that contains your simple query.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoNamedUserItemCriteriaOptionsPass a NamedUserItemCriteriaOptions object with the project, sort, page, and pagedRes options you require.
Returns

Promise<Array<NamedUserItem>> - An array of all the NamedUserItem objects

Examples
await IafItemSvc.getAllNamedUserItems({  query: {    _userType: "example_colection"  }},  ctx,  undefined);

getIndexes#

Gets all indexes for a NamedUserCollection.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection id. Pass either the _userItemId or the MongoDB ObjectId.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo get the indexes of a specific NamedUserCollection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To get indexes in the tip version, do not pass an options parameter.
Returns

Promise<Page<JSON>> - The NamedUserCollection's database indexes

Examples
await IafItemSvc.getIndexes(collection._id);

getInverseRelations#

Gets the inverse relationships in a NamedUserCollection when you pass a simple query.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection id of the parent item. Pass either the _userItemId or the MongoDB ObjectId.
criteriaYesRelationShipCriteriaPass an object that contains a simple query
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo get the inverse relationships between related items in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To get inverse relationships in the tip version, do not pass an options parameter.
Returns

Promise<Page<RelationShip>> -

Examples
let criteria = {"query":{"_relatedUserType": "file_container"}}
await IafItemSvc.getInverseRelations(parentCollection._id, criteria);

getNamedUserItem#

Gets a NamedUserItem when you pass its id

ParameterRequiredTypeDescription
idYesStringThe NamedUserItem's id
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
Returns

Promise<NamedUserItem> -

Examples
const fileCollection = await IafItemSvc.getNamedUserItem(collection._id, ctx);

getNamedUserItems#

Gets NamedUserItems with criteria you pass.

ParameterRequiredTypeDescription
criteriaYesNamedUserItemCriteriaPass an object that contains your simple query.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoNamedUserItemCriteriaOptionsPass a NamedUserItemCriteriaOptions object with the project, sort, page, and pagedRes options you require.
Returns

Promise<Page<NamedUserItem>> - A Page object with the NamedUserItem objects that match your query.

Examples
let query = {   _usertype: "ref_app_telementary_collection",   _name: "Named Telemetry Collection" };
const options = {  project: {_userType: 1, _itemClass: 1},  sort: {_name: 1}, // -1 for descending order  page: {_offset: 10, _pageSize: 20}};

let items = await IafItemSvc.getNamedUserItems({query}, context, options);

getNamedUserItemVersion#

Gets a NamedUserItemVersion.

ParameterRequiredTypeDescription
userItemIdYesStringThe NamedUserItem's id. Pass either the _userItemId or the MongoDB ObjectId.
versionIdYesStringThe NamedUserItem's "_version" property value
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
Returns

Promise<NamedUserItemVersion> - The user item version as a NamedUserItemVersion object

Examples
const version = await IafItemSvc.getNamedUserItemVersion(item._id, item.versions[3]._id);

getNamedUserItemVersions#

Gets named user item versions based on a query you pass.

ParameterRequiredTypeDescription
userItemIdYesStringThe user item's id. Pass either the _userItemId or the MongoDB ObjectId.
criteriaYesNamedUserItemVersionCriteriaPass an object that contains your simple query
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoNamedUserItemCriteriaOptionsPass a NamedUserItemCriteriaOptions object with any of the following options as parameters: project, sort, page, and pagedRes.
Returns

Promise<Page<NamedUserItemVersion>> - A Page object with a NamedUserItemVersion object

Examples
const criteria = {  query: {     _userAttributes.fileId: "6336c490017d84b0a506e450"  }};
const versions = await IafItemSvc.getNamedUserItemVersions(item._id, criteria);

getPermissions#

Gets permissions for File Service resources.

ParameterRequiredTypeDescription
criteriaYesPermissionCriteriaPass a PermissionCriteria object that contains your simple query
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
Returns

Promise<Page<Permission>> - A promise with a Page object that contains the Permission objects that match your query

Examples
criteria = {   _userType: "Project_Setup_Config"};
const permissions = await IafItemSvc.getPermissions(criteria, ctx);

getRelatedInItem#

Gets the RelatedCollection class objects in a NamedCompositeItem.

ParameterRequiredTypeDescription
compIdYesStringThe NamedCompositeItem's id. Pass either the _userItemId or the MongoDB ObjectId.
criteriaYesRelatedCollectionCriteriaPass an object that contains your simple query
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo get RelatedCollection class objects in a specific NamedCompositeItem version rather than the tip version, pass a UserCollectionOptions object with a userItemVersionId property and value.
Returns

Promise<Page<RelatedCollection>> - RelatedCollection objects

Examples
//Get related collections from tip versionlet res1 = await IafItemSvc.getRelatedInItem(compItem._id, {}, ctx);
//Get related collections from specific versionlet res1 = await IafItemSvc.getRelatedInItem(compItem._id, {}, ctx, {userItemVersionId: "45cab6acfa877736bb1c5323"});

getRelatedItem#

Get a RelatedItem in a NamedUserCollection when you pass the RelatedItem's id.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
itemIdYesStringThe RelatedItem's id
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo get a related item in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To get items in the tip version, do not pass an options parameter.
Returns

Promise<RelatedItem> -

Examples
const relatedItem = await getRelatedItem(collection._id, item._id, ctx, undefined);

getRelatedItems#

Gets the RelatedItems in a NamedUserCollection that match a query you pass.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
criteriaYesRelatedItemCriteriaPass an object containing a simple query.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoRelatedItemCriteriaOptionsPass a RelatedItemCriteriaOptions object to set options, such as userItemVersionId, page, sort, pagedRes and project.
Returns

Promise<Page<RelatedItem>> - The RelatedItem objects that match your query

Examples
let criteria = {  query: {    assetType: "door",     floor: 2  }};
let options = {  project:{    type: 1,     floor: 1  },   sort: {    floor: -1  },   page: {    _pageSize: 2,     _offset: 2  }};
// Get related items by criteria from tip versionlet relatedItems = await IafItemSvc.getRelatedItems(userCollectionId, criteria, ctx, options);
// Get related items by criteria from specific versionconst versiondedOptions = { ...options, userItemVersionId: versionId };let relatedItems = await IafItemSvc.getRelatedItems(userCollectionId, criteria, ctx, versiondedOptions);

getRelatedItemUpdateLogs#

Gets update logs for a RelatedItem in a NamedUserCollection

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
itemIdYesStringThe RelatedItem's id
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
Returns

Promise<Array<JSON>> - An array of the RelatedItem's update logs, which are JSON objects

Examples
await IafItemSvc.getRelatedItemUpdateLogs(userCollection._id, item._id);

getRelatedReadingItems#

Gets all Reading class objects in a NamedTelemetryCollection or readings that match a query you pass.

ParameterRequiredTypeDescription
cidYesStringPass either a NamedTelemetryCollection's ObjectId or _userItemId.
criteriaYesRelatedItemCriteriaPass a RelatedItemCriteria object to filter for readings.
ctxYesCtxContext, such as authorization token requirements, namespaces, or session storage
optionsYesRelatedItemCriteriaOptionsPass a RelatedItemCriteriaOptions object to use response options, such as userItemVersionId, page, sort and project.
Returns

Promise<Page<Readings>> - A page of Reading objects

Examples
// Get readings by criteria from tip versionlet criteria = {query:{"$and": [{"_tsMetadata._telItemId": "61af69934e46196f8532bf13"},{"_ts": {"$gte":"2021-12-01T00:00:00.000Z"}}]}let options = {page: {_pageSize: 300, _offset: 0}, sort: {floor: 1}, project: {assetType: 1}}
const relatedItems = await IafItemSvc.getRelatedReadingItems(  collection._id,  criteria,  ctx,  options);

getRelations#

Gets relationships in a NamedUserCollection with a query you pass.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection id of the parent item. Pass either the _userItemId or the MongoDB ObjectId.
criteriaYesRelationshipCriteriaPass an object that contains a simple query
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoRelationshipCriteriaOptionsTo relate a specific version of items, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To get relationships in the tip version, do not pass an options parameter.
Returns

Promise<Page<RelationShip>> -

Examples
let criteria = {"query":{"_relatedUserType": "file_container"}}
await IafItemSvc.getRelations(parentCollection._id, criteria);

getScriptContentUrlByCriteria#

ParameterRequiredTypeDescription
criteriaYesNamedUserItemCriteriaPass an object that contains your simple query.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
Returns

String - Script url that can be used in dynamic import

getTelemetryConfig#

Gets a TelemetryConfig by id.

ParameterRequiredTypeDescription
idYesStringThe TelemetryConfig's id
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
Returns

Promise<TelemetryConfig> -

Examples
const telemConfig = await IafItemSvc.getTelemetryConfig(id);

getTelemetryConfigs#

Gets TelemetryConfigs that match the criteria you pass.

ParameterRequiredTypeDescription
criteriaYesTelemetryConfigPass a TelemetryConfig object that contains your simple query.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoTelemetryConfigCriteriaOptionsPass a TelemetryConfigCriteriaOptions object with the project, sort, page, and pagedRes options you require.
Returns

Promise<Page<TelemetryConfig>> - A Page object with the TelemetryConfig objects that match your query.

getTelemetryProcessingErrors#

Gets telemetry processing errors.

ParameterRequiredTypeDescription
criteriaYesJSONObjectPass an object that contains your simple query.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoNamedUserItemCriteriaOptionsPass a NamedUserItemCriteriaOptions object with the project, sort, page, and pagedRes options you require.
Returns

Promise<Page<TelemetryProcessingError>> - A Page object with the TelemetryProcessingError objects that match your query.

Examples
let criteria = {  query: {     _timestamp:{        "$gt": 1690788364587      }   }};
let options = {  project: {_exception: 1, _message: 1},  sort: {_timestamp: 1}, // -1 for descending order  page: {_offset: 10, _pageSize: 20}};
const errors = await getTelemetryProcessingErrors(criteria, options);

getUpdateLogs#

Gets a NamedUserCollection's update logs.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
Returns

Promise<Array<JSON>> - An array of update logs

Examples
getUpdateLogs(collection._id);

ItemClass#

Item class constants

Type: string

publishNamedUserItems#

Publishes the NamedUserItem objects that matches the criteria in _nameduseritems into the namespace thats in Publish request

ParameterRequiredTypeDescription
reqBodyYesJSONObjectreq body that contains publish request id and criteria for nameduseritems
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
Examples
let reqBody = {  _nameduseritems: {    _id: "65324b06401bd046c0454e0f"  },  _publishRequestId: "bff466a5-9782-4db2-8121-ec67138e19d1"};
const publishedItems = await IafItemSvc.publishNamedUserItems(reqBody, ctx);

searchRelatedItems#

Searches for related items with relationships with either a FindWithRelatedQuery, FindInCollectionsQuery, or DistinctRelatedItemFieldQuery.

ParameterRequiredTypeDescription
bodyYesCustomRelatedItemQueryPass one of the following custom query types: FindWithRelatedQuery, FindInCollectionsQuery, DistinctRelatedItemFieldQuery.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
Returns

CustomRelatedItemQueryResponse - An array of RelatedItemQueryResponse objects, which contain the matching versions and parent related items, and strings detailing the time taken to execute the query.

Examples
Please refer {@link CustomRelatedItemQuery} for inputs

updateNamedUserItem#

Updates a NamedUserItem class object

ParameterRequiredTypeDescription
itemYesNamedUserItemPass your updated NamedUserItem object
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoItemsvcOptionsTo make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true.
Returns

Promise<String> - Response string 'Ok: 204'

Examples
item._name = “Named User Collection Example”;
const updatedItem = IafItemSvc.updateNamedUserItem(item, {"transactional": true});

updateNamedUserItemVersion#

Updates the attributes of a particular NamedUserItemVersion class object

ParameterRequiredTypeDescription
userItemIdYesStringThe NamedUserItem's id. Pass either the _userItemId or the MongoDB ObjectId.
versionIdYesStringPass the NamedUserItemVersion's id.
versionYesNamedUserItemVersionPass a NamedUserItemVersion object that contains the properties you want to update with their updated values.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoItemsvcOptionsTo make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true.
Returns

Promise<NamedUserItemVersion> - The updated user item version as a NamedUserItemVersion object

Examples
const version = {  "_userAttributes": {    "folderName": "Warranty Docs"  }};
const updatedVersion = await IafItemSvc.updateNamedUserItemVersion(item._id, item.versions[3]._id, version, ctx, options);

updatePermissions#

Updates Permission class objects for Item Service resources such as the following NamedUserItem classes: Script, UserConfig, NamedUserCollection, and NamedCompositeItem. If a permission doesn't exist, this method creates the permission. To check if a permission exists or not, the method checks one of the following fields of a permission object: _resourceDesc, _namespace, _user.

ParameterRequiredTypeDescription
permissionsYesArray<Permission>Pass an array of updated Permission objects with the properties and the updated values
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
Returns

Promise<CreatePermissionsResponse> - A promise with a CreatePermissionsResponse object with an array of successful permissions and an array of failed permissions

updateRelatedItem#

Updates a RelatedItem in a NamedUserCollection.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
itemIdYesStringThe RelatedItem's id
bodyYesRelatedItemPass a RelatedItem object with the properties and values you want to update
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo update a related item in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To update a relationship in the tip version, do not pass an options parameter.
Returns

Promise<RelatedItem> - Updated related item

Examples
const userCollectionId = collection._id;const relatedItemUpdate = {"_name": "new_name"};
await IafItemSvc.updateRelatedItem(userCollectionId, relatedItemId, relatedItemUpdate);

updateRelatedItems#

Updates multiple RelatedItems in a NamedUserCollection.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id. Pass either the _userItemId or the MongoDB ObjectId.
itemsYesArray<RelatedItem>Pass an array of RelatedItem objects with an "_id" property and the properties and values you want to update
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage
optionsNoUserCollectionOptionsTo update related items in a specific collection version rather than the tip version, pass a UserCollectionOptions object with a "userItemVersionId" property and value. To update related items in the tip version, do not pass an options parameter.
Returns

Promise<String> - Ok: 204 response

Examples
const updatedRelatedItems = relatedItems.map(item => {  item._userType = updated_rel_item_ut;  return item;});
await IafItemSvc.updateRelatedItem(container._id, updatedRelatedItems);

updateRelatedItemsBulk#

Updates RelatedItems in bulk. You can look up RelatedItems by userItemVersionId or the tip version by default.

ParameterRequiredTypeDescription
cidYesStringThe NamedUserCollection's id or _userItemId
itemsYesArray<RelatedItem>The updated array of RelatedItems. This update array replaces the existing array. The max request body must be 10MB or less.
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsYesUserCollectionBulkOperationOptionsIt contains options such as userItemVersionId
Returns

Promise<String> - ok: 204 response

updateTelemetryConfig#

Updates a telemetry config in the item service when you pass your updated TelemetryConfig object.

ParameterRequiredTypeDescription
telemetryConfigYesundefined
ctxNoCtxContext, such as authorization token requirements, namespaces, or session storage.
optionsNoItemsvcOptionsTo make the action transactional, pass a ItemsvcOptions object with a "transactional" property and set its value to true.
itemYesTelemetryConfigPass your updated TelemetryConfig object.
Returns

Promise<TelemetryConfig> -

Examples
const updatedTelemConfig = await IafItemSvc.updateTelemetryConfig({  _namespaces: [    "lnt_bkJUK1W3"  ],  _shortName: "telconfig",  _name: "Project A Telemetry Config",  _userType: "telemetry_config",  _configData: {    _normalizationScript: {      _userType: "telemetry_parser_script"    },    _bindings: {      collectionDesc: {        _userItemId: "lnt_sensors__MogUhzsHhY"      },      query: {        "sensor_type": "co2"      }    }  }});