Jump to content

Data search by ID?


Sivaji

Recommended Posts

Hi Sivaji,

actually you can search by ID using either the API/SDK or writing some code in Data Lab. In terms of API/SDK you should try the /items/{id} endpoint:
image.thumb.png.5e754f243fa95517fd8108aba8a5eb79.png

In case an item exists you will get HTTP 200 as status code and details about the item in the response body. If the item does not exist you receive an HTTP 404 status code.

In Data Lab you can use spy.search for this. In case of non-existing item spy.search throws an error, therefore I am iterating over the IDs:

item_ids = ["FCC9F932-B328-4A7E-9300-A17331519C93", "BF769E50-B93A-4C1A-81FD-326F488CD1E1", "64832183-D97F-4E5C-81A1-C466C494DC3A", "64832183-D97F-4E5C-81A1-C466C494DC6A", "FCC9F932-B328-4A7E-9300-A17331519C91"]

item_infos = []
for item_id in item_ids:
    try:
        data = spy.search({"ID": item_id})
        item_infos.append("Item with ID " + item_id + " exists")
    except:
        item_infos.append("Item with ID " + item_id + " does not exist")
print (item_infos)

Output looks like this:
['Item with ID FCC9F932-B328-4A7E-9300-A17331519C93 exists', 'Item with ID BF769E50-B93A-4C1A-81FD-326F488CD1E1 exists', 'Item with ID 64832183-D97F-4E5C-81A1-C466C494DC3A does not exist', 'Item with ID 64832183-D97F-4E5C-81A1-C466C494DC6A exists', 'Item with ID FCC9F932-B328-4A7E-9300-A17331519C91 does not exist']

Be aware that both methods return all types of items. In case you want to search only for signals or conditions you have to make some adjustments like evaluating the returned data.

Hope this helps.

Regards,

Thorsten

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...