Overview

At ThingLogix we highly encourage all our users to use the New Advanced Search API methods in their own applications. This is because the New Advanced Search leverages an RDS table to more efficiently query your stored data.


Getting Started

1. Get Saved Search Criteria:

Description: To easily get the criteria needed for your searches we recommend that users use a saved search to get the criteria, which will then be used in the next API call.

Method: GET /foundry/saved-search/{id}

Response Example: 

{
  "id": "456",
  "userId": "123",
  "name": "searchName",
  "criteria": [
    {
      "filterName": "Name",
      "operator": "==",
      "condition": "AND",
      "value": "Test",
      "key": "a.name",
      "templateType": "String"
    }
  ]
}


2. Start Advanced Search New:

Description: Use the criteria that was returned from the previous API call to get the an Id which will be used to query the RDS table.

Method: POST /foundry/devices/advanced-search/new

Body Example:

{
  "accountId": "0016000001EvgkiAAF",
  "criteria": [
    {
      "filterName": "Name",
      "operator": "==",
      "condition": "AND",
      "value": "Test",
      "key": "a.name",
      "templateType": "String"
    }
  ]
}


Response Example: 

{
  "search": "_bfc11b30-01a7-11e8-a6ad-e3eca61f2559"
}



2. Get Result of Search:

Description: Use the searchId returned from the previous API call to get the result of your search. In most circumstances you will have to call this method a multiple times to get all the devices from your search.

Method: POST /foundry/devices/advanced-search/page

Body Example:

{
  "limit": 30,
  "searchId": "_bfc11b30-01a7-11e8-a6ad-e3eca61f2559",
  "offset": 0,
  "sort_by": "id",
  "sort_dir": "desc",
  "columns": [
    "a.name",
    "typeId"
  ],
  "filter": "",
  "accountId": "0016000001EvEkiAAF"
}

Body Breakdown:

limit (int): The number of devices returned from search. 0 can be used to check the status of the search.

searchId (string): Id of search returned from previous API call.

offset (int): Number of devices you want to start your search from. Ex If your first call has a limit of 30 and offset of 0 it will return devices 1-30. If you use a limit of 30 and offset of 30 it will return devices 31-60.


Response Example: 

{
  "status": "finished",
  "full_count": "5",
  "filtered_count": "5",
  "devices": [
    {
     "id": 5,
      "deviceId": "11245567",
      "accountId": "qwewf34tgreg",
      "typeId": "svf434frfe",
      "a.cron": 1484050996500,
      "a.status": "active",
      "a.type": "Scheduled",
      "a.payload": "{}",
      "a.mqtt_publish_topic": "com.test/test",
      "a.action_type": "MQTT Publish",
      "a.selected_device": "000000",
      "a.name": "Sch_D | MQTT Publish | Jan 10, 2017 12:23 PM +00:00 | test"
    }
  ]
}


Response Broken Down:

status (string): Status of the Search

   - "started" means that the search is still in progress and full_count could be changed. It is usually advised to continue to poll the API until the status reaches "finished".

   - "finished" means the search is now finished and full_count contains the number of items that will appear in the search. 

full_count (string): Current count of devices in result table.

filtered_count (string): Count of devices after filter apply.

devices (Array[Device]): Array of devices from search