Skip to content

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.

Creating a python client to the CDB API

"""
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)

Assigning Locations to inventory items

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.

Getting the ID of location

  • First Way (Using the portal):
  • 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.
  • 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)

Adding the location relationship

inventoryItemId=2242
locationItemId=1114
itemRestApi.addItemRelationship(
    firstItemId = inventoryItemId, 
    secondItemId = locationItemId, 
    relationshipTypeName = 'Location', 
    relationshipDetails='Optional Location details can be specified as well')
Clone this wiki locally