-
Notifications
You must be signed in to change notification settings - Fork 19
Python API (Deprecated)
Dariusz Jarosz edited this page May 24, 2024
·
1 revision
The python API allows a user to programmatically interact with CDB using python.
"""
First `run pip install cdb_api`
"""
from cdb.cdb_web_service.api.itemRestApi import ItemRestApi
from cdb.cdb_web_service.api.userRestApi import UserRestApi
from cdb.cdb_web_service.api.logRestApi import LogRestApi
from cdb.cdb_web_service.api.propertyRestApi import PropertyRestApi
params = dict(
protocol='https',
host='cdb_host',
port=10232,
username='cdb_user',
password='cdb_pass')
itemRestApi = ItemRestApi(**params)
userRestApi = UserRestApi(**params)
logRestApi = LogRestApi(**params)
propertyRestApi = PropertyRestApi(**params)
In order to assign a location to an inventory item you will first need to gather some information. First you need to know the ids of item and location item. Second will be using those ids to assign the location to an inventory item.
- First Way (Using the portal):
- Navigate to https://cdbhost/cdb/views/itemDomainLocation/list
- Click on the wrench button on the top right of the list table
- Expand extra information columns and select Display Id
- You can now see the id of each location item
- Second Way (API browse the hierarchy)
- itemRestApi.getLocationTopLevelItems()
- This will give you all the location that do not have a parent
- Now to go lower in the hierarchy
- result = itemRestApi.getItemElementsForItem(3)
- Elements may contain a contained item
- one of the elements is a 'self element' it will not have a contained item, it holds information about the parent item.
- result[1]['containedItem']
- The contained item is the child location
- You can keep going down the hierarchy as needed.
- itemRestApi.getLocationTopLevelItems()
- Third way (get all items):
- locationItems = itemRestApi.getLocationItems()
- The problem is that the hierarchy is unknown when fetching the complete list. Items with names such as shelf 3 may be to generic to know where shelf 3 actually is. However you can also get parent item of the item to get a better idea of its hierarchy
- Ex: itemRestApi.getParentItems(1114)
inventoryItemId=2242
locationItemId=1114
itemRestApi.addItemRelationship(
firstItemId = inventoryItemId,
secondItemId = locationItemId,
relationshipTypeName = 'Location',
relationshipDetails='Optional Location details can be specified as well')